0% found this document useful (0 votes)
5 views

class-xii-computer-sc-ut-1-2018-19

This document is a unit test for Class XII Computer Science with a focus on C++ programming. It includes various questions covering topics such as variable types, built-in functions, class definitions, and member functions. The test consists of multiple-choice questions, coding problems, and theoretical questions related to object-oriented programming concepts.

Uploaded by

7x8bqbhqv4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

class-xii-computer-sc-ut-1-2018-19

This document is a unit test for Class XII Computer Science with a focus on C++ programming. It includes various questions covering topics such as variable types, built-in functions, class definitions, and member functions. The test consists of multiple-choice questions, coding problems, and theoretical questions related to object-oriented programming concepts.

Uploaded by

7x8bqbhqv4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

UNIT TEST-1

CLASS-XII
SUB:- COMP.SC.
MM:-40 Time:- 90 Min
Instructions:-
(1) All questions are compulsory.
(2) Programming Language:- C++

Q 1. (a) What is the difference between local variable and global variable? Also give a suitable C++ code to illustrate both. 2
(b) Name the header file to be included for the use of following built in – functions (any two)
(a) rand() (b) toupper()
(c) pow() (d) exit() 2

(c)Find the output of the following program. 2


#include<iostream.h>
int global=20;
void fun(int &x, int y)
{ x=x-y;
y=x*10;
cout<<x<<’,’<<y<<’\n’; }
void main()
{ int global=8;
fun(::global,global);
cout<<global<<’,’<<::global<<”\n”;
fun(global,::global);
cout<<global<<’,’<<::global<<’\n’; }

(d) Find the output of the following program. 4


#include<iostream.h>
struct package
{ int length,breadth,height; };
void occupies(package m)
{ cout<<.length<<”x”
<<.breadth<<”x”;
cout<<.height<<endl; }
void main()
{ package p1={100,150,50},p2,p3;
++p1.length;
Occupies(p1);
P3=31;
++p3.breadth;
P3.breadth++;
Occupies(p3);
P2=p3;
P2.breadth+=50;
P2.height--;
Occupies(p2); }
(e) In the following program, if the value of N given by the user is 20, what maximum and minimum values the
program could possibly display? 2

#include <iostream.h>
#include <stdlib.h>
void main()
{
int N,Guessnum;
randomize();
cin>>N;
Guessnum=random(N-10)+10;
cout<<Guessnum<<endl;
}

(f) Identify the error in the following program : (Min. 3 errors) 3


void main()
{ First = 25, Last = 35 ;
Assign(First, Last) ;
int x = Assign(Last) ;
return 0; }
void Assign(int default1=23, int default2)
{ default1=default1+default2 ;
cout<< default1 >> default2; }

Q2. (a) Define a class TEST in C++ with following description: 5


Private Members
• TestCode of type integer
• Description of type string
• No of Candidate of type integer
• CenterReqd (number of centers required) of type integer
• A member function CALCNTR() to calculate and return the number of centers as
(NoCandidates/100+1)
Public Members
• A function SCHEDULE() to allow user to enter values for TestCode,Description, NoCandidate& call function CALCNTR() to
calculate the number of Centres.
• A function DISPTEST() to allow user to view the content of all the data members.

(b) Define a class in C++ with following description: 5


Private Members

 A data member Flight number of type integer


 A data member Destination of type string
 A data member Distance of type float
 A data member Fuel of type float
 A member function CALFUEL() to calculate the value of Fuel as per the following criteria
Distance Fuel
<=1000 500
more than 1000 and <=2000 1100
more than 2000 2200
Public Members
 A function FEEDINFO() to allow user to enter values for Flight Number, Destination, Distance & call function
CALFUEL() to calculate the quantity of Fuel
 A function SHOWINFO() to allow user to view the content of all the data members

(c) Questions are based on following class 4


Class student
{ private :
Int rollno ;
char name[21] ;
public :
student() // Function 1
{ cout<< “Student initialized” ;
rollno = 101;
strcpy(name, “”) ; }
student(int r, char *s) // Function 2
{ rollno = r ; strcpy (name, *s) ; }

Student(student S) // Function 3
{ rollno= S.rollno;
Strcpy(name, S.name) ; }

~Student() { cout<< “Object Student Deleted “ } // Function 4


};
i) Write the Names of Function 1 and Function 4.
ii) Write a statement to call the Function No 3.
iii) Write a statement to call function 2 .

(d) Answer the questions (i) to (v) based on the following code : 4
class Employee
{ int id;
protected:
char name[20];
char doj[20];
public :
Employee( ); ~Employee( );
void get( ); void show( );
};
class Daily_wager : protected Employee
{ Int wphour;
protected :
int nofhworked;
public :
void getd( );
void showd( );
};
class Payment : private Daily_wager
{ char date[10];
protected :
int amount;
public :
Payment( );
~Payment( );
void show( ); };
(i) Name the member functions, which are accessible by the objects of class Payment.
(ii) From the following, Identify the member function(s) that can be called directly from the object of class Daily_wager
class show( ), getd( ), get( )
(iii) Find the memory size of object of class Daily_wager.
(iv) What type of inheritance is there in this program.

(e) What do you understand about a member function? How does a member function differ from an ordinary function? 2
(f) Differentiate Private & Public visibility mode. 2
(g) How does a class enforce data-hiding, abstraction and encapsulation? 3

You might also like