SlideShare una empresa de Scribd logo
1 de 13
Question 1:
(a) Explain why Object Oriented Programming approach is better than Structured Programming
Approach.
(5 Marks)
Ans :- For the most part, web developers the world over have to contend with programming their
back-end applications using either structured or object-oriented programming. So what exactly
do those terms mean? Keep reading to find out as I compare structured and object oriented
programming in this article.
•

Definition of Structured Programming

Structured programming can be defined as a Software application
programming technique that follows a top down design approach with block oriented structures.
This style of programming is characterized by the programmers tendency to divide his program
source code into logically structured blocks which would normally consist of conditional
statements, loops and logic blocks. This style of programming has the implementation of the
source code being processed in the order in which bits of the code have been typed in.
•

Definition of Object-Oriented Programming

Object-oriented programming can be defined in simplest terms as
software application programming where there is an interaction between self-contained miniprograms or objects within the main program. In other terms, object-oriented programming can
be known as the process of using several classes to represent different areas of functionality or
data objects within your software application. These data objects have data fields and functions
that act on the data fields. The hold three main characteristics which are encapsulation,
inheritance, and polymorphism. Examples of objects would include windows, menus, text inputs,
icons, etc. There must be procedures to manipulate them.
(b) Write a simple C++ program to explain the basic structure of C++ programming. (5 Marks)
Ans :- Probably the best way to start learning a programming language is by writing a program.
Therefore, here is our first program:
1
2
3
4
5
6
7
8
9
10

// my first program in C++
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}

Hello World!

The first panel (in light blue) shows the source code for our first program. The second one (in
light gray) shows the result of the program once compiled and executed. To the left, the grey
numbers represent the line numbers - these are not part of the program, and are shown here
merely for informational purposes.
The way to edit and compile a program depends on the compiler you are using. Depending on
whether it has a Development Interface or not and on its version. Consult the compilers section
and the manual or help included with your compiler if you have doubts on how to compile a C++
console program.
The previous program is the typical program that programmer apprentices write for the first time,
and its result is the printing on screen of the "Hello World!" sentence. It is one of the simplest
programs that can be written in C++, but it already contains the fundamental components that
every C++ program has. We are going to look line by line at the code we have just written:
// my first program in C++

This is a comment line. All lines beginning with two slash signs (//) are considered
comments and do not have any effect on the behavior of the program. The programmer
can use them to include short explanations or observations within the source code itself.
In this case, the line is a brief description of what our program is.
#include <iostream>

Lines beginning with a hash sign (#) are directives for the preprocessor. They are not
regular code lines with expressions but indications for the compiler's preprocessor. In this
case the directive #include <iostream> tells the preprocessor to include the iostream
standard file. This specific file (iostream) includes the declarations of the basic standard
input-output library in C++, and it is included because its functionality is going to be
used later in the program.
using namespace std;

All the elements of the standard C++ library are declared within what is called a
namespace, the namespace with the name std. So in order to access its functionality we
declare with this expression that we will be using these entities. This line is very frequent
in C++ programs that use the standard library, and in fact it will be included in most of
the source codes included in these tutorials.
int main ()

This line corresponds to the beginning of the definition of the main function. The main
function is the point by where all C++ programs start their execution, independently of its
location within the source code. It does not matter whether there are other functions with
other names defined before or after it - the instructions contained within this function's
definition will always be the first ones to be executed in any C++ program. For that same
reason, it is essential that all C++ programs have a main function.
The word main is followed in the code by a pair of parentheses (()). That is because it is
a function declaration: In C++, what differentiates a function declaration from other types
of expressions are these parentheses that follow its name. Optionally, these parentheses
may enclose a list of parameters within them.
Right after these parentheses we can find the body of the main function enclosed in
braces ({}). What is contained within these braces is what the function does when it is
executed.
cout << "Hello World!";

This line is a C++ statement. A statement is a simple or compound expression that can
actually produce some effect. In fact, this statement performs the only action that
generates a visible effect in our first program.
cout

is the name of the standard output stream in C++, and the meaning of the entire
statement is to insert a sequence of characters (in this case the Hello World sequence
of characters) into the standard output stream (cout, which usually corresponds to the
screen).
cout is declared in the iostream standard file within the std namespace, so that's why we
needed to include that specific file and to declare that we were going to use this specific
namespace earlier in our code.
Notice that the statement ends with a semicolon character (;). This character is used to
mark the end of the statement and in fact it must be included at the end of all expression
statements in all C++ programs (one of the most common syntax errors is indeed to
forget to include some semicolon after a statement).
return 0;

The return statement causes the main function to finish. return may be followed by a
return code (in our example is followed by the return code with a value of zero). A return
code of 0 for the main function is generally interpreted as the program worked as
expected without any errors during its execution. This is the most usual way to end a C++
console program.
(c) Explain the usage of the following C++ operators with the help of an example program.
(6 Marks)
A) sizeof operator :- The sizeof is a keyword, but it is a compile-time operator that
determines the size, in bytes, of a variable or data type.
The sizeof operator can be used to get the size of classes, structures, unions and any other user
defined data type.
The syntax of using sizeof is as follows:
sizeof (data type)

Where data type is the desired data type including classes, structures, unions and any other user
defined data type.

B ) Logical Operators :- An operator is a symbol that tells the compiler to perform specific
mathematical or logical manipulations. C++ is rich in built-in operators and provides the
following types of operators:
•
•
•
•
•
•

Arithmetic Operators
Relational Operators
Logical Operators
Bitwise Operators
Assignment Operators
Misc Operators

This chapter will examine the arithmetic, relational, logical, bitwise, assignment and other
operators one by one.

Arithmetic Operators:
There are following arithmetic operators supported by C++ language:
Assume variable A holds 10 and variable B holds 20, then:
Show Examples
Operator
Description
+
Adds two operands
Subtracts second operand from the first
*
Multiplies both operands
/
Divides numerator by de-numerator
Modulus Operator and remainder of after
%
an integer division
Increment operator, increases integer value
++
by one
-Decrement operator, decreases integer

