C++ HOLIDAY HOMEWORK ASSIGNMENT WITH MARKING SCHEME
CHAPTER -1 C++ REVISION
1.(a)What is the difference between Global Variable and Local Variable? Also, give a
suitable C++ code to illustrate both. 2
(b) Which C++ header file(s) will be essentially required to be included to run /execute
the following C++ code: 1
void main()
{
char Msg[ ]="Sunset Gardens";
for (int I=5;I<strlen(Msg);I++)
puts(Msg);
}
(c) Rewrite the following program after removing the syntactical errors (if any).Underline
each correction. 2
#include [iostream.h]
class MEMBER
{
int Mno;float Fees;
PUBLIC:
void Register(){cin>>Mno>>Fees;}
void Display{cout<<Mno<<" : "<<Fees<<endl;}
};
void main()
{
MEMBER M;
Register();
M.Display();
}
(d) Find the output of the following program: 3
#include <iostream.h>
struct GAME
{ int Score, Bonus;};
void Play(GAME &g, int N=10)
{
g.Score++;g.Bonus+=N;
}
void main()
{
GAME G={110,50};
Play(G,10);
cout<<G.Score<<":"<<G.Bonus<<endl;
Play(G);
cout<<G.Score<<":"<<G.Bonus<<endl;
Play(G,15);
cout<<G.Score<<":"<<G.Bonus<<endl;
}
(e) Find the output of the following program: 2
#include <iostream.h>
void Secret(char Str[ ])
{
for (int L=0;Str[L]!='\0';L++);
for (int C=0;C<L/2;C++)
if (Str[C]=='A' || Str[C]=='E')
Str[C]='#';
else
{
char Temp=Str[C];
Str[C]=Str[L-C-1];
Str[L-C-1]=Temp;
}
}
void main()
{
char Message[ ]="ArabSagar";
Secret(Message);
cout<<Message<<endl;
}
(f) In the following program, if the value of Guess entered by the user is 65, what will be
the expected output(s) from the following options (i), (ii), (iii) and (iv)? 2
#include <iostream.h>
#include <stdlib.h>
void main()
{
int Guess;
randomize();
cin>>Guess;
for (int I=1;I<=4;I++)
{
New=Guess+random(I);
cout<<(char)New;
}
}
(i) ABBC
(ii) ACBA
(iii) BCDA
(iv) CABD
2.(a) What is the difference between Actual Parameter and Formal Parameters?
Also, give a suitable C++ code to illustrate both. 2
(b) Write the names of the header files to which the following belong: 1
(i) frexp() (ii) isalnum()
(c) Rewrite the following program after removing the syntactical errors (if any).
Underline each correction. 2
#include <iostream.h>
struct Pixels
{ int Color,Style;}
void ShowPoint(Pixels P)
{ cout<<P.Color,P.Style<<endl;}
void main()
{
Pixels Point1=(5,3);
ShowPoint(Point1);
Pixels Point2=Point1;
Color.Point1+=2;
ShowPoint(Point2);
}
(d) Find the output of the following program: 3
#include <iostream.h>
void Changethecontent(int Arr[ ], int Count)
{
for (int C=1;C<Count;C++)
Arr[C-1]+=Arr[C];
}
void main()
{
int A[]={3,4,5},B[]={10,20,30,40},C[]={900,1200};
Changethecontent(A,3);
Changethecontent(B,4);
Changethecontent(C,2);
for (int L=0;L<3;L++) cout<<A[L]<<'#';
cout<<endl;
for (L=0;L<4;L++) cout<<B[L] <<'#';
cout<<endl;
for (L=0;L<2;L++) cout<<C[L] <<'#';
}
(e) Find the output of the following program: 2
#include <iostream.h>
struct Game
{
char Magic[20];int Score;
};
void main()
{
Game M={"Tiger",500};
char *Choice;
Choice=M.Magic;
Choice[4]='P';
Choice[2]='L';
M.Score+=50;
cout<<M.Magic<<M.Score<<endl;
Game N=M;
N.Magic[0]='A';N.Magic[3]='J';
N.Score-=120;
cout<<N.Magic<<N.Score<<endl;
}
(f) In the following program, if the value of N given by the user is 20, what
maximum and minimum values the program could possibly display? 2
#include <iostream.h>
#include <stdlib.h>
void main()
{
int N,Guessnum;
randomize();
cin>>N;
Guessnum=random(N-10)+10;
cout<<Guessnum<<endl;
}
Q 3.)(i)Write the names of the header files to which the following belong :
(1/2) MARK EACH
puts(), sin(), setw(), sqrt(), strcat(), gets(), strcpy(), abs(), isupper(), pow(), random(),
strcmp(), isalnum(), isalpha(), fabs()
(ii) In the following program, find the correct possible output(s) from the options: (2)
#include <stdlib.h>
#include <iostream.h>
void main ( )
{
randomize( );
char Area[][10]= {“NORTH”, “SOUTH”, “EAST”, “WEST”};
int ToGo;
for(int I = 0; I <3, I++)
ToGo = random (2) +1;
Cout<<Areaa[ToGo]<<”:”;
} }
(iii) In the following C++ program what is the expected value of Myscore from Options (i)
to (iv) given below. Justify your answer. (2)
#include<stdlib.h>
#include<iostream.h>
void main( )
{randomize();
int Score[] = {25,20,34,56, 72, 63}, Myscore;
Myscore = Score[2 + random(2)];
cout<<Myscore<<endl;
}
(i) 25
(ii) 34
(iii) 20
(iv) None of the above
(iv) In the following program, if the value of N given by the user is 15, what maximum and
minimum values the program could possibly display? (2)
#include <iostream.h>
#include <stdlib.h>
void main()
int N,Guessme;
randomize();
cin>>N;
Guessme=random(N)+10;
cout<<Guessme<<endl;
(v) Find the output of the following program:
#include <iostream.h>
#include <ctype.h>
void main() {
char Text[ ]= “Mind@Work!”;
for (int I=0; Text[I] != „\0‟; I++)
{if ( ! isalpha(Text[I]))
Text[I]=‟*‟;
else if (isupper (Text[I]))
Text[I]=Text[I]+1;
else
Text[i]=Text[I=1];
}
cout<<Text;
}
Q4. (a) Differentiate between a global variable and a local variable. Also give suitable
example in C++. 2
. (b) Name the Header file(s) that shall be needed for successful compilation of the
following C++ code:
void main()
{
char st[20];
gets(st);
if(isaplha(st[0])
else
}
cout<<”Starts with alphabet”;
cout<<strlen(st);
}
(c) Rewrite the following program after removing syntactical error(s) if any.
Underline each correction. 2
#include<iostream.h>
#define SIZE =10
void main()
{
int a[SIZE]={10,20,30,40,50};
float x=2;
SIZE=5;
for(int i=0;i<SIZE;i++)
cout<<a[i]%x;
}
(d) Find the output of the following program : 2
#include<iostream.h>
#include<string.h>
struct Student
{
int rno;
char name[20];
};
void main()
{
student a[2]={1,”Amit”,}{2,”Sumit”}};
for(int i=0;i<2;i++)
{
cout<<”\n Rno”<<a[i].rno;
cout<<”\n Name “;
for(int j=0;j<strlen(a[i].name);j++)
cout<<a[i].name[i]<<” “;
(e) Find the output of the following program 2
#include<iostream.h>
void Modify(int &a,int b=10)
if(b%10==0)
a+=5;
for(int i=5;i<=a;i++)
cout<<b++<<”:”;
cout<<endl;
void Disp(int x)
if(x%3==0)
Modify(x);
Modify(x,3);
Disp(3);
Disp(4);
Modify(2,20);
}
(f) In the following C++ program , fill in the blanks for the statement1 with the
help of random function , if the number generated by the random number is
supposed to be between the range of 20-2000 2
#include<iostream.h>
#include<stdlib.h>
randomize();
r=___________________//statement 1
cout<<r;
(g) Define typedef with a suitable example. 2
Q5.) a. Define Macro with suitable example. 2
b. Which C++ header file (s) will be included to run /execute the following C++ code? 1
void main( )
{ int Last =26.5698742658;
cout<<setw(5)<<setprecision(9)<<Last; }
c. Rewrite the following program after removing any syntactical errors. Underline each
correction made. 2
#include<iostream.h>
void main( )
int A[10];
A=[3,2,5,4,7,9,10];
for( p = 0; p<=6; p++)
{ if(A[p]%2=0)
int S = S+A[p]; }
cout<<S; }
d. Find the output of the following C++ program: 2
#include<iostream.h>
void repch(char s[])
{
for (int i=0;s[i]!='\0';i++)
{
if(((i%2)!=0) &&(s[i]!=s[i+1]))
{
s[i]='@';
}
else if (s[i]==s[i+1])
{
s[i+1]='!';
i++;
}
}
}
void main()
{
char str[]="SUCCESS";
cout<<”Original String”<<str
repch(str);
cout<<"Changed String"<<str;
}
e. Find the output of the following : 3
#include<iostream.h>
void switchover(int A[ ],int N, int split)
{
for(int K = 0; K<N; K++)
if(K<split)
A[K] += K;
else
A[K]*= K;
}
void display(int A[ ] ,int N)
{
for(int K = 0; K<N; K++)
(K%2== 0) ?cout<<A[K]<<"%" : cout<<A[K]<<endl;
}
void main( )
{ int H[ ] = {30,40,50,20,10,5};
switchover(H,6,3);
display(H,6);
}
f. Observe the following C++ code and find out , which out of the given options i) to iv)
are the
expected correct output.Also assign the maximum and minimum value that can be assigned
to
the variable ‘Go’. 2
void main()
{ int X [4] ={100,75,10,125};
int Go = random(2)+2;
for (inti = Go; i< 4; i++)
cout<<X[i]<<”$$”;
}
i. 100$$75 ii. 75$$10$$125$$ iii. 75$$10$$ iv.10$$125$
CHAPTER – OBJECT ORIENTED PROGRAMMING
1.(a) What do you understand by Data Encapsulation and Data Hiding? Also, give a suitable
C++ code to illustrate both. 2
(b) Answer the questions (i) and (ii) after going through the following class: 2
class Seminar
{
int Time;
public:
Seminar() //Function 1
{
Time=30;cout<<"Seminar starts now"<<end1;
}
void Lecture() //Function 2
{
cout<<"Lectures in the seminar on"<<end1;
}
Seminar(int Duration) //Function 3
{
Time=Duration;cout<<"Seminar starts now"<<end1;
}
~Seminar()
//Function 4
{
cout<<"Vote of thanks"<<end1;
}
};
i) In Object Oriented Programming, what is Function 4 referred as and when does it get
invoked/called?
ii) In Object Oriented Programming, which concept is illustrated by Function 1 and
Function 3 together? Write an example illustrating the calls for these functions.
(c) Define a class TEST in C++ with following description: 4
Private Members
• TestCode of type integer
• Description of type string
• NoCandidate of type integer
• CenterReqd (number of centers required) of type integer
• A member function CALCNTR() to calculate and return the number of centers as
(NoCandidates/100+1)
Public Members
• A function SCHEDULE() to allow user to enter values for TestCode,
Description, NoCandidate & call function CALCNTR() to calculate the number of
Centres
• A function DISPTEST() to allow user to view the content of all the data members
(d) Answer the questions (i) to (iv) based on the following: 4
class PUBLISHER
{
char Pub[12];
double Turnover;
protected:
void Register();
public:
PUBLISHER();
void Enter();
void Display();
};
class BRANCH
{
char CITY[20];
protected:
float Employees;
public:
BRANCH();
void Haveit();
void Giveit();
};
class AUTHOR : private BRANCH , public PUBLISHER
{
int Acode;
char Aname[20];
float Amount;
public:
AUTHOR();
void Start();
void Show();
};
(i) Write the names of data members, which are accessible from objects belonging to class
AUTHOR.
(ii) Write the names of all the member functions which are accessible from objects
belonging to class BRANCH.
(iii) Write the names of all the members which are accessible from member functions of
class AUTHOR.
(iv) How many bytes will be required by an object belonging to class AUTHOR?
Q2. (a) What do you understand by Polymorphism? Give a suitable example of the
same. 2
(b) Answer the questions (i) and (ii) after going through the following program: 2
class Match
{
int Time;
public:
Match()
//Function 1
{
Time=0;
cout<<"Match commences"<<end1;
}
void Details() //Function 2
{
cout<<"Inter Section Basketball Match"<<end1;
}
Match(int Duration) //Function 3
{
Time=Duration;
cout<<"Another Match begins now"<<end1;
}
Match(Match &M) //Function 4
{
Time=M.Duration;
cout<<"Like Previous Match "<<end1;
}
};
i) Which category of constructor - Function 4 belongs to and what is the purpose
of using it?
ii) Write statements that would call the member Functions 1 and 3
(c) Define a class in C++ with following description: 4
Private Members
• A data member Flight number of type integer
• A data member Destination of type string
• A data member Distance of type float
• A data member Fuel of type float
• A member function CALFUEL() to calculate the value of Fuel as per the
following criteria
Distance Fuel
<=1000 500
more than 1000 and <=2000 1100
more than 2000 2200
Public Members
" A function FEEDINFO() to allow user to enter values for Flight Number,
Destination, Distance & call function CALFUEL() to calculate the quantity of Fuel
" A function SHOWINFO() to allow user to view the content of all the data members
(d) Answer the questions (i) to (iv) based on the following: 4
class CUSTOMER
{
int Cust_no;
char Cust_Name[20];
protected:
void Register();
public:
CUSTOMER();
void Status();
};
class SALESMAN
{
int Salesman_no;
char Salesman_Name[20];
protected:
float Salary;
public:
SALESMAN();
void Enter();
void Show();
};
class SHOP : private CUSTOMER , public SALESMAN
{
char Voucher_No[10];
char Sales_Date[8];
public:
SHOP();
void Sales_Entry();
void Sales_Detail();
};
(i) Write the names of data members which are accessible from objects belonging to
class CUSTOMER.
(ii) Write the names of all the member functions which are accessible from objects
belonging to class SALESMAN.
(iii) Write the names of all the members which are accessible from member functions of
class SHOP.
(iv) How many bytes will be required by an object belonging to class SHOP?
Q3.) Answer the questions (i) to (iv) based on the following code:
class Cricketer
char category[20];
protected:
float match_fee;
void calc_match_fee(float);
public:
Cricketer();
void CInput();
void CShow();
};
class Bowler : public Cricketer
char BOWLERName[20];
int Wickets;
public:
Bowler();
void BOWInput();
void BOWShow();
};
class Batsman : public Cricketer
char BASTSMANName[20];
int Centuries;
float Bat_Average;
public:
Batsman();
void BATInput();
void BATShow();
};
(i) Which type of Inheritance is shown in the above example?
(ii) How many bytes will be required by an object of the class Batsman?
(iii) Write name of all the data members accessible from member functions of the class
Bowler?
(iv) Write the name of all the member functions accessible by an object of the class
Batsman?
Q4. (a) Differentiate between a default and a parameterized constructor in context of class
and object . Give suitable example in C++. 2
(b) Answer the questions (i) and (ii) after going through the following class : 2
class Computer
{
char C_name[20];
char Config[100];
public:
Computer(Computer &obj); // function1
~Computer(); //function 2
};
(i) Write the statement(s) which will invoke the function 1.
(ii) Name the specific feature of the class shown by function 2. Also
write the time of its invoke.
(c) Define a class Shop in C++ with the description given below : 4
private members
name array of 40 characters
address array of 40 characters
type of item array of 3X20 characters
availqty array of 3 integers
totalqty array of 3 integers
public members
init() function to ask and store the values of address ,type
of item from the user and updates the totalqty and avialqty
accordingly .
display() function to display the details of the item in the
following format :
Name : <SHOP NAME >
Address :<ADDRESS >
Items : <Type of Item 1> <Type of Item 2> <Type Of item 3>
Balance Stock : <avialqty> <availqty> <avialqty>
(d) Answer the questions (i) to (iv) based on the following code : 4
class Goods
{
int id;
protected :
char name[20];
long qty;
void Incr(int n);
public :
Goods();
~Goods();
void get();
};
class Food_products : protected Goods
{
char exp_dt[10];
protected :
int id;
int qty;
public :
void getd();
void showd();
};
class Cosmetics : private Goods
{
int qty;
char exp_date[10];
protected :
int id;
public :
~Cosmetics();
Cosmetics();
void show();
};
(i) Name the all protected members of class Food_products.
(ii) Name the member functions accessible through the object of class
Food_products.
(iii) From the following, Identify the member function(s) that cannot be called
directly from the object of class Cosmetics
show()
getd()
get()
(iv) If the class cosmetics inherits the properties of food_products class also,
then name the type of inheritance.
Q5.) Differentiate between data abstraction and data hiding. 2
b. Answer the questions (i) and (ii) after going through the following class : 2
class Exam
{
int Rollno;
char Cname[25];
float Marks ;
public :
Exam( ) //Function 1
{
Rollno = 0 ;
Cname=””;
Marks=0.0;
}
Exam(int Rno, char candname) //Function 2
{
Rollno = Rno ;
strcpy(Cname,candname);
}
~Exam( ) //Function 3
{
cout << “Result will be intimated shortly” << endl ;
}
void Display( ) //Function 4
{
cout << “Roll no :”<<Rollno;
cout<<”Name :” <<Cname;
cout <<” Marks:”<<Marks;
}
} ;
(i)Which OOP concept does Function 1 and Function 2 implement.Explain?
(ii)What is Function 3 called? When will it be invoked?
c. Define a class Candidate in C++ with the following specification : 4
Private Members :
A data members Rno(Registration Number) type long
A data member Cname of type string
A data members Agg_marks (Aggregate Marks) of type float
A data members Grade of type char
A member function setGrade () to find the grade as per the aggregate marks
obtained by the student. Equivalent aggregate marks range and the respective grade as
shown
below.
Aggregate Marks Grade
>=80 A
Less than 80 and >=65 B
Less than 65 and >=50 C
Less than 50 D
Public members:
A constructor to assign default values to data members:
Rno=0,Cname=”N.A”,Agg_marks=0.0
A function Getdata () to allow users to enter values for Rno. Cname, Agg_marks and call
function setGrade () to find the grade.
A function dispResult( ) to allow user to view the content of all the data members.
d. Give the following class definition answer the question that is follow: 4
class University
{
char name [20];
protected :
char vc[20];
public :
void estd();
void inputdata();
void outputdata();
}
class College : protected University
{ int regno;
protected
char principal()
public :
int no_of_students;
void readdata();
void dispdata ( );
};
class Department : public College
char name[20];
char HOD[20];
public :
void fetchdata(int);
void displaydata( ); }
i). Name the base class and derived class of college.
ii) Name the data member(s) that can be accessed from function displaydata().
iii)What type of inheritance is depicted in the above class definition?
iv) What will be the size of an object (in bytes) of class Department?
SOLVED QUESTIONS AND ANSWERS
Q1. Name the header files of following built in functions :
Strcpy(), strcat(),log(), clrscr(),setw(),fabs(),isalnum(),isupper()
Ans. Strcpy()- string.h
Strcat()- string.h
log() - math.h
clrscr() - conio.h
setw - iomanip.h
fabs() - math.h
isalpnum() - ctype.h
isupper() - ctype.h
Q 2. Q4. What are the advantages and disadvantages of inline functions?
Ans. The main advantages of inline functions is that they save on the overheads of a
function call as the function is not invoked, rather its code is replaced in the program.
The major disadvantage of inline functions is that with more function calls, more memory
is wasted as for every function call, the same function code is inserted in the program.
Repeated occurrences of same function code waste memory space.
Q3.) What are static class members?
Ans A class can have static data members as well as static member functions The static
data members are the class variables that are common for all the objects of the class. Only
one copy of static data members is maintained which is shared by all the objects of the
class. They are visible only with in the class.
Q4.) What is the significance of access specifiers in a class?
Ans A class provides three access specifiers namely private, public and protected
(a) A data member declared as private or protected remains hidden from outside world and
it can only be accessed by the member functions of the class.
(b) A data member declared as public is made available to the outside world. That is, it can
be accessed by any function, any expression in the program but only by using an object of
the same class type.
Q5.) What is destructor ? What is its need ? Ans. Destructor:
A destructor is also a member function whose name is the same as the class name but is
preceded by tilde (‘~’)
A destructor takes no arguments and no return types can be specified for it. It is called
automatically by the compiler when an object is destroyed. A destructor cleans up the
storage ( memory area of the object) that is no longer accessible.
Need for Destructors
Allocated resources (like constructor) must be de-allocated before the object is destroyed.
It works as a de-allocating and releasing memory area and it perform our works as a clean
up tasks. Therefore, a destructor is equally useful as a constructor is.
class stud
{
stud() //constructor
{
cout << “ welcome”
}
~stud() //destructor
{
}
};
stud s1;
Q6.) What are the characteristics of a Constructors?
Ans. The constructor functions have certain special characteristics:-
1. Constructor fuctions are invoked automatically when the objects are created.
2. If a class has a constructor, each object of that class will be initialized before any use is
made of the object.
3. No return type can be specified for a constructor
4. They can not be inherited through a derived class can call the base class constructor
5. A constructor may not be static.
6. It is not possible to take the address of a constructor
7. Member functions may be called from within a constructor.
Q7.) What do you understand by default constructor?
Ans A default constructor is the one that takes no arguments. It is automatically invoked
when an object is created without providing any initial values. In case, the programmer has
not defined a default constructor, the compiler automatically generates it.
Q8.) What is copy constructor?
Ans Copy constructor:
A copy constructor is a constructor that can be used to initialize one object with the values
from another object of same class during declaration.
Q9.) What is the relationship between constructor and its class? Define constructor also
Ans Both carry the same name. It is a function that automatically initializes the data
members of an object at the time of its creation.
Constructor : It removes the memory held by an object, It is the last member function to be
called. Morevoer, it carries the same name of the class with tidle (~) as prefix.
Q10. What is Inheritance ?
Ans. It is a special feature of OOPS. Inheritance is capability to inherit the properties of
one class in to another class.
The derive new class is called derived class (sub class) and old class is called based class
(super class).
The Class whose properties of data members are inherited, is called Base Class or Super
Class and the class that inherits these properties, is called Derived Class or Sub Class.
Exp1:- If Class A inherits the data of Class B then we can say A is Sub Class and B is
Super Class.
Q11. Define the needs and objectives of Inheritance.
Ans The major needs and objectives of inheritance are:
(i) It ensures the closeness with the real world models.
(ii) It extend the functionality of an existing class.
(iii) It establishes “a kind of” relationship.
(iv) It helps in reuse of an existing class by a subclass (reusability).
(v) It implements transitive nature( if a class Y inherits properties from class X, then all
subclassY will automatically inherit the properties of X)
(vi) The redundancy can be reduced by abstracting a super class from few sub classes.
(vii) It is conept of reusability.
Q12.) Give the following definitions, answer the questions that follow:-
#include <iostream.h>
class book
{
char title[20];
char author[20];
int noof pages;
public:
void read();
void show();
};
class textbook: private textbook
{
int noofchapters, noof assignments;
protected:
int standard;
void readtextbook();
void showtextbook();
};
class physicsbook: public textbook
{
char topic[20];
public:
void readphysicsbook();
void showphysicsbook();
};
(i) Name the members, which can be accessed from the member functions of class
physicsbook.
(ii) Name the members, which can be accessed by an object of Class textbook.
(iii) Name the members, which can be accessed by an object of Class physicsbook.
(iv) What will be the size of an object (in bytes) of class physicsbook.
Ans
(i) standard , readtextbook(),showtextbook() and topic;
(ii) readtextbook() and showtextbook()
(iii) readphysicsbook(), showphysicsbook(), readtextbook() and showtextbook()
(iv) The size of object of physicsbook= size of book + size of Textbook + size of
physicsbook.
= 42+6+20 = 68 bytes
Q13.) Consider the following declarations and answer the questions given below:
Class vehicle
{
int wheels;
protected:
int passenger;
public:
void inputdata( int, int);
void outputdata();
};
class heavyvehicle: protected vehicle
{
int dieselpetrol;
protected:
int load;
public:
void readdata( int, int);
void writedata();
};
class bus:private heavyvehicle
{
char marks[20];
public:
void fetchdata(char);
void displaydata();
};
(i) Name the class and derived class of the class heavyvehicle.
(ii) Name the data members that can be accessed from function displaydata()
(iii) Name the data members that can be accessed by an object of bus class
(iv) Is the member function outputdata() accessible to the objects of heavyvehicle class.
Ans
(i) base class = vehicle, derived class = bus
(ii) The data members passenger, load, make are available to function display data
(iii) No data members can be accessed by the object of bus calss.
(iv) No member functions outputdata () is not accessible to the objects of heavy vehicle
class.
Q13 . What type of C++ class members ( data members and member functions) are not
inherited?
Ans Data member : Static data members of the base class are not inherited by the derived
class
Member functions: Constructors and destructors of base class are not inherited.
Q14.) Differentiate between Call by Value and Call by Reference. Ans. Comparison: S.N.
Parameters passed by value Parameters passed by reference
1. When we call a function by passing parameters by value, the values of actual parameters get copied into the formal parameters but not the variables themselves.
When we call a function by passing parameters by reference, formal parameters create a reference or pointer directly to the actual parameters.
2. The changes made in the values of formal parameters will not be reflected back to the actual parameters.
The changes made in the values of formal parameters will be reflected back to the actual parameters.
3. Example – // passing parameters by
value
#include <iostream.h>
void swap (int a, int b)
{ a=a+b;
b=a-b; c=a-b; cout << "Values inside
function \n”; cout<<”a=" << a << ", b="
<< b; }
int main ()
{ int x=1, y=3;
swap (x, y); cout << "Values inside
main \n”; cout << "x=" << x << ",
y=" << y; return 0; }
Output :
Values inside function
a=3, b=1
Values inside main
x=1, y=3
(Note: Changes made in formal parameters (a and b) are not reflected back to actual parameters (x and y))
Example - // passing parameters by
reference
#include <iostream.h>
void swap (int &a, int
&b) { a=a+b;
b=a-b; c=a-b; cout << "Values inside
function \n”; cout<<”a=" << a << ", b="
<< b; }
int main ()
{ int x=1, y=3;
swap (x, y); cout << "Values inside
main \n”; cout << "x=" << x << ",
y=" << y; return 0; }
Output :
Values inside function
a=3, b=1
Values inside main
x=3, y=1
(Note: Changes made in formal parameters (a and b) are reflected back to actual parameters
Theory Questions to be done in the notebook after revising all the chapters.
Q1.) Explain the following with examples
(i) Tokens
(ii) Identifiers
(iii) Literals
(iv) Pre-defined datatypes and User defined datatypes
Q2.) Differentiate between Implicit and Explicit type casting.
Q3.) Differentiate between run-time and syntax error. Give example of each.
Q4.) Differentiate between Procedural Programming and Object Oriented programming.
Q5.) Explain the basic concepts of OOP’s with examples.
Q6.) Explain the advantages and disadvantages of OOP’s
Q7.) What is base class? What is derived class? How are they interrelated?
Q8.) What is function overloading ? What is it’s need? Give an example illustrating its use in a C++ .
Q9.) Explain the process of disambiguation in C++ program.
Q10.) Explain the scope rules of a class.
Q11.) what are inline member function? Explain its use.
Q12.) What is the significance of access specifiers in a class?
Q13.)Explain the different visibility modes in context with Object Oriented Programming.
Q14.)What is the relationship of a class and its objects? How is memory allocated to a class and its objects?
Q15.) What are static data members of a class? Explain the characteristics of a static data member.
Q16.) What do you understand by a default constructor? What is its role? How is it equivalent to a constructor
having default arguments?
Q17.)What do you understand by constructor and destructor functions used in classes? How are these functions
different from other member functions ?
Q18.) What is copy constructor? Elaborate with suitable examples.
Q19.) Discuss the various situations when a copy constructor is automatically invoked.
Q20.) What are the advantages of inheritance in Object oriented programming?
Q21.)Differentiate between members, which are present within the private visibility mode with those which are
present within the public visibility modes.
Q22.) Describe how is an object of a class that contains objects of other classes created?
Boolean Algebra
Q23.)What is the significance of Principle of Duality?
Q24.) Write the dual of the following Boolean expression
(a) (x+y’) (b) xy+xy’+x’y
(c) a+a’b+b’ (d) (x+y’+z)(x+y)
Q25.) State all the basic theorems of Boolean Algebra
Q26.) What is Logic gate? Draw all the logic gates with truth table.
Q27.) Prove De Morgans Law