Upload
vannhi
View
213
Download
0
Embed Size (px)
Citation preview
KENDRIYA VIDYALAYA IIT KANPUR
FIRST UNIT TEST 2015
CLASS XII
COMPUTER SCIENCE
TIME 1 ½ HRS MM 40
1. What is the difference between automatic type conversion and type casting? Also, give a suitable C++ code to illustrate both. [2]
2. What do you understand by polymorphism? Also, give an example in C++ to illustrate t he same. [2]3. What is the difference between call by value and call by reference? Also, give a suitable C++ code to
illustrate both. [2]4. What do you understand by Data Encapsulation and Data Hiding? Also, give an example in C++ to
illustrate both. [2]5. What is the difference between copy constructor and parameterized constructor? Also, give a
suitable C++ code to illustrate both. [2]6. Which C++ header file(s) will be essentially required to included to run/execute the following C++
code: [1x3]a. void main()
{int Rno=34; char Name[] = “ABCD”;cout << setw(33)<<Rno<<setw(9)<<Name<<endl;}
b.
c. void main(){int Sno=34; char Item = “Soap; float Price=45.00;cout << setw(33)<<Sno<<setw(9)<<Item<<setw(7)<<sqrt(Price)<<endl;}
7. Rewrite the following C++ program code after removing the syntax error(s) (if any). Underline each correction. [2x3]
a. include <iostream.h>class TRAIN{long TrainNo;char Description[25];publicvoid Entry(){cin>>TrainNo; gets(Description);}void Display(){cout<<TrainNo<<”:”<<Description<<endl;}};void main(){TRAIN T; Entry.T(); Display.T();}
b. @include(iiostreamh>CLASS FLIGHT{long FlightCode;char Description[25];Public:void AddInfo();void ShowInfo();};
c. #include<iostream.h>Class Item{long Id, Qty;public:void Purchase{cin>>Id>>Qty;}void Sale(){cou t<<setw(5)<<Id<<” Old:”<<Qty<<endl;cout<<”New:”<<--Qty<<endl;}};void main(){Item I;Purchase();
I.Sale();}
8. Find the output of the following program code: [8]a. #include<iostream.h>
class TRAIN{int Mno, TripNo, PCount;public:TRAIN(int Tmno=1){Mno=Tmno;TripNo=0;PCount=0;}void Trip(int PC=20){TripNo++;PCount+=PC;}void StatusShow(){cout<<Mno<<”:”<<TripNo<<”:”<<PCount<<endl;}};void main(){TRAIN M(5),T;M.Trip();T.Trip(50);M.StatusShow();M.Trip(30);T.StatusShow();M. StatusShow();}
b. Find output
c. Find the output
9. Define a class SUPPLY in C++ with the following description: [4]Private members:
Code of type int FoodName of type string Sticker of type string FoodType of type string A member function GetType() to assign the values for FoodType as per the given sticker:
Sticker FoodTypeGREEN VegetarianYELLOW Contains EggRED Non-Vegetarian
Public members:
A function FoodIn() to allow user to enter values for Code, FoodName, Sticker and call function GetType() to assign respective FoodType
A function FoodOut() to allow user to view the content of all the data members10. Answer the questions (i) and (ii) after going through the following class code: [4]
class Hospital{Int Pno, Dno;public:Hospital(int PN); //Function 1Hospital(); //Function 2
3
Hospital(Hospital &H); //Function 3void In(); //Function 4void Disp(); //Function 5` Hospital(); //Function 6};void main(){Hospital H(20); //statement 1}i) Which of the functions out of Function 1, 2 ,3 , 4 or 5 will get executed when the statement
1 is executed in the above code.ii) Write a statement to declare a new object M with reference to already existing object H
using Function 3iii) Which concept of OOPs is illustrated through Function 1 to 3iv) What is Function 6 known asand does it get invoked?
11. Consider the following C++ code and anser the questions from (i) to (iv): [5]class University{
long City[30];protected:
University()void Register();void Display();
};
4
class Department: private University{
long Dcode[10];char HOD[20];
protected:double Budget;
public:Departement();void Enter();void Show();
};
class Student : public Department{
long Name[20];public:
Student();void Enroll();void View();
};
i) Which type of inheritance is shown in above exampleii) Write the names of those member functions which are directly accessed from the objects of
class studentiii) Write the names of those data members which can be directly accessible from the member
functions of class Studentiv) Is it possible to directly call function Display() of class University from an object of class
Department. (Yes/No)?v) How many bytes will be required by an object of class Student
**********************************************