Example
A + B will give 30
A - B will give -10
A * B will give 200
B / A will give 2
B % A will give 0
A++ will give 11
A-- will give 9
value by one

C ) Scope resolution operator :- The :: (scope resolution) operator is used to qualify hidden
names so that you can still use them. You can use the unary scope operator if a namespace scope
or global scope name is hidden by an explicit declaration of the same name in a block or class.
For example:
int count = 0;
int main(void) {
int count = 0;
::count = 1; // set global count to 1
count = 2;
// set local count to 2
return 0;
}

The declaration of count declared in the main() function hides the integer named count
declared in global namespace scope. The statement ::count = 1 accesses the variable named
count declared in global namespace scope.
You can also use the class scope operator to qualify class names or class member names. If a
class member name is hidden, you can use it by qualifying it with its class name and the class
scope operator.
In the following example, the declaration of the variable X hides the class type X, but you can still
use the static class member count by qualifying it with the class type X and the scope resolution
operator.
#include <iostream>
using namespace std;
class X
{
public:
static int count;
};
int X::count = 10;
int main ()
{
int X = 0;
cout << X::count << endl;
}

Question 2:

// define static data member

// hides class type X
// use static member of class X
(a) Define the class Book with all the basic attributes such as title, author, publisher, price etc.
Define the default constructor, member functions display_data() for displaying the Book
details. Use appropriate access control specifiers in this program.
(8 Marks)
Ans :- class Book{
public:
enum Genre{
fiction = 0, nonfiction, periodical, biography, children
};
class Invalid{
//...
};
Book(int isbn, string author, string title, string copyright, Genre
genre, string status)
Book();
int isbn(); const{return isbn;}
string author(); const{return author;}
string title(); const{return title;}
string copyright(); const{return copyright;}
Genre genre(); const{return genre;}
string status(); const{return status;}
private:
int isbn;
string author;
string title;
string copyright;
Genre genre;
string status;
};

(b) Explain the following terms in the context of object oriented programming. Also explain how
these concepts are implemented in C++ by giving an example program for each.
(a)

(b)

(8 Marks)
Abstraction :- Data abstraction refers to, providing only essential information
to the outside word and hiding their background details, i.e., to represent the
needed information in program without presenting the details.
Encapsulation :- Encapsulation is the process of combining data and
functions into a single unit called class. Using the method of encapsulation,
the programmer cannot directly access the data. Data is only accessible
through the functions existing inside the class. Data encapsulation led to the
important concept of data hiding. Data hiding is the implementation details
of a class that are hidden from the user. The concept of restricted access led
programmers to write specialized functions or methods for performing the
operations on hidden members of the class. Attention must be paid to ensure
that the class is designed properly.
(c)

Operator Overloading :- using the assignment operator is fairly
straightforward, correctly implementing an overloaded assignment operator
can be a little more tricky than you might anticipate. There are two primary
reasons for this. First, there are some cases where the assignment operator
isn’t called when you might expect it to be. Second, there are some issues in
dealing with dynamically allocated memory (which we will cover in the next
lesson).

Static Member :- C++ introduces two new uses for the static keyword when applied to classes:
static member variables, and static member classes. Before we go into the static keyword as
applied to member variables, first consider the following class:
1
2 class Something
3 {
4 private:
int m_nValue;
5 public:
Something() { m_nValue = 0; }
6
};
7
8
9 int main()
10{
Something cFirst;
11
Something cSecond;
12
return 0;
13}
14
When we instantiate a class object, each object gets it’s own copy of all normal member
variables. In this case, because we have declared two Something class objects, we end up with
two copies of m_nValue — one inside cFirst, and one inside cSecond. cFirst->m_nValue is
different than cSecond->m_nValue.

Question 3:
(a) What is polymorphism? What are different forms of polymorphism? Explain
implementation of polymorphism with the help of a C++ program.
(8 Marks)
Ans :- The word polymorphism means having many forms. Typically, polymorphism occurs
when there is a hierarchy of classes and they are related by inheritance.
C++ polymorphism means that a call to a member function will cause a different function to be
executed depending on the type of object that invokes the function.
#include <iostream>
using namespace std;
class Shape {
protected:
int width, height;
public:
Shape( int a=0, int b=0)
{
width = a;
height = b;
}
int area()
{
cout << "Parent class area :" <<endl;
return 0;
}
};
class Rectangle: public Shape{
public:
Rectangle( int a=0, int b=0)
{
Shape(a, b);
}
int area ()
{
cout << "Rectangle class area :" <<endl;
return (width * height);
}
};
class Triangle: public Shape{
public:
Triangle( int a=0, int b=0)
{
Shape(a, b);
}
int area ()
{
cout << "Rectangle class area :" <<endl;
return (width * height / 2);
}
};
// Main function for the program
int main( )
{
Shape *shape;
Rectangle rec(10,7);
Triangle tri(10,5);
// store the address of Rectangle
shape = &rec;
// call rectangle area.
shape->area();
// store the address of Triangle
shape = &tri;
// call triangle area. shape>area();
return 0;
}

(b) What is friend function? How it is implemented in C++? Explain advantages of using friend
function with the help of an example.
( 8 Marks)
Ans :- A friend function of a class is defined outside that class' scope but it has the right to
access all private and protected members of the class. Even though the prototypes for friend
functions appear in the class definition, friends are not member functions.
A friend can be a function, function template, or member function, or a class or class template, in
which case the entire class and all of its members are friends.
To declare a function as a friend of a class, precede the function prototype in the class definition
with keyword friend as follows:
class Box
{
double width;
public:
double length;
friend void printWidth( Box box );
void setWidth( double wid );
};

