Académique Documents
Professionnel Documents
Culture Documents
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.
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; }
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
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.
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
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
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] ;
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.
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?