Kendriya Vidyalaya Nda Pune-23 Computer Science (083) Class-XII (Monthly Test-September)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

KENDRIYA VIDYALAYA NDA PUNE-23

Computer Science (083)


Class- XII
(Monthly Test-September)
Time: 1:30hrs M.M: 40
Instructions:
i. All Questions are Compulsory.
ii. Programming Language: Section A : C++

Section : A (C++)
Q1 a. Define Macro with suitable example. 2

b. Which C++ header file (s) will be included to run /execute the following C++ code? 1
void main( )
{ int Last =26.5698742658;
cout<<setw(5)<<setprecision(9)<<Last; }

c. Rewrite the following program after removing any syntactical errors. Underline each
correction made. 2
#include<iostream.h>
void main( )
int A[10];
A=[3,2,5,4,7,9,10];
for( p = 0; p<=6; p++)
{ if(A[p]%2=0)
int S = S+A[p]; }
cout<<S; }
d. Find the output of the following C++ program: 2
#include<iostream.h>
void repch(char s[])

1
{
for (int i=0;s[i]!='\0';i++)
{
if(((i%2)!=0) &&(s[i]!=s[i+1]))
{
s[i]='@';
}
else if (s[i]==s[i+1])
{
s[i+1]='!';
i++;
}
}
}
void main()
{
char str[]="SUCCESS";
cout<<”Original String”<<str
repch(str);
cout<<"Changed String"<<str;
}
e. Find the output of the following : 3
#include<iostream.h>
void switchover(int A[ ],int N, int split)
{
for(int K = 0; K<N; K++)
if(K<split)
A[K] += K;
else
A[K]*= K;
}

2
void display(int A[ ] ,int N)
{
for(int K = 0; K<N; K++)
(K%2== 0) ?cout<<A[K]<<"%" : cout<<A[K]<<endl;
}
void main( )
{ int H[ ] = {30,40,50,20,10,5};
switchover(H,6,3);
display(H,6);
}

f. Observe the following C++ code and find out , which out of the given options i) to iv) are the
expected correct output.Also assign the maximum and minimum value that can be assigned to
the variable ‘Go’. 2
void main()
{ int X [4] ={100,75,10,125};
int Go = random(2)+2;
for (inti = Go; i< 4; i++)
cout<<X[i]<<”$$”;

i. 100$$75 ii. 75$$10$$125$$ iii. 75$$10$$ iv.10$$125$

Q2a. Differentiate between data abstraction and data hiding. 2

b. Answer the questions (i) and (ii) after going through the following class : 2
class Exam
{
int Rollno;
char Cname[25];
float Marks ;
public :
Exam( ) //Function 1
{
Rollno = 0 ;
Cname=””;
Marks=0.0;

3
}
Exam(int Rno, char candname) //Function 2
{
Rollno = Rno ;
strcpy(Cname,candname);

}
~Exam( ) //Function 3
{
cout << “Result will be intimated shortly” << endl ;
}
void Display( ) //Function 4
{
cout << “Roll no :”<<Rollno;
cout<<”Name :” <<Cname;
cout <<” Marks:”<<Marks;
}
};
(i)Which OOP concept does Function 1 and Function 2 implement.Explain?
(ii)What is Function 3 called? When will it be invoked?
c. Define a class Candidate in C++ with the following specification : 4
Private Members :
A data members Rno(Registration Number) type long
A data member Cname of type string
A data members Agg_marks (Aggregate Marks) of type float
A data members Grade of type char
A member function setGrade () to find the grade as per the aggregate marks
obtained by the student. Equivalent aggregate marks range and the respective grade as shown
below.
Aggregate Marks Grade
>=80 A
Less than 80 and >=65 B

4
Less than 65 and >=50 C
Less than 50 D
Public members:
A constructor to assign default values to data members:
Rno=0,Cname=”N.A”,Agg_marks=0.0
A function Getdata () to allow users to enter values for Rno. Cname, Agg_marks and call
function setGrade () to find the grade.
A function dispResult( ) to allow user to view the content of all the data members.

d. Give the following class definition answer the question that is follow: 4
class University
{
char name [20];
protected :
char vc[20];
public :
void estd();
void inputdata();
void outputdata();
}
class College : protected University
{ int regno;
protected
char principal()
public :
int no_of_students;
void readdata();
void dispdata ( );
};
class Department : public College
char name[20];

5
char HOD[20];
public :
void fetchdata(int);
void displaydata( ); }
i). Name the base class and derived class of college. 1
ii) Name the data member(s) that can be accessed from function displaydata().
iii)What type of inheritance is depicted in the above class definition?
iv) What will be the size of an object (in bytes) of class Department?
Qs. 3a. An integer array A [30][40] is stored along the column in the memory. If the element
A[20][25] is stored at 50000, find out the location of A[25][30]. 3

c. Write a function to sort any array of n elements using insertion sort . Array should be passed
as argument to the function. 3
d. Write a function NewMAT(int A[][],int r,int c ) in C++, which accepts a 2d array of integer and
its size as parameters divide all those array elements by 6 which are not in the range 60 to
600(both values inclusive) in the 2d Array . 2

Q4a.Consider a file F containing objects E of class Emp. 1

i) Write statement to position the file pointer to the end of the file

ii) Write statement to return the number of bytes from the beginning of the file to the
current position of the file pointer.

b. Write a function RevText() to read a text file “ Input.txt “ and Print only word starting with ‘I’
in reverse order . 2

Example: If value in text file is: INDIA IS MY COUNTRY Output


will be: AIDNI SI MY COUNTRY

c. Write a function in C++ to search and display details, whose destination is “Chandigarh”from
binary file “Flight.Dat”. Assuming the binary file is containing the objects of the
following class: 3
class FLIGHT
{ int Fno; // Flight Number Flight
public: char From[20]; //
Starting Point Flight
char * GetFrom ( ); { // return from; }
char To[20];
char * GetTo( ); { Destination
return To; }
void input() { 6
{ cin>>Fno>>; gets(From); get(To); }
}; void show( )
cout<<Fno<< “:”<<From << “:” <<To<<endl; }

d. What is this pointer? What is its significance? 2

You might also like