Question 4 :
(a)

Explain the following functions for manipulating file pointers, with the help of example
program:
(8 Marks)
•

seekg() :- Internally, the function accesses the input sequence by first constructing a
sentry object (with noskipws set to true). Then (if good), it calls either pubseekpos
(1) or pubseekoff (2) on its associated stream buffer object (if any). Finally, it
destroys the sentry object before returning.

•

seekp() :- This function simply copies a block of data, without checking its contents
nor appending a null character at the end.
If the input sequence runs out of characters to extract (i.e., the end-of-file is reached)
before n characters have been successfully read, the array pointed by s contains all the
characters read until that point, and both the eofbit and failbit flags are set for the
stream.
•

•
(b)

tellg() :- the function accesses the input sequence by first constructing a sentry object
(with noskipws set to true) without evaluating it. Then, if member fail returns true,
the function returns -1.
Otherwise, returns rdbuf()->pubseekoff(0,cur,in). Finally, it destroys the sentry
object before returning.
tellp() :- Returns the position of the current character in the output stream.

What is an exception? How an exception is different from an error? Explain how
exceptions are handled in C++, with the help of an example program.
(8 Marks)

Ans :- Exception handling is a mechanism that separates code that detects and handles
exceptional circumstances from the rest of your program. Note that an exceptional circumstance
is not necessarily an error.
When a function detects an exceptional situation, you represent this with an object. This object is
called an exception object. In order to deal with the exceptional situation you throw the
exception. This passes control, as well as the exception, to a designated block of code in a direct
or indirect caller of the function that threw the exception. This block of code is called a handler.
In a handler, you specify the types of exceptions that it may process. The C++ run time, together
with the generated code, will pass control to the first appropriate handler that is able to process
the exception thrown. When this happens, an exception is caught. A handler may rethrow an
exception so it can be caught by another handler.

Question 5:
(a )

What is template? Write appropriate statements to create a template class for Stack data
structure in C++. (8 Marks)

Ans :- Templates are the foundation of generic programming, which involves writing code in a
way that is independent of any particular type.
A template is a blueprint or formula for creating a generic class or a function. The library
containers like iterators and algorithms are examples of generic programming and have been
developed using template concept.
There is a single definition of each container, such as vector, but we can define many different
kinds of vectors for example, vector <int> or vector <string>.
#include <iostream>
#include <vector>
#include <cstdlib>
#include <string>
#include <stdexcept>
using namespace std;
template <class T>
class Stack {
private:
vector<T> elems;

// elements

public:
void push(T const&); // push element
void pop();
// pop element
T top() const;
// return top element
bool empty() const{
// return true if empty.
return elems.empty();
}
};
template <class T>
void Stack<T>::push (T const& elem)
{
// append copy of passed element
elems.push_back(elem);
}
template <class T>
void Stack<T>::pop ()
{
if (elems.empty()) {
throw out_of_range("Stack<>::pop(): empty stack");
}
// remove last element
elems.pop_back();
}
template <class T>
T Stack<T>::top () const
{
if (elems.empty()) {
throw out_of_range("Stack<>::top(): empty stack");
}
// return copy of last element
return elems.back();
}
int main()
{
try {
Stack<int>
intStack;
Stack<string> stringStack;
// manipulate int stack
intStack.push(7);
cout << intStack.top() <<endl;

// stack of ints
// stack of strings
// manipulate string stack
stringStack.push("hello");
cout << stringStack.top() << std::endl;
stringStack.pop();
stringStack.pop();
}
catch (exception const& ex) {
cerr << "Exception: " << ex.what() <<endl;
return -1;
}
}

(b)

What is inheritance? What are different types of inheritance? Explain advantages of using
inheritance. (8 Marks)

Ans :- One of the most important concepts in object-oriented programming is that of inheritance.
Inheritance allows us to define a class in terms of another class, which makes it easier to create
and maintain an application. This also provides an opportunity to reuse the code functionality
and fast implementation time.
When creating a class, instead of writing completely new data members and member functions,
the programmer can designate that the new class should inherit the members of an existing class.
This existing class is called the base class, and the new class is referred to as the derived class.
The idea of inheritance implements the is a relationship. For example, mammal IS-A animal, dog
IS-A mammal hence dog IS-A animal as well and so on.

A class can be derived from more than one classes, which means it can inherit data and functions
from multiple base classes. To define a derived class, we use a class derivation list to specify the
base class(es). A class derivation list names one or more base classes and has the form:
#include <iostream>
using namespace std;
// Base class
class Shape
{
public:
void setWidth(int w)
{
width = w;
}
void setHeight(int h)
{
height = h;
}
protected:
int width;
int height;
};
// Derived class
class Rectangle: public Shape
{
public:
int getArea()
{
return (width * height);
}
};
int main(void)
{
Rectangle Rect;
Rect.setWidth(5);
Rect.setHeight(7);
// Print the area of the object.
cout << "Total area: " << Rect.getArea() << endl;
return 0;
}

For More Ignou Solved Assignments Please Visit - www.ignousolvedassignments.com
Connect on Facebook :
http://www.facebook.com/pages/IgnouSolvedAssignmentscom/346544145433550
Subscribe and Get Solved Assignments Direct to your Inbox :
http://feedburner.google.com/fb/a/mailverify?uri=ignousolvedassignments_com

Más contenido relacionado

La actualidad más candente

Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++ Bharat Kalia
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming CourseDennis Chang
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Languagesatvirsandhu9
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5REHAN IJAZ
 
01 c++ Intro.ppt
01 c++ Intro.ppt01 c++ Intro.ppt
01 c++ Intro.pptTareq Hasan
 
Functions, Strings ,Storage classes in C
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in Carshpreetkaur07
 
C++ questions and answers
C++ questions and answersC++ questions and answers
C++ questions and answersDeepak Singh
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)Mansi Tyagi
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c languagetanmaymodi4
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cppNilesh Dalvi
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteachingeteaching
 
