Saved Bookmarks
| 1. |
Answer the question (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 () //Fuction 1{strcpy(Category,"Cereal");strcpy(Item,"Rice");Qty=100;Price=25;} public:void Show() //Function 2{ cout<<Category<<"-"<<Item<<":"<<Qty<<"@"<<Price<<endl;}};void main(){Retail R; //Statement 1R.Show(); //Statement 2}(i) Will Statement 1 initialize all the data members for object R with the values given in the Function 1? (Yes OR No). Justify your answer suggesting the correction(s) to be made in the above code.(ii) What shall be the possible output when the program gets executed? (Assuming, if required – the suggested correction(s) are made in the program) |
|
Answer» (i) No. Since the default constructor Retail() is declared inside private section, it cannot initialize the objects declared outside the class. Correction needed are: The constructor Retail() should be declared inside public section. (ii) Cereal-Rice:[email protected] |
|