Documente Academic
Documente Profesional
Documente Cultură
Class XII
C++
Assignment
COMPUTER SCIENCE
CLASS XII(2009-10)
Assignment: Classes, Objects & Constructor
Define a function draw_nos() which takes an array of Housing as parameter, chooses and
displays the details of 2 houses selected randomly from the array. Use random function
to generate the registration no.
• Define constructor (outside the class P_rec) that accepts the values of data
• members from the user.
• Define the display_rec (outside the class P_rec) that shows the current values .
• Declare structures in C++ for Name and Phone . Declare the class P_rec.
7. Define a class Competition in C++ with the following descriptions:
Data Members
Event_no integer
Description char(30)
Score integer
qualified char
Member functions
• A constructor to assign initial values Event_No number as 101,Description as
“State level” Score is 50 , qualified ‘N’.
• Input() To take the input for event_no,description and score.
• Award(int) To award qualified as ‘Y’, if score is more than the cutoffscore passed
as argument to the function else ‘N’.
• Show() To display all the details.
8. Declare a class bank to represent bank account of 10 customers with the following
data members: name of depositor, account number, type of account(s for savings and c
for current account), balance amount. The class also contains the following member func-
tions:
• To initialize data members.
• To deposit money
• To withdraw money after checking minimum balance (say 1000)
• To display the data members on screen.
9. Answer the questions(i) and (ii) after going through the following class :
class Exam
{
int year;
public :
Exam(int y) { year=y; }
Exam(Exam &t);
}
(i) Create an object, such that it invokes constructor 1.
(ii) Write complete definition for constructor 2.
Q. 10 Describe the methods of accessing data members and member functions of a class
in the following cases:
i. Inside the main program
ii. Inside a member function of the same class
iii.Inside a member function of another class.
Q .13Given the following C++ code, answer the questions i and ii:
class readbook
{
public:
readbook( ) //Function1
{
cout<<”Open the Book”<<endl;
}
void readchapter( ) //Function 2
{
cout<<”Reading chapter one”<<endl;
}
~readbook( ) //Function 3
{
cout<<”Close the book”<<endl;
}
};
1. In OOP, what is Function 1 referred as and when does it get invoked/called?
2. In OOP, what is Function 3 referred as and when does it get invoked/called?