C++ OOP Implementation
C++ OOP ImplementationC++ OOP Implementation
C++ OOP ImplementationFridz Felisco
 
Basic structure of C++ program
Basic structure of C++ programBasic structure of C++ program
Basic structure of C++ programmatiur rahman
 

La actualidad más candente (20)

Data types in c++
Data types in c++ Data types in c++
Data types in c++
 
C programming notes
C programming notesC programming notes
C programming notes
 
Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Language
 
Structures-2
Structures-2Structures-2
Structures-2
 
Ppt of c vs c#
Ppt of c vs c#Ppt of c vs c#
Ppt of c vs c#
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
 
01 c++ Intro.ppt
01 c++ Intro.ppt01 c++ Intro.ppt
01 c++ Intro.ppt
 
Functions, Strings ,Storage classes in C
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in C
 
C++ questions and answers
C++ questions and answersC++ questions and answers
C++ questions and answers
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 
Structures
StructuresStructures
Structures
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c language
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteaching
 
C++ ppt
C++ pptC++ ppt
C++ ppt
 
Handout#11
Handout#11Handout#11
Handout#11
 
C++ OOP Implementation
C++ OOP ImplementationC++ OOP Implementation
C++ OOP Implementation
 
Basic structure of C++ program
Basic structure of C++ programBasic structure of C++ program
Basic structure of C++ program
 

Destacado

Computer Math Day 03 Addition
Computer Math Day 03 AdditionComputer Math Day 03 Addition
Computer Math Day 03 AdditionA Jorge Garcia
 
Computer math
Computer mathComputer math
Computer mathPDE1D
 
Colorado Nut Company One Sheet and Order Form
Colorado Nut Company One Sheet and Order FormColorado Nut Company One Sheet and Order Form
Colorado Nut Company One Sheet and Order FormHeidi Gardiner
 
AZLinux. Master Software Libre URJC. 2012
AZLinux. Master Software Libre URJC. 2012AZLinux. Master Software Libre URJC. 2012
AZLinux. Master Software Libre URJC. 2012Eduardo Romero Moreno
 
Special World Cup Whitepaper - Fantasy football is proven to increase TV ratings
Special World Cup Whitepaper - Fantasy football is proven to increase TV ratingsSpecial World Cup Whitepaper - Fantasy football is proven to increase TV ratings
Special World Cup Whitepaper - Fantasy football is proven to increase TV ratingsFanXT
 
Tapping into IT Sales Opportunities across Office of the Secretary of Defense...
Tapping into IT Sales Opportunities across Office of the Secretary of Defense...Tapping into IT Sales Opportunities across Office of the Secretary of Defense...
Tapping into IT Sales Opportunities across Office of the Secretary of Defense...immixGroup
 
Mishlej - Proverbios
Mishlej - ProverbiosMishlej - Proverbios
Mishlej - ProverbiosMalakDYHWH
 
”A framework for e/mHealth projects – examples from various industries”
”A framework for e/mHealth projects – examples from various industries””A framework for e/mHealth projects – examples from various industries”
”A framework for e/mHealth projects – examples from various industries”Dr. Daniel Stoller-Schai
 
Profesionales involucrados en su atención integral
Profesionales  involucrados en su atención integralProfesionales  involucrados en su atención integral
Profesionales involucrados en su atención integralanmendozasa
 
Interfase del mundo analógico con el digital (1)
Interfase del mundo analógico con el digital (1)Interfase del mundo analógico con el digital (1)
Interfase del mundo analógico con el digital (1)trach12
 
Tutorial scratch
Tutorial scratchTutorial scratch
Tutorial scratchlajucori
 
Colaboración 2.0 en un plan de emergencias -- José Gil de Bernabé
Colaboración 2.0 en un plan de emergencias -- José Gil de BernabéColaboración 2.0 en un plan de emergencias -- José Gil de Bernabé
Colaboración 2.0 en un plan de emergencias -- José Gil de Bernabéorganizacion_20
 
Two Months Of Rock And Road
Two Months Of Rock And RoadTwo Months Of Rock And Road
Two Months Of Rock And Roadguest02f41
 

Destacado (20)

Computer Math Day 03 Addition
Computer Math Day 03 AdditionComputer Math Day 03 Addition
Computer Math Day 03 Addition
 
Computer math
Computer mathComputer math
Computer math
 
Colorado Nut Company One Sheet and Order Form
Colorado Nut Company One Sheet and Order FormColorado Nut Company One Sheet and Order Form
Colorado Nut Company One Sheet and Order Form
 
AZLinux. Master Software Libre URJC. 2012
AZLinux. Master Software Libre URJC. 2012AZLinux. Master Software Libre URJC. 2012
AZLinux. Master Software Libre URJC. 2012
 
Special World Cup Whitepaper - Fantasy football is proven to increase TV ratings
Special World Cup Whitepaper - Fantasy football is proven to increase TV ratingsSpecial World Cup Whitepaper - Fantasy football is proven to increase TV ratings
Special World Cup Whitepaper - Fantasy football is proven to increase TV ratings
 
Tapping into IT Sales Opportunities across Office of the Secretary of Defense...
Tapping into IT Sales Opportunities across Office of the Secretary of Defense...Tapping into IT Sales Opportunities across Office of the Secretary of Defense...
Tapping into IT Sales Opportunities across Office of the Secretary of Defense...
 
Mishlej - Proverbios
Mishlej - ProverbiosMishlej - Proverbios
Mishlej - Proverbios
 
RESUME F
RESUME FRESUME F
RESUME F
 
”A framework for e/mHealth projects – examples from various industries”
”A framework for e/mHealth projects – examples from various industries””A framework for e/mHealth projects – examples from various industries”
”A framework for e/mHealth projects – examples from various industries”
 
