You are on page 1of 5

COMPUTER SCIENCE (083)

SHORT TEST, SET-1


Marking Scheme
Class: XII

Time: 3hrs Max. Marks: 70

General Instructions :

This question paper has 4 questions.


All the questions are compulsory.
Write the correct serial number of the question before attempting it.

Ans1 a) break, continue, goto, exit 4* =2


b) Run Time Error : Error occurring in a program during its execution. Program execution halts when
such an error is encountered.
Example:
int A, B, C;
cin>>A>>B;
C = A / B; //Runtime error if value of B is zero.
Syntax Error: Error occurred due to wrong syntax of language detected by the compiler during
compilation.
Example:
cout>>A C++ Program;
c) i) ctype.h, iomanip.h, iostream.h, math.h 4* =2
ii) conio.h, string.h, stdio.h, process.h 4* =2
d) i) #include <iostream.h>
const int Max = 10; //assignment operator was missing
void main()
{
int Numbers[Max] = {20,50,10,30,40}; //initialization was incorrect
for(int Loc=Max-1; Loc>=0; Loc--) //Loc was undefined
cout<<Numbers[Loc]; //input operator was used
}
ii) Corrected Program:
#include<iostream.h>
#include<stdio.h> // header file was missing
void main()
{ struct STUDENT
{ char stu_name[20];
char stu_sex;
int stu_age; //initialization not allowed inside structure definition
} student;
gets(student.stu_name); //structure reference was missing
cin>>student.stu_sex; //cannot use gets() function for a character input
student.stu_age = 17; //Ignored
}
e) i) EOEyMOEpEISM 3
ii) 6#10#12 1.5
12@18@30@36 1.5

f) (ii) 94 2
Ans2 a) A constructor that accepts no parameters is called the default constructor. The compiler
supplies a default constructor, if a class has no explicit constructor defined. It initializes the
data members by a dummy value. It is also used to create objects with default values. 1
Destructor is used to destroy the objects and deallocate the memory resources that have
been allocated by a constructor. It has same name as the class preceded by tilde (~). It takes
no arguments and no return types can be specified.
1
b) public visibility mode:
Members of a class declared under this visibility are accessible inside the class (in member
functions of the class) as well as by the Objects of that class (in any non member function of
the program, prototyped / defined after the class declaration). 1
private visibility mode:
Members of a class declared under this visibility are accessible only inside the class (in
member functions of the class). They can not be accessed outside the class. 1
class Example
{ int Priv;
public:
void Assign()
{ Priv =10; //private member accessible only inside class
}
};
void main()
{
Example E;
E.Assign( ); //public member accessible by Object
}
c) Object Oriented Programming
It emphasis on objects
It follows Bottom-Up approach in program design. 1
Its Data hiding feature prevents accidental change in data.
Its features like data encapsulation, polymorphism, inheritance are present.
Procedural Programming
It emphasis on doing things
It follows Top-down approach in program design.
Presence of Global variables increase changes of accidental change in data 1
Features like encapsulation, polymorphism, Inheritance are not available in this type of
programming.
d) i) No, since the constructor Retail has been defined in private section.
Suggested Correction: Constructor Retail() to be defined in public section of class.
ii) Cereal-Rice:100@25 1
e) Constructor A
Constructor A
Constructor B
Constructor C 2
Constructor B
Constructor A
Destructor A
Destructor B
Destructor C 1
Destructor B
Destructor A
Destructor A
f) Creating object 1
Creating object 2
Creating object 3 1.5
Creating object 4
Creating object 5
Destroying object 5
Destroying object 4
Destroying object 3 1.5
Destroying object 2
Destroying object 1

g) i) Polymorphism(Constructor Overloading) 1
ii) Test::Test(char P[], int M)
{ strcpy(Paper, P); 1
Marks = M;
}
iii) Test::Test(Test &t)
{ strcpy(Paper, t.Paper); 1
Marks = t.Marks;
}
iv) Test T1; //for Function 1
Test T2( Computer Sciencde, 100); //for Function 3
v) Destructor 1
vi) Test T3=T2; or Test T3(T2); 1

Ans3 a) variable x is not a static so it cannot be used in static member function prn( ) 1
b) The main advantage of inline functions is that they save on the overheads of a function call as the
function is not invoked, rather its code is replaced in the program. 1
The major disadvantage of inline functions is that with more function calls, more memory is wasted as
for every function call, the same function code is inserted in the program. Repeated occurrences of
same function code waste memory space.
1
c) Member functions have full access privilege to both the public and private members of the class
while, in general, nonmember functions have access only to the public members of the class
1
Member functions are defined within the class scope that is they are not visible the scope of class.
Nonmember functions are also visible outside the scope of class. 1
d) class Tour
{ char TCode[5];
int NoofAdults;
int NoofKids; 1
int Kilometres;
float TotalFare;
public:
Tour()
{ TCode = NULL;
NoofAdults = 0;
NoofKids = 0; 1
Kilometres = 0;
TotalFare = 0;
}
void AssignFare( )
{ if(Kilometres>=1000)
TotalFare = NoofAdults*500 + NoofKids*250;
else if(Kilometres>=500) 1
TotalFare = NoofAdults*300 + NoofKids*150;
else
TotalFare = NoofAdults*200 + NoofKids*100;
}
void EnterTour( )
{ cin>>TCode;
cin>>NoofAdults;
cin>>NoofKids;
cin>>Kilometres;
AssignFare( ); 1
}
void ShowTour( )
{ cout<<TCode<< <<NoofAdults<< <<NoofKids<< <<Kilometres;
cout<<TotalFare; 1
}
};
e) class RESORT
{ int Rno;
char Name[20];
float Charges; 1
int Days;
float COMPUTE();
public:
void Getinfo();
void Dispinfo();
};
void RESORT::Getinfo()
{ cin>>Rno;
gets(Name); 1
cin>>Charges;
cin>>Days;
}
void RESORT::Dispinfo()
{ cout<<Rno<< <<Name<< <<Charges<< <<Days<< ; 1
cout<<COMPUTE()<<endl;
}
float RESORT::COMPUTE()
{ float Amount = Charges*Days;
if(Amount>11000) 1
Amount = 1.02*Days*Charges;
return Amount;
}

Ans 4 a) In Multilevel inheritance, a class inherits it's properties from another derived class transitively.

A
B

C
In Hybrid inheritance,

B C

D
a) i) Hierarchical Inheritance is shown in the above example. 1
ii) 116 bytes 1
iii) artfilm::theme 1
iv) None 1
v) Multiple Inheritance 1
vi) film class constructor will be called first at the time of declaration of an object of class artfilm. 1

b) i) 118 bytes will be required by an object of class Dealer. 1


ii) Multiple Inheritance is illustrated in the above C++ code. 1
iii) Constructor of class car will be called first at the time of declaration of an object of class Dealer.
1 iv) Dealer::enterdetails( ), Dealer::showdetails( )
1
Car::entercardetail( ), Car::showcardetail( );
v) No_of_dealers, dealers_name, No_of_products, stereo_type, sheet_cover, Company 1
vi) Data Member: Price; 1
Member function: enteraccessoriesdetails( );
showaccessoriesdetails( );
.

You might also like