Answer the questions (i) to (iv) based on the following:
class Exterior
{
int OrderId;
char Address[20];
protected:
float Advance;
public:
Exterior();
void Book();
void View();
};
class Paint:public Exterior
{
int WallArea,ColorCode;
protected:
char Type;
public:
Paint();
void PBook();
void PView();
};
class Bill : public Paint
{
float Charges;
void Calculate();
public :
Bill();
void Billing();
void Print();
};
(i) Which type of Inheritance out of the following is illustrated in the above example?
– Single Level Inheritance
– Multi-Level Inheritance
– Multiple Inheritance
(ii) Write the names of all the data members, which are directly accessible from the member functions of class Paint.
(iii) Write the names of all the member functions, which are directly accessible from an object of class Bill.
(iv) What will be the order of execution of the constructors, when an object of class Bill is declared?
Write the definition of a function Alter(int A[], int N) in C++, which should change all the multiples of 5 in the array to 5 and rest of the elements as 0. For example, if an array of 10 integers is as follows:
A[0] | A[1] | A[2] | A[3] | A[4] | A[5] | A[6] | A[7] | A[8] | A[9] |
55 | 45 | 20 | 16 | 39 | 90 | 83 | 40 | 48 | 25 |
After executing the function, the array content should be changed as follows:
A[0] | A[1] | A[2] | A[3] | A[4] | A[5] | A[6] | A[7] | A[8] | A[9] |
5 | 0 | 5 | 0 | 0 | 5 | 0 | 5 | 0 | 5 |
A two-dimensional array P[20] [50] is stored in the memory along the row with each of its element occupying 4 bytes, find the address of the element [10] [30], if the element P[5] [5] is stored at the memory location 15000.
LOC(P[10][30])
= Loc(P[5][5])+ W[(ILBR)*C+(JLBC)]
= 15000 + 4[(105)*50 + (305)]
= 15000 + 4[ 5*50 + 25]
= 15000 + 4 *275
= 15000 + 1100
= 16100
Write the definition of a member function Pop() in C++, to delete a book from a dynamic stack of TEXTBOOKS considering the following code is already included in the program.
struct TEXTBOOKS
{
char ISBN[20]; char TITLE[80];
TEXTBOOKS *Link;
};
class STACK
{
TEXTBOOKS *Top;
public:
STACK(){Top=NULL;}
void Push();
void Pop();
~STACK();
};
Write a function REVCOL (int P[] [5], int N, int M) in C++ to display the content of a two-dimensional array, with each column content in reverse order.
Note: Array may contain any number of rows.
For example, if the content of the array is as follows:
15 | 12 | 56 | 45 | 51 |
13 | 91 | 92 | 87 | 63 |
11 | 23 | 61 | 46 | 81 |
The function should display output as:
11 | 23 | 61 | 46 | 81 |
13 | 91 | 92 | 87 | 63 |
15 | 12 | 56 | 45 | 51 |
Convert the following infix expression to its equivalent postfix expression, showing the stack contents for each step of conversion.
X / Y + U* (VW)
Write function definition for SUCCESS( ) in C++ to read the content of a text file STORY.TXT, count the presence of word STORY and display the number of occurrence of this word.
Note :
– The word STORY should be an independent word
– Ignore type cases (i.e. lower/upper case)
Example :
If the content of the file STORY.TXT is as follows:
Success shows others that we can do it. It is
possible to achieve success with hard work. Lot
of money does not mean SUCCESS.
The function SUCCESS () should display the following:
3
Write a definition for function Economic() in C++ to read each record of a binary file ITEMS.DAT, find and display those items, which costs less than 2500. Assume that the file ITEMS.DAT is created with the help of objects of class ITEMS, which is defined below:
class ITEMS
{
int ID;char GIFT[20]; float Cost;
public:
void Get()
{
cin>>CODE;gets(GIFT);cin>>Cost;
}
void See()
{
cout<<ID<<':'<<GIFT<<':'<<Cost<<endl;
}
float GetCost()
{
return Cost;
}
};
Find the output of the following C++ code considering that the binary file CLIENTS.DAT exists on the hard disk with records of 100 members.
class CLIENTS
{
int Cno;char Name[20];
public :
void In(); void Out();
};
void main()
{
fstream CF;
CF.open("CLIENTS.DAT",ios:: binary| ios::in) ;
CLIENTS C;
CF.read((char*)&C,sizeof(C));
CF.read((char*)&C,sizeof(C));
CF.read((char*)&C,sizeof(C));
int POS=CF.tellg()/sizeof(C);
cout<<"PRESENT RECORD:"<<POS<<endl;
CF.close()
}