Topic Wise Solved Problems Question – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  


Shop
siteicon
CPP All :Topicwise Exam Questions: constructor-concepts siteicon
02A-2016 2

Differentiate between Constructor and Destructor functions giving suitable example using a class in C++. When does each of them execute?

CBSE12D-2016

02B-2016 2

Observe the following C++ code and answer the questions (i) and (ii). Assume all necessary files are included:

class FICTION
{
  long FCode;
  char FTitle[20];
  float FPrice;
public:
  FICTION() //Member Function 1
  {
    cout<<”Bought”<<endl;
    FCode=100;strcpy(FTitle,”Noname”);FPrice=50;
  }
  FICTION(int C,char T[],float P) //Member Function 2
  {
    FCode=C;
    strcpy(FTitle,T);
    FPrice=P;
  }
  void Increase(float P) //Member Function 3
  {
    FPrice+=P;
  }
  void Show()           //Member Function 4
  {
    cout<<FCode<<”:”<<FTitle<<”:”<<FPrice<<endl;
  }
  ~FICTION()            //Member Function 5
  {
    cout<<”Fiction removed!”<<end1;
  }
};
void main()                          //Line 1
{                                    //Line 2
  FICTION F1,F2(101,”Dare”,75);      //Line 3
  for (int I=0;I<4;I++)              //Line 4
  {                                  //Line 5
    F1.Increase(20);F2.Increase(15); //Line 6
    F1.Show();F2.Show();             //Line 7
  }                                  //Line 8
}                                    //Line 9

(i) Which specific concept of object oriented programming out of the following is illustrated by Member Function 1 and Member Function 2 combined together?
– Data Encapsulation
– Data Hiding
- Polymorphism
– Inheritance

(ii) How many times the message ”Fiction removed!” will be displayed after executing the above C++ code? Out of Line 1 to Line 9, which line is responsible to display the message “Fiction removed!”?

CBSE12D-2016

OOPs Concept Identification and Destructor Calling Identification 2

Observe the following C++ code and answer the questions (i) and (ii). Assume all necessary files are included:

class BOOK
{
  long Code ;
  char Title[20];
  float Price;
public:
  BOOK() //Member Function 1
  {
    cout<<”Bought”<<endl;
    Code=10;strcpy(Title,”NoTitle”);Price=100;
  }
  BOOK(int C,char T[],float P) //Member Function 2
  {
    Code=C;
    strcpy(Title,T);
    Price=P;
  }
  void Update(float P) //Member Function 3
  {
    Price+=P;
  }
  void Display() //Member Function 4
  {
    cout<<Code<<”:”<<Title<<”:”<<Price<<endl;
  }
  ~BOOK()        //Member Function 5
  {
    cout<<”Book Discarded!”<<end1;
  }
};
void main()                    //Line 1
{                              //Line 2
  BOOK B,C(101,"Truth",350};   //Line 3
  for (int I=0;I<4;I++)        //Line 4
  {                            //Line 5
    B.Update(50);C.Update(20); //Line 6
    B.Display();C.Display();   //Line 7
  }                            //Line 8
}                              //Line 9  

(i) Which specific concept of object oriented programming out of the following is illustrated by member Function 1 and member Function 2 combined together?

  • Data Encapsulation
  • Polymorphism
  • Inheritance
  • Data Hiding

(ii) How many times the message ”Book Discarded!” will be displayed after executing the above C++ code? Out of Line 1 to Line 9, which line is responsible to display the message ”Book Discarded!”

CBSE12A-2016