Vous êtes sur la page 1sur 6

DELHI PUBLIC SCHOOL GHAZIABAD

Class XII
Mid Term Exam Session 2019-2020
Subject :- Computer Science
(SET A)
GENERAL INSTRUCTIONS
 All questions are compulsory and are to be answered with respect to C++ programming language.

MM. 70 Time 3 Hrs.

Q1
a. Name the header files for the following functions. 2
i. setw() ii. abs() iii rename() iv getche()

b. Deepa has just started working as a programmer in STAR SOFTWARE company. In the company she has got 2
her first assignment to be done using a C++ function to find the smallest number out of a given set of numbers
stored in a one-dimensional array. But she has committed some logical mistakes while writing the code and is
not getting the desired result. Rewrite the correct code underlining the corrections done. Do not add any
additional statements in the corrected code.
int find(int a[],int n)
{ int s=a[0];
for(int x=1;x<n;x++)
if(a[x]>s)
a[x]=s;
return(s);
}
c. Rewrite the correct code underlining the corrections done. Do not add any additional statements in the 2
corrected code.
typedef char[80] STR;
void main()
{
Txt STR;
gets(Txt);
cout<<Txt[0]<<’\t<<Txt[2]; cout<<Txt<<endline; }

d. Write the output of the following C++ program code : 2


Note : Assume all required header files are already being included in the program
#include<iostream.h>
#include<ctype.h>
void Mycode(char Msg[],char CH)
{
for(int cnt=0;Msg[cnt]!=‘\0’;cnt++)
{ if(Msg[cnt]>=‘B’&& Msg[cnt]<=‘G’)
Msg[cnt]=tolower(Msg[cnt]);
else
if(Msg[cnt]==‘N’||Msg[cnt]==‘n’ || Msg[cnt]==‘ ’)
Msg[cnt]=CH;
else
if(cnt%2==0)

COMPUTER SCIENCE Page 1 of 6


Msg[cnt]=toupper(Msg[cnt]);
else
Msg[cnt]=Msg[cnt–1];
}}
void main( )
{ char MyText[]="Input Raw";
Mycode(MyText,‘@’);
cout<<"NEW TEXT:"<<MyText<<endl; }

e. Read the following C++ code carefully and find out, which out of the given options (i) to (iv) are the 2
expected correct output(s) of it. Also, write the maximum and minimum value that can be assigned to the
variable Taker and PICKER used in the code :

void main( ) {
int GuessMe[4]={100,50,200,20};
int Taker=random(2)+2;
for (int Chance=0;Chance<Taker;Chance++)
cout<<GuessMe[Chance]<< # ;
}
(i) 100# (ii) 50# 200# (iii) 100# 50# 200# (iv) 100# 50

f. Which out of the given functions can be overloaded? Give Reasons. 2


display(int x=10);
display(int &x);
display(int x);
display(int x, char ch);

Q2
What is a copy constructor? Give a suitable example in C++ to illustrate with its definition within a class and a 2
a. declaration of an object with the help of it.

b. Write the definition of a class CITY in C++ with following description: 4

Private Members
- Ccode //Data member for City Code (an integer)
- CName //Data member for City Name (a string)
- Pop //Data member for Population (a long int)
- KM //Data member for Area Coverage (a float)
- Density //Data member for Population Density (a float)
- DenCal() //A member function to calculate ---
//Density as Pop/KM
Public Members
- Record() //A function to allow user to enter values of
//Acode,Name,Pop,KM and call DenCal() function
- View() //A function to display all the data members
//also display a message ”Highly Populated City”
//if the Density is more than 10000

c. Answer the following questions after going through the following class: 5

class Personal { int Class,Rno;


char Section;

COMPUTER SCIENCE Page 2 of 6


protected:
char Name[20];
public:
personal();
void pentry();
void Pdisplay();
};
class Marks: private Personal
{
float M[5];
protected:
char Grade[5];
public:
Marks(); void Mentry(); void Mdisplay(); };
class Result: public Marks
{
float Total, Agg;
public:
char FinalGrade, comments[20];
Result();
void Rcalculate(); void Rdisplay(); };
(i) Which type of inheritance is shown in the above example?
(ii) Write the names of those data members, which can be directly accessed from the
objects of class Result.
(iii) Write the names of those member functions which can be directly accessed from the
objects of class Result.
(iv) Write names of those data members, which can be directly accessed from the Mentry()
function of class Marks.
v) what is the size in bytes of the class Result.

d. Observe the following C++ code and answer the questions (i) and (ii) : 2
class Passenger
{
long PNR; char Name[20];
public:
Passenger() //Function 1
{ cout<<”Ready”<<endl; }
void Book(long P,char N[]) //Function 2
{ PNR = P; strcpy(Name, N); }
void Print() //Function 3
{ cout≪PNR ≪ Name ≪endl; }
~Passenger() //Function 4
{ cout≪”Booking cancelled!”≪endl; }
};

(i) Fill in the blank statements in Line 1 and Line 2 to execute Function 2 and Function 3 respectively in the
following code :
void main()
{
Passenger P;
___________ //Line 1
COMPUTER SCIENCE Page 3 of 6
___________ //Line 2
}//Ends here
(ii) Which function will be executed at } / / Ends here ? What is this function referred as?

e. What are the different types of memory allocation in C++. Explain with the help of example. 2
Q3
a. Write code for a function void EvenOdd (int T [ ], int C) in C++, to add 1 in all the odd values and 2 in all the 2
even values of the array T.
b. Write the definition of a function SumEO(int VALUES[3][3]) in C++, which should display the sum of even 2
values and sum of odd values of the array separately.
Example: If the array VALUES contains
25 20 22 21 52