ESCUELA WALDORF
ESCUELA WALDORFESCUELA WALDORF
ESCUELA WALDORF
 
Profesionales involucrados en su atención integral
Profesionales  involucrados en su atención integralProfesionales  involucrados en su atención integral
Profesionales involucrados en su atención integral
 
Office365 für Bildungseinrichtungen
Office365 für BildungseinrichtungenOffice365 für Bildungseinrichtungen
Office365 für Bildungseinrichtungen
 
Pon el-cielo-a-trabajar
Pon el-cielo-a-trabajarPon el-cielo-a-trabajar
Pon el-cielo-a-trabajar
 
Interfase del mundo analógico con el digital (1)
Interfase del mundo analógico con el digital (1)Interfase del mundo analógico con el digital (1)
Interfase del mundo analógico con el digital (1)
 
Tutorial scratch
Tutorial scratchTutorial scratch
Tutorial scratch
 
Soundway Sales Catalogue
Soundway Sales CatalogueSoundway Sales Catalogue
Soundway Sales Catalogue
 
Pisos de-cemento
Pisos de-cementoPisos de-cemento
Pisos de-cemento
 
Colaboración 2.0 en un plan de emergencias -- José Gil de Bernabé
Colaboración 2.0 en un plan de emergencias -- José Gil de BernabéColaboración 2.0 en un plan de emergencias -- José Gil de Bernabé
Colaboración 2.0 en un plan de emergencias -- José Gil de Bernabé
 
Reading_Jung
Reading_JungReading_Jung
Reading_Jung
 
Two Months Of Rock And Road
Two Months Of Rock And RoadTwo Months Of Rock And Road
Two Months Of Rock And Road
 

Similar a Bcsl 031 solve assignment

Tutorial basic of c ++lesson 1 eng ver
Tutorial basic of c ++lesson 1 eng verTutorial basic of c ++lesson 1 eng ver
Tutorial basic of c ++lesson 1 eng verQrembiezs Intruder
 
The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming LanguageProf Ansari
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 
Introduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to itIntroduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to itPushkarNiroula1
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptxMugilvannan11
 
Book management system
Book management systemBook management system
Book management systemSHARDA SHARAN
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxrajkumar490591
 
C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeksAashutoshChhedavi
 
1 CMPS 12M Introduction to Data Structures Lab La.docx
1 CMPS 12M Introduction to Data Structures Lab La.docx1 CMPS 12M Introduction to Data Structures Lab La.docx
1 CMPS 12M Introduction to Data Structures Lab La.docxtarifarmarie
 
C programming languag for cse students
C programming languag for cse studentsC programming languag for cse students
C programming languag for cse studentsAbdur Rahim
 
PRINCE PRESENTATION(1).pptx
PRINCE PRESENTATION(1).pptxPRINCE PRESENTATION(1).pptx
PRINCE PRESENTATION(1).pptxSajalKesharwani2
 

Similar a Bcsl 031 solve assignment (20)

Introduction of C++ By Pawan Thakur
Introduction of C++ By Pawan ThakurIntroduction of C++ By Pawan Thakur
Introduction of C++ By Pawan Thakur
 
Tutorial basic of c ++lesson 1 eng ver
Tutorial basic of c ++lesson 1 eng verTutorial basic of c ++lesson 1 eng ver
Tutorial basic of c ++lesson 1 eng ver
 
The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming Language
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Introduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to itIntroduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to it
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptx
 
Prog1-L1.pdf
Prog1-L1.pdfProg1-L1.pdf
Prog1-L1.pdf
 
Book management system
Book management systemBook management system
Book management system
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
C tutorials
C tutorialsC tutorials
C tutorials
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
 
Cp week _2.
Cp week _2.Cp week _2.
Cp week _2.
 
C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeks
 
Oops index
Oops indexOops index
Oops index
 
1 CMPS 12M Introduction to Data Structures Lab La.docx
1 CMPS 12M Introduction to Data Structures Lab La.docx1 CMPS 12M Introduction to Data Structures Lab La.docx
1 CMPS 12M Introduction to Data Structures Lab La.docx
 
SRAVANByCPP
SRAVANByCPPSRAVANByCPP
SRAVANByCPP
 
C programming languag for cse students
C programming languag for cse studentsC programming languag for cse students
C programming languag for cse students
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
PRINCE PRESENTATION(1).pptx
PRINCE PRESENTATION(1).pptxPRINCE PRESENTATION(1).pptx
PRINCE PRESENTATION(1).pptx
 

Más de Indira Gnadhi National Open University (IGNOU)

Más de Indira Gnadhi National Open University (IGNOU) (19)

Mcs 17 solved assignment 2015- 16
Mcs 17 solved assignment 2015- 16Mcs 17 solved assignment 2015- 16
Mcs 17 solved assignment 2015- 16
 
Mcs 16 solved assignment 2015-16
Mcs 16 solved assignment 2015-16Mcs 16 solved assignment 2015-16
Mcs 16 solved assignment 2015-16
 
Mcs 014 solved assignment 2015-16
Mcs 014 solved assignment 2015-16Mcs 014 solved assignment 2015-16
Mcs 014 solved assignment 2015-16
 
Mcs 012 soved assignment 2015-16
Mcs 012 soved assignment 2015-16Mcs 012 soved assignment 2015-16
Mcs 012 soved assignment 2015-16
 
Mcs 011 solved assignment 2015-16
Mcs 011 solved assignment 2015-16Mcs 011 solved assignment 2015-16
Mcs 011 solved assignment 2015-16
 
BCSL 058 solved assignment
BCSL 058 solved assignmentBCSL 058 solved assignment
BCSL 058 solved assignment
 
BCSL 057 solved assignments
BCSL 057 solved assignmentsBCSL 057 solved assignments
BCSL 057 solved assignments
 
