CLASS XII - UNIT TEST-2 : COMPUTE SCIENCE (C++)


1)      Consider the following C++ code and answer the following code and answer the following questions:

class University
{
long Id;
char City[20];

protected:
char country[20];

public:
University();
void Register ();
void Display();
};

class Department : private University
{
long DCode[10];
char HOD[20];

protected:
double Budget;

public:
Department();
void Enter ();
void Show();
};

class Student : public Department
{
long RollNo;
char Name[20];

public:
Student();
void Enroll ();
void View ();
};

Questions (Answer any six) :
(i)                 Which type of Inheritance is shown in the above example?
(ii)               Name all protected members of class Student.
(iii)             Name all private members of class Department.
(iv)              Name the member functions which are directly accessed from the objects of class Student.
(v)                Name the data members which can be directly accessible from the member functions of class Student.
(vi)              How many bytes does an object belonging to class Student require?
(vii)            Is it possible to directly cell function Display() of class University from an object of class Department?

2)      List the forms/ types of inheritance supported by C++.

3)      What do you understand by base class and derived class? If a base class and a derived class each include a member function with the same name and arguments, which member function will be called by the object of the derived class, if the scope operator is not used.


4)      What is wrong with the following code, also mention the description of error in which line it occurs.

1.                   class X
2.                   {              protected:
3.                                   int a;      
4.                   };
5.                   class Y : public X
6.                   {              int k;
7.                                   public:
8.                                   void set(X x, int c)
9.                                   { X.a = c ; }
10.                };

5)      Fill in the blanks marked as Statement 1 and Statement 2, in the program segment given before with appropriate function for the required task.
class Agency
{
int ANo.                                                                         // Agent Code
char Aname[20];                                         // Agent Name
char Mobile[12];                                         // Agent Mobile No.

public:
void Enter();                                                                //Function to enter details of agent
void Disp();                                                                  //Function to display details of agent
int RAno() {return ANo;}
void UpdateMobile()                  //Function to update Mobile
{
        cout<<"Update Mobile: ";
        gets(Mobile);
}
};

void AgentUpdate()
{
fstream F;
Agency A;
int Updt=0,   UAno;
F.open("AGENT.DAT", ios::binary|ios::in|ios::out);
cout<<"Ano (Agent No - to update Mobile): ";
cin>>UAno;
while(!Updt && F.read((char*)&A,sizeof(A)))
{
if(A.RAno()==UAno)
//Statement 1: To call the function to Update Mobile No.
______________________ ;
//Statement 2: To reposition file pointer to re-write the updated object back in the file
______________________ ;
F.Write((char*)&A,sizeof(A));
Updt++;
}
if(Updt)
cout<<"Mobile Update for Agent: "<<UAno<<endl;
else
cout<<"Agent not in the Agency."<<endl;
F.close();
}

6)      What is the difference between seekp() and seekg()?

7)      Dissect the following statement in terms of file mode, stream object, file name and file operation.
fout.open(“Data.txt”,ios::app);
File Mode: ……………………                                                 Stream Object: ……………………                         
File Name: ……………………                                                 File Operation: ……………………
8)      Write a function in C++ to count the number of lowercase alphabets present in a text file “Profile.txt”.

9)      Assuming the class ANTIQUE as declared below, write a function in C++ to read objects of ANTIQUE from binary file “ANTIQUE.DAT” and display those antique items, which are priced between 10000 and 15000.

class ANTIQUE
{
                int ANO;
                char Aname[10];
                float Price;
                public:
                                void BUY()
                                {
                                                cin>>ANO;
                                                gets(Aname);
                                                cin>>Price;
                                }
                                void SHOW()
                                {
                                                cout<<ANO<<endl;
                                                cout<<Aname<<endl;
                                                cout<<Price<<endl;
                                }
                                float GetPrice(){ return Price;}
};

No comments

Post your comments

Powered by Blogger.