PRACTICE PAPER
1)a)
Write and 2 characteristics of a constructor and a destructor.
b) Are
the default constructor and constructor with default parameter same?Give
reason.
c) Give
any 2 differences between a constructor and a normal function.
d) Given
the following :
class
Distance
{
private:
int
feet;
float inches;
public:
--------------
--------------
};
void main()
{
Distance dist1, dist3;
//define two lengths
Distance dist2(11,
6.25); //define, initialize dist2
dist1.getdist(); //get
dist1 from user
dist3 =
dist1.add_dist(dist2); //dist3 = dist1 + dist2
cout
<< “\ndist1 = “; dist1.showdist(); // print dist1
cout << “\ndist2
= “; dist2.showdist(); // print dist2
}
Complete the above
class description with necessary constructors and member function definitions.
e)
Answer the questions (a) and (b) after
going through the class definition:
class
Force
{
int
power;
public:
Force() // constructor 1
{power=0;}
Force(int
z) // constructor 2
{
power=Z;
}
Force(Force
&F) // constructor 3
{power=F.power;}};
a)
What type of constructor is constructor 3? Explain.
b)
Write statement to declare object for 'Force' so that it invokes constructor 2.
f)
Answer the questions (a) and (b) after
going through the following class:
class
cars
{
int
noofwheels,capacity;
float
mileage;
cars(); // function 1
cars(int
x, int y, float z); // function 2
cars(cars
&c); // function 3
};
a)
Write the definition of function 1, function 2 and function 3.
b)
Create object to invoke function 1, function 2, function 3.
2)
a) Define the following terms:
i) Abstract class
ii) Containership
b) Assume there is a class pony derived from base
class horse. Both classes contain a member function jump() that takes no
arguments. Write a statement that calls the member function jump() of class
horse from the object of class pony.
c) Consider the following declarations and answer
the questions (i to ii) that follow:
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],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?
d)
Answer the question (i) to (iv) based on the following:
class Organization
{
char Address[20];
double Budget, Income;
protected:
void Compute( );
public:
Organization( );
void Get( );
void Show( );
};
class WorkArea : public
Organization
{
char Address[20];
int Staff;
protected:
double Pay;
void Calculate( );
public:
WorkArea( );
void Enter( );
void Display( );
};
class ShowRoom : private
Organization
{
char Address[20];
float Area;
double Sale;
public:
ShowRoom( );
void Input( );
void Show( );
};
(i)
Name the type of inheritance illustrated in the above C++ code.
(ii)
Write the name of members, which are accessible from member function Input() of
class ShowRoom.
(iii)
Write the name of all the member functions, which are accessible from objects
belonging to class WorkArea.
(iv) How many bytes will be
required by an object of class ShowRoom?
3 a) Write a function AECount()
in C++, which should read each character of a text file NOTES.TXT, should count and display the occurrence of alphabets A and E (including small cases a
and e too).
Example :
If the file
content is as follows :
CBSE enhanced
its CCE guidelines further.
The AECount()
function should display the output as
A:1
E:7
b) Write a function in C++ to
read the content of a text file “Place.TXT” and display all those lines on
screen which are either starting with “P” or starting with “S”.
c) Write the command to place the
file pointer at the 10th and 4th record starting position using seekp() or
seekg() command. File object is ‘file’ and record name is ‘STUDENT’.
c)Write a function LtoD() that that
would display the corrected version of entire content of the file LINE.TXT with
all alphabets ‘D’ to be replaced as ‘L’,
‘d’ with ‘l’.
If
the file contained the following text:
Dearn
to dive and dive to dearn
Then
it should display the following
Learn
to live and live to learn
1) d)
class
Distance
{
private:
int
feet;
float
inches;
public:
Distance()
{
feet=12;inches=5.5;}
Distance(int
x, float y)
{
feet=x;
inches=y;
}
void
getdist()
{
cin>>feet>>inches;
}
Distance
add_dist(Distance d2)
{Distance
d3;
d3.feet=feet+d2.feet;
d3.inches=inches+d3.inches;
return
d3;
}
void
showdist()
{
cout<<feet<<"
"<<inches;
}
};
void
main()
{
Distance
dist1, dist3; //define two objects
Distance
dist2(11, 6.25); //define, initialize dist2
dist1.getdist();
//get dist1 from user
dist3
= dist1.add_dist(dist2); //dist3 = dist1 + dist2
cout
<< “\ndist1 = “; dist1.showdist(); // print dist1
cout
<< “\ndist2 = “; dist2.showdist(); // print dist2
}
e)
a) Copy constructor because the object is passed by
reference that is used to initialize another object with its values.
b) Force f(5) ;
f) a)cars::cars() // function 1
{
noofwheels=4;
capacity
= 1500;
mileage
= 5000;}
cars::cars(int
x, int y, float z) // function 2
{
noofwheels=x;
capacity=y;
mileage=z;
}
cars::cars(cars
&c) // function 3
{
noofwheels=c.noofwheels;
capacity=c.capacity;
mileage=c.mileage
}
void
main()
{
cars
c1, c2(5,1000,10000); // object
declaration
cars
c3=c1;
}
2)
c)
i)
None
ii)Enter(),
Show()
iii)
Data Members: Voucher_No[10],Sales_Date[8],Salary
Member functions : Register(), Enter(), Show(),
Sales_Entry(),Sales_Detail()
iv)
66 bytes
d)
i)
Hierarchical
ii)
Data members -
Address[20],Area,Sale
Member functions - Compute(), Get(),
Organization::Show(), Show()
iii)Enter(),
Display()
iv)68 bytes
2. (a)
Differentiate between protected and private members of a class in context of
Object Oriented Programming. Also give a suitable example illustrating
accessibility/non-accessibility of each using a class and an object in C++.
(b) Observe the following C++ code and
answer the questions (i) and (ii).
Note : Assume
all necessary files are included.
class TEST
{
long TCode;
char
TTitle[20];
float Score;
public:
TEST()
//Member Function 1
{
TCode=100;strcpy(TTitle,"FIRST
Test");Score=0;
}
TEST(TEST
&T) //Member Function 2
{
TCode=E.TCode+1;
strcpy(TTitle,T.TTitle);
Score=T.Score;
}
};
void main()
{
_______________
//Statement 1
_______________
//Statement 2
}
(i) Which Object Oriented Programming
feature is illustrated by the Member Function 1 and the Member Function 2
together in the class TEST ?
(ii) Write Statement 1 and Statement 2
to execute Member Function 1 and Member Function 2 respectively.
Answer
the questions (i) to (iv) based on the following :
class
First
{
int X1;
protected:
float X2;
public:
First();
void Enter1();
void Display1();
};
class Second :
private First
{
int Y1;
protected:
float Y2;
public:
Second();
void Enter2();
void
Display();
};
class
Third : public Second
{
int Z1;
public:
Third();
void
Enter3();
void
Display();
};
void
main()
{
Third
T; //Statement 1
___________________;
//Statement 2
}
i)Which type of Inheritance out of the
following is illustrated in the above example ?
Single Level Inheritance, Multilevel
Inheritance, Multiple Inheritance
(ii) Write the names of all the member
functions, which are directly accessible by the object T of class Third as
declared in main() function.
(iii) Write Statement 2 to call function
Display() of class Second from the object T of class Third.
(iv) What will be the order of execution
of the constructors, when the object T of class Third is declared inside main()
?
No comments:
Post a Comment