BCSL 056 solved assignment
BCSL 056 solved assignmentBCSL 056 solved assignment
BCSL 056 solved assignment
 
Bcs 055 solved 2014-15
Bcs 055 solved 2014-15Bcs 055 solved 2014-15
Bcs 055 solved 2014-15
 
Bcs 054 solved assignment
Bcs 054 solved assignmentBcs 054 solved assignment
Bcs 054 solved assignment
 
Bcs 053 solved assignment 2014-15
Bcs 053 solved assignment 2014-15Bcs 053 solved assignment 2014-15
Bcs 053 solved assignment 2014-15
 
Bcs 052 solved assignment
Bcs 052 solved assignmentBcs 052 solved assignment
Bcs 052 solved assignment
 
Mcs 021 solve assignment
Mcs 021 solve assignmentMcs 021 solve assignment
Mcs 021 solve assignment
 
Bcsl 033 solve assignment
Bcsl 033 solve assignmentBcsl 033 solve assignment
Bcsl 033 solve assignment
 
2012 bcsl-021 solve assihnment
2012 bcsl-021 solve assihnment2012 bcsl-021 solve assihnment
2012 bcsl-021 solve assihnment
 
Bcsl 022 solved-assignment_2012-13
Bcsl 022 solved-assignment_2012-13Bcsl 022 solved-assignment_2012-13
Bcsl 022 solved-assignment_2012-13
 
Eco 02 question paper
Eco 02 question paperEco 02 question paper
Eco 02 question paper
 
Mcs 015 solve assignment
Mcs 015 solve assignmentMcs 015 solve assignment
Mcs 015 solve assignment
 
Mcs 013 solve assignment
Mcs 013 solve assignmentMcs 013 solve assignment
Mcs 013 solve assignment
 

Último

Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Último (20)

Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

