OUTSIDE DELHI 2008
2.b. Answer the questions (i) and (ii) after going through the following program:
#include<iostream.h>
#include<string.h>
class Retail
{
char category[20];
char item[20];
int qty; float price;
retail () //function 1
{
strcpy (category, “cerial”);
strcpy (Item, “Rice”); qty =100 ;
price =25 ;
}
public; void show() //function 2
{
cout << category <<”-“<< Item << “:”<<Qty<<“@”<< price<<endl;
}
};
void main()
{
Retail R; //statement 1 R.
show (); //statement 2
}
(i) will statement 1 initialize all the data members for objects R with the given in the function 1 ? (YES OR NO). Justify your Answer suggesting the corrections(s) to be made in the above code.
Ans: No. The reason is the constructor should be defined under the public visibility label.
(ii) What shall be the possible out put when the program gets executed ? (Assuming, if required the suggested correction(s) are made in the program)
Ans: Possible Output: cerial–Rice:100@25
2.c. Define a class clothing in c++ with the following descriptions :
private members :
code | of type string |
type | of type string |
size | of type intiger |
material | of type string |
price | of type float |
A function calc_price( ) which calculates and assigns the value of GPrice as follows ;
For the value of material as “COTTON” :
Type | price (Rs) |
TROUSER | 1500 |
SHIRT | 1200 |
for material other than “COTTON”, the above mentioned GPprice price gets reduced by 25%