Then the function should display the output as:


Sum of even values = 42(i.e 20 + 22)
Sum of odd values = 99(i.e 25 + 21+53)
c. An array A[20][30] is stored along the row in the memory with each element 3
requiring 4 bytes of storage. If the base address of array A is 32000, find out the location of A[15][10]. Also,
find the total number of elements present in this array.
Or
An array P[50] [60] is stored in the memory along the column with each of the element occupying 2 bytes,
find out the memory location for the element P[10][20], if the Base Address of the array is 6800.

d. Write the definition of a member function PUSH() in C++, to add a new book in a dynamic stack of 4
BOOKS considering the following code is already included in the program:
struct BOOKS
{ char ISBN[20], TITLE[80];
BOOKS *Link;
};
class STACK
{ BOOKS *Top;
public:
STACK()
{Top=NULL;}
void PUSH(); void
POP();
~STACK();
};
e. Write the definition of a member function DELETE() for a class QUEUE in C++, to remove a product 4
from a dynamically allocated Queue of products considering the following code is already written as a part
of the program.
struct PRODUCT {int PID; char PNAME[20]; PRODUCT *Next; };
class QUEUE {PRODUCT *R,*F;
public: QUEUE(){R=NULL;F=NULL;} void INSERT();void DELETE(); ~QUEUE(); };

F Evaluate the following postfix expression. Show the status of stack after execution of each operation 4
separately :
i. T, F, NOT, AND, T, OR, F, AND
ii. 250,45,9,/,5,+,20,*,-

g. Convert the following infix expression to its equivalent Postfix expression, showing the stack contents for 4
each step of conversion.
COMPUTER SCIENCE Page 4 of 6
i. U * V + R/(S-T)
ii. A+B*C^D-E
Q4
a. Write a definition for function COSTLY() in C++ to read each record of a binary file GIFTS.DAT, find and 3
display those items, which are priced more than 2000. Assume that the file GIFTS.DAT is created with the
help of objects of class GIFTS, which is defined below:
class GIFTS
{ int CODE;char ITEM[20]; float PRICE; public:
void Procure()
{cin>>CODE; gets(ITEM);cin>>PRICE;
}
void View()
{ cout<<CODE<<":"<<ITEM<<":"<<PRICE<<endl;
} float GetPrice() {return PRICE;} };
b. Write function definition for TOWER() in C++ to read the content of a text file WRITEUP.TXT, count the 3
presence of word TOWER and display the number of occurrences of this word.
Note :
- The word TOWER should be an independent word
- Ignore type cases (i.e. lower/upper case) Example:
If the content of the file WRITEUP.TXT is as follows:
Tower of hanoi is an interesting problem.Mobile phone tower is
away from here. Views from EIFFEL TOWER are amazing.
The function TOWER () should display the following:
3
c. Write a function AECount() in C++, which should read each character of a text file NOTES.TXT, should 3
count and display the occurrence of alphabets A and E (including small cases a and e too).
d. Consider a file “SCHOOLS.DAT” containing the following records. 1
SCode SName NOT
1001 Brains School 100
1003 Child Life School 115
1002 Care Share School 300
1006 Educate for life School 50
1005 Guru Shishya Sadan 195
1004 Holy Education School 140
1010 Play School 95
1008 Innovate Excel School 300
1011 Premier Education School 200
1012 Uplifted Minds School 100
Predict the output of given code considering the above data in the file.
void main{)
{
fstream SFIN; SFIN.open("SCHOOLS.DAT",ios:: binary| ios::in) ;
SCHOOLS S; SFIN.seekg(5 * sizeof(S));
SFIN.read((char*)&C,sizeof(S));
S.Display();
cout<<"RECORD: "<< SFIN.tellg()/sizeof(S) + 1 <<endl;
SFIN.close() ; }
e. Observe the program segment given below carefully and fill the blanks marked as Statement 1 and Statement 2
2 using tellg() and seekp() functions for performing the required task.
#include <fstream.h>
class Client
{ long Cno; char Name[20], Email[30] ;

COMPUTER SCIENCE Page 5 of 6


public: //Function to allow user to enter the Cno, Name, Email
void Enter() ; //Function to allow user to enter (modify) Email
void Modify() ; long ReturnCno() {return Cno;} };
void ChangeEmail() { Client C; fstream F; F.open (‘‘INFO.DAT’’,ios::binary|ios::in|ios::out);
long Cnoc;//Client’s no. whose Email needs to be changed
cin>>Cnoc;
while (F.read((char*)&C, sizeof(C))) {
if (Cnoc= =C.ReturnCno()) {
C.Modify();
int Pos = __________//To find the current position of file pointer //Statement 1
_______________//To move the file pointer to write the modified record
//back onto the file for the desired Cnoc // Statement 2
F.write((char*)&C, sizeof(C)); }} F.close(); }

Q5
a. Observe the following table carefully and write the names of the most appropriate 8
columns, which can be considered as
(i) candidate keys and (ii) primary key.

b. Write SQL Queries for the following.

i. To display item code, item name and price of all the items.
ii. To display Name and Price of all the Accessories in ascending order of their Price.
iii. To display details of the items whose price is more that 4000.
iv. Increase the price of stapler Mini by Rs 5 in the table.
v. Delete all the records from the table.
vi. What is the cardinality and degree of the above table?

COMPUTER SCIENCE Page 6 of 6

Vous aimerez peut-être aussi