Bcsl 031 solve assignment

  • 1. Question 1: (a) Explain why Object Oriented Programming approach is better than Structured Programming Approach. (5 Marks) Ans :- For the most part, web developers the world over have to contend with programming their back-end applications using either structured or object-oriented programming. So what exactly do those terms mean? Keep reading to find out as I compare structured and object oriented programming in this article. • Definition of Structured Programming Structured programming can be defined as a Software application programming technique that follows a top down design approach with block oriented structures. This style of programming is characterized by the programmers tendency to divide his program source code into logically structured blocks which would normally consist of conditional statements, loops and logic blocks. This style of programming has the implementation of the source code being processed in the order in which bits of the code have been typed in. • Definition of Object-Oriented Programming Object-oriented programming can be defined in simplest terms as software application programming where there is an interaction between self-contained miniprograms or objects within the main program. In other terms, object-oriented programming can be known as the process of using several classes to represent different areas of functionality or data objects within your software application. These data objects have data fields and functions that act on the data fields. The hold three main characteristics which are encapsulation, inheritance, and polymorphism. Examples of objects would include windows, menus, text inputs, icons, etc. There must be procedures to manipulate them.
  • 2. (b) Write a simple C++ program to explain the basic structure of C++ programming. (5 Marks) Ans :- Probably the best way to start learning a programming language is by writing a program. Therefore, here is our first program: 1 2 3 4 5 6 7 8 9 10 // my first program in C++ #include <iostream> using namespace std; int main () { cout << "Hello World!"; return 0; } Hello World! The first panel (in light blue) shows the source code for our first program. The second one (in light gray) shows the result of the program once compiled and executed. To the left, the grey numbers represent the line numbers - these are not part of the program, and are shown here merely for informational purposes. The way to edit and compile a program depends on the compiler you are using. Depending on whether it has a Development Interface or not and on its version. Consult the compilers section and the manual or help included with your compiler if you have doubts on how to compile a C++ console program. The previous program is the typical program that programmer apprentices write for the first time, and its result is the printing on screen of the "Hello World!" sentence. It is one of the simplest programs that can be written in C++, but it already contains the fundamental components that every C++ program has. We are going to look line by line at the code we have just written: // my first program in C++ This is a comment line. All lines beginning with two slash signs (//) are considered comments and do not have any effect on the behavior of the program. The programmer can use them to include short explanations or observations within the source code itself. In this case, the line is a brief description of what our program is. #include <iostream> Lines beginning with a hash sign (#) are directives for the preprocessor. They are not regular code lines with expressions but indications for the compiler's preprocessor. In this case the directive #include <iostream> tells the preprocessor to include the iostream standard file. This specific file (iostream) includes the declarations of the basic standard input-output library in C++, and it is included because its functionality is going to be used later in the program. using namespace std; All the elements of the standard C++ library are declared within what is called a namespace, the namespace with the name std. So in order to access its functionality we declare with this expression that we will be using these entities. This line is very frequent in C++ programs that use the standard library, and in fact it will be included in most of the source codes included in these tutorials.
  • 3. int main () This line corresponds to the beginning of the definition of the main function. The main function is the point by where all C++ programs start their execution, independently of its location within the source code. It does not matter whether there are other functions with other names defined before or after it - the instructions contained within this function's definition will always be the first ones to be executed in any C++ program. For that same reason, it is essential that all C++ programs have a main function. The word main is followed in the code by a pair of parentheses (()). That is because it is a function declaration: In C++, what differentiates a function declaration from other types of expressions are these parentheses that follow its name. Optionally, these parentheses may enclose a list of parameters within them. Right after these parentheses we can find the body of the main function enclosed in braces ({}). What is contained within these braces is what the function does when it is executed. cout << "Hello World!"; This line is a C++ statement. A statement is a simple or compound expression that can actually produce some effect. In fact, this statement performs the only action that generates a visible effect in our first program. cout is the name of the standard output stream in C++, and the meaning of the entire statement is to insert a sequence of characters (in this case the Hello World sequence of characters) into the standard output stream (cout, which usually corresponds to the screen). cout is declared in the iostream standard file within the std namespace, so that's why we needed to include that specific file and to declare that we were going to use this specific namespace earlier in our code. Notice that the statement ends with a semicolon character (;). This character is used to mark the end of the statement and in fact it must be included at the end of all expression statements in all C++ programs (one of the most common syntax errors is indeed to forget to include some semicolon after a statement). return 0; The return statement causes the main function to finish. return may be followed by a return code (in our example is followed by the return code with a value of zero). A return code of 0 for the main function is generally interpreted as the program worked as expected without any errors during its execution. This is the most usual way to end a C++ console program. (c) Explain the usage of the following C++ operators with the help of an example program. (6 Marks) A) sizeof operator :- The sizeof is a keyword, but it is a compile-time operator that determines the size, in bytes, of a variable or data type.
  • 4. The sizeof operator can be used to get the size of classes, structures, unions and any other user defined data type. The syntax of using sizeof is as follows: sizeof (data type) Where data type is the desired data type including classes, structures, unions and any other user defined data type. B ) Logical Operators :- An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. C++ is rich in built-in operators and provides the following types of operators: • • • • • • Arithmetic Operators Relational Operators Logical Operators Bitwise Operators Assignment Operators Misc Operators This chapter will examine the arithmetic, relational, logical, bitwise, assignment and other operators one by one. Arithmetic Operators: There are following arithmetic operators supported by C++ language: Assume variable A holds 10 and variable B holds 20, then: Show Examples Operator Description + Adds two operands Subtracts second operand from the first * Multiplies both operands / Divides numerator by de-numerator Modulus Operator and remainder of after % an integer division Increment operator, increases integer value ++ by one -Decrement operator, decreases integer Example A + B will give 30 A - B will give -10 A * B will give 200 B / A will give 2 B % A will give 0 A++ will give 11 A-- will give 9
  • 5. value by one C ) Scope resolution operator :- The :: (scope resolution) operator is used to qualify hidden names so that you can still use them. You can use the unary scope operator if a namespace scope or global scope name is hidden by an explicit declaration of the same name in a block or class. For example: int count = 0; int main(void) { int count = 0; ::count = 1; // set global count to 1 count = 2; // set local count to 2 return 0; } The declaration of count declared in the main() function hides the integer named count declared in global namespace scope. The statement ::count = 1 accesses the variable named count declared in global namespace scope. You can also use the class scope operator to qualify class names or class member names. If a class member name is hidden, you can use it by qualifying it with its class name and the class scope operator. In the following example, the declaration of the variable X hides the class type X, but you can still use the static class member count by qualifying it with the class type X and the scope resolution operator. #include <iostream> using namespace std; class X { public: static int count; }; int X::count = 10; int main () { int X = 0; cout << X::count << endl; } Question 2: // define static data member // hides class type X // use static member of class X
  • 6. (a) Define the class Book with all the basic attributes such as title, author, publisher, price etc. Define the default constructor, member functions display_data() for displaying the Book details. Use appropriate access control specifiers in this program. (8 Marks) Ans :- class Book{ public: enum Genre{ fiction = 0, nonfiction, periodical, biography, children }; class Invalid{ //... }; Book(int isbn, string author, string title, string copyright, Genre genre, string status) Book(); int isbn(); const{return isbn;} string author(); const{return author;} string title(); const{return title;} string copyright(); const{return copyright;} Genre genre(); const{return genre;} string status(); const{return status;} private: int isbn; string author; string title; string copyright; Genre genre; string status; }; (b) Explain the following terms in the context of object oriented programming. Also explain how these concepts are implemented in C++ by giving an example program for each. (a) (b) (8 Marks) Abstraction :- Data abstraction refers to, providing only essential information to the outside word and hiding their background details, i.e., to represent the needed information in program without presenting the details. Encapsulation :- Encapsulation is the process of combining data and functions into a single unit called class. Using the method of encapsulation, the programmer cannot directly access the data. Data is only accessible through the functions existing inside the class. Data encapsulation led to the important concept of data hiding. Data hiding is the implementation details of a class that are hidden from the user. The concept of restricted access led programmers to write specialized functions or methods for performing the operations on hidden members of the class. Attention must be paid to ensure that the class is designed properly.
  • 7. (c) Operator Overloading :- using the assignment operator is fairly straightforward, correctly implementing an overloaded assignment operator can be a little more tricky than you might anticipate. There are two primary reasons for this. First, there are some cases where the assignment operator isn’t called when you might expect it to be. Second, there are some issues in dealing with dynamically allocated memory (which we will cover in the next lesson). Static Member :- C++ introduces two new uses for the static keyword when applied to classes: static member variables, and static member classes. Before we go into the static keyword as applied to member variables, first consider the following class: 1 2 class Something 3 { 4 private: int m_nValue; 5 public: Something() { m_nValue = 0; } 6 }; 7 8 9 int main() 10{ Something cFirst; 11 Something cSecond; 12 return 0; 13} 14 When we instantiate a class object, each object gets it’s own copy of all normal member variables. In this case, because we have declared two Something class objects, we end up with two copies of m_nValue — one inside cFirst, and one inside cSecond. cFirst->m_nValue is different than cSecond->m_nValue. Question 3: (a) What is polymorphism? What are different forms of polymorphism? Explain implementation of polymorphism with the help of a C++ program. (8 Marks) Ans :- The word polymorphism means having many forms. Typically, polymorphism occurs when there is a hierarchy of classes and they are related by inheritance.
  • 8. C++ polymorphism means that a call to a member function will cause a different function to be executed depending on the type of object that invokes the function. #include <iostream> using namespace std; class Shape { protected: int width, height; public: Shape( int a=0, int b=0) { width = a; height = b; } int area() { cout << "Parent class area :" <<endl; return 0; } }; class Rectangle: public Shape{ public: Rectangle( int a=0, int b=0) { Shape(a, b); } int area () { cout << "Rectangle class area :" <<endl; return (width * height); } }; class Triangle: public Shape{ public: Triangle( int a=0, int b=0) { Shape(a, b); } int area () { cout << "Rectangle class area :" <<endl; return (width * height / 2); } }; // Main function for the program int main( ) { Shape *shape; Rectangle rec(10,7); Triangle tri(10,5); // store the address of Rectangle shape = &rec; // call rectangle area. shape->area();
  • 9. // store the address of Triangle shape = &tri; // call triangle area. shape>area(); return 0; } (b) What is friend function? How it is implemented in C++? Explain advantages of using friend function with the help of an example. ( 8 Marks) Ans :- A friend function of a class is defined outside that class' scope but it has the right to access all private and protected members of the class. Even though the prototypes for friend functions appear in the class definition, friends are not member functions. A friend can be a function, function template, or member function, or a class or class template, in which case the entire class and all of its members are friends. To declare a function as a friend of a class, precede the function prototype in the class definition with keyword friend as follows: class Box { double width; public: double length; friend void printWidth( Box box ); void setWidth( double wid ); }; Question 4 : (a) Explain the following functions for manipulating file pointers, with the help of example program: (8 Marks) • seekg() :- Internally, the function accesses the input sequence by first constructing a sentry object (with noskipws set to true). Then (if good), it calls either pubseekpos (1) or pubseekoff (2) on its associated stream buffer object (if any). Finally, it destroys the sentry object before returning. • seekp() :- This function simply copies a block of data, without checking its contents nor appending a null character at the end. If the input sequence runs out of characters to extract (i.e., the end-of-file is reached) before n characters have been successfully read, the array pointed by s contains all the
  • 10. characters read until that point, and both the eofbit and failbit flags are set for the stream. • • (b) tellg() :- the function accesses the input sequence by first constructing a sentry object (with noskipws set to true) without evaluating it. Then, if member fail returns true, the function returns -1. Otherwise, returns rdbuf()->pubseekoff(0,cur,in). Finally, it destroys the sentry object before returning. tellp() :- Returns the position of the current character in the output stream. What is an exception? How an exception is different from an error? Explain how exceptions are handled in C++, with the help of an example program. (8 Marks) Ans :- Exception handling is a mechanism that separates code that detects and handles exceptional circumstances from the rest of your program. Note that an exceptional circumstance is not necessarily an error. When a function detects an exceptional situation, you represent this with an object. This object is called an exception object. In order to deal with the exceptional situation you throw the exception. This passes control, as well as the exception, to a designated block of code in a direct or indirect caller of the function that threw the exception. This block of code is called a handler. In a handler, you specify the types of exceptions that it may process. The C++ run time, together with the generated code, will pass control to the first appropriate handler that is able to process the exception thrown. When this happens, an exception is caught. A handler may rethrow an exception so it can be caught by another handler. Question 5: (a ) What is template? Write appropriate statements to create a template class for Stack data structure in C++. (8 Marks) Ans :- Templates are the foundation of generic programming, which involves writing code in a way that is independent of any particular type. A template is a blueprint or formula for creating a generic class or a function. The library containers like iterators and algorithms are examples of generic programming and have been developed using template concept. There is a single definition of each container, such as vector, but we can define many different kinds of vectors for example, vector <int> or vector <string>. #include <iostream> #include <vector>
  • 11. #include <cstdlib> #include <string> #include <stdexcept> using namespace std; template <class T> class Stack { private: vector<T> elems; // elements public: void push(T const&); // push element void pop(); // pop element T top() const; // return top element bool empty() const{ // return true if empty. return elems.empty(); } }; template <class T> void Stack<T>::push (T const& elem) { // append copy of passed element elems.push_back(elem); } template <class T> void Stack<T>::pop () { if (elems.empty()) { throw out_of_range("Stack<>::pop(): empty stack"); } // remove last element elems.pop_back(); } template <class T> T Stack<T>::top () const { if (elems.empty()) { throw out_of_range("Stack<>::top(): empty stack"); } // return copy of last element return elems.back(); } int main() { try { Stack<int> intStack; Stack<string> stringStack; // manipulate int stack intStack.push(7); cout << intStack.top() <<endl; // stack of ints // stack of strings
  • 12. // manipulate string stack stringStack.push("hello"); cout << stringStack.top() << std::endl; stringStack.pop(); stringStack.pop(); } catch (exception const& ex) { cerr << "Exception: " << ex.what() <<endl; return -1; } } (b) What is inheritance? What are different types of inheritance? Explain advantages of using inheritance. (8 Marks) Ans :- One of the most important concepts in object-oriented programming is that of inheritance. Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and fast implementation time. When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing class. This existing class is called the base class, and the new class is referred to as the derived class. The idea of inheritance implements the is a relationship. For example, mammal IS-A animal, dog IS-A mammal hence dog IS-A animal as well and so on. A class can be derived from more than one classes, which means it can inherit data and functions from multiple base classes. To define a derived class, we use a class derivation list to specify the base class(es). A class derivation list names one or more base classes and has the form: #include <iostream> using namespace std; // Base class class Shape { public: void setWidth(int w) { width = w; } void setHeight(int h) { height = h; }
  • 13. protected: int width; int height; }; // Derived class class Rectangle: public Shape { public: int getArea() { return (width * height); } }; int main(void) { Rectangle Rect; Rect.setWidth(5); Rect.setHeight(7); // Print the area of the object. cout << "Total area: " << Rect.getArea() << endl; return 0; } For More Ignou Solved Assignments Please Visit - www.ignousolvedassignments.com Connect on Facebook : http://www.facebook.com/pages/IgnouSolvedAssignmentscom/346544145433550 Subscribe and Get Solved Assignments Direct to your Inbox : http://feedburner.google.com/fb/a/mailverify?uri=ignousolvedassignments_com