Вы находитесь на странице: 1из 32

SAMPLE PAPER – 2008-09

INTRODUCTORY COMPUTER SCIENCE (Theory)


CLASS – XII
Time allowed : 3 hours Maximum marks : 70
Note :
i) All the questions are compulsory .
ii) Programming Language : C++ .

1. a) What is the difference between #define & const ? Explain through example.
2
b) Name the header files that shall be required for successful compilation of the following C++ program : 1
main( )
{ char str[20];
cout<<fabs(-34.776);
cout<<”\n Enter a string : ”;
cin.getline(str,20);
return 0; }
c) Rewrite the following program after removing all the syntactical errors underlining each correction. (if any)2
#include<iostream.h>
#include<stdio.h>
struct NUM
{ int x;
float y;
}*p;
void main( )
{
NUM A=(23,45.67);
p=A;
cout<<”\n Integer = “<<*p->x;
cout<<”\n Real = “<<*A.y;
}
d) Find the output of the following program segment ( Assuming that all required header files are included in
the program ) : 3
void FUNC(int *a,int n)
{ int i,j,temp,sm,pos;
for(i=0;i<n/2;i++)
for(j=0;j<(n/2)-1;j++)
if(*(a+j)>*(a+j+1))
{ temp=*(a+j);
*(a+j)=*(a+j+1);
*(a+j+1)=temp; }
for(i=n-1;i>=n/2;i--)
{ sm=*(a+i);
pos=i;
for(j=i-1;j>=n/2;j--)
if(*(a+j)<sm)
{ pos=j;
sm=*(a+j); }
temp=*(a+i);
*(a+i)=*(a+pos);
*(a+pos)=temp; } }
void main( )
{
int w[ ]={-4,6,1,-8,19,5},i;
FUNC(w,6);
for(i=0;i<6;i++)
cout<<w[i]<<' ';}
e) Give the output of the following program ( Assuming that all required header files are included in the
program ) : 2
class state
{
private:
char *stname;
int size;
public:

1|Page
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
state( )
{ size=0;
stname=new char[size+1];}
state(char *s)
{ size=strlen(s);
stname=new char[size+1];
strcpy(stname,s); }
void disp( )
{ cout<<stname<<endl; }
void repl(state &a, state &b)
{size=a.size+b.size;
delete stname;
stname=new char[size+1];
strcpy(stname,a.stname);
strcat(stname,b.stname); } };
void main( )
{ char *st1="Punjab";
clrscr( );
state ob1(st1),ob2("Uttaranchal"),ob3("Madhyapradesh"),s1,s2;
s1.repl(ob1,ob2);
s2.repl(s1,ob3);
s1.disp( );
s2.disp( ); getch( ); }
f) Observe the following program carefully & choose the correct possible output from the options (i) to (iv)
justifying your answer. 2
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void main( )
{
clrscr( );
randomize( );
int RN;
RN=random(4)+5;
for(int i=1;i<=RN;i++)
cout<<i<<' ';
getch(); }
i) 0 1 2 ii)1 2 3 4 5 6 7 8 iii) 4 5 6 7 8 9 iv) 5 6 7 8 9 10 11 12
2. a) Differenciate between default & parameterized constructor with suitable example. 2
b) Answer the questions i) and ii) after going through the following class : 2
#include<iostream.h>
#include<string.h>
#include<stdio.h>
class wholesale
{ char categ[20],item[30];
float pr;
int qty;
wholesale( ) // Function 1
{ strcpy(categ ,”Food”);
strcpy(item,”Biscuits”);
pr=150.00;
qty=10 }
public :
void SHOW( ) //Function 2
{
cout<<categ<<”#”<<item<<”:”<<pr<<”@”<<qty<<endl;
}
};
void main( )
{ wholesale ob; //Statement 1
ob.SHOW( ); //Statement 2
}
i) Will statement 1 initialize all the data members for object ob with the values given in function 1?(Y/N).
Justify your answer suggesting the corrections to be made in the above code.
ii) What shall be the possible output when the program gets executed? (Assuming, if required- the
suggested correction(s) are made in the program.
c) Defne a class WEAR in C++ with following description : 4
Private members :
code string
Type string
2|Page
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
Size integer
material string
Price real number
A function calprice( ) that calculates and assign the value of price as follows :
For the value of material as “WOOLEN”
Type Price(Rs.)
------- -------------
Coat 2400
Sweater 1600
For material other than “WOOLEN” the above mentioned price gets reduced by 30%.
Public members :
A constructor to get initial values for code, Type & material as “EMPTY” & size and price with 0.
A function INWEAR( ) to input the values for all the data members except price which will be initialized
by function calprice( ).
Function DISPWEAR( ) that shows all the contents of data members

d) Answer the questions (i) to (iv) based on the following : 4


class COMP
{ private :
           char Manufacturer [30];
char addr[15];

      public:
      toys( );
      void RCOMP( );
      void DCOMP( );
};
class TOY: public COMP
{ private:
      char bcode[10];
           public:
double cost_of_toy;
      void RTOY ( );
      void DTOY( );
};
      class BUYER: public TOY
{ private:
      char nm[30];
      char delivery date[10];
char *baddr;
      public:
      void RBUYER( );
      void DBUYER( );
};
void main ( )
{       BUYER MyToy;      }

i) Mention the member names that are accessible by MyToy declared in main( ) function.
ii) Name the data members which can be accessed by the functions of BUYER class.
iii) Name the members that can be accessed by function RTOY( ).
iv) How many bytes will be occupied by the objects of class BUYER?

3. a) Define a function that would accept a one dimensional integer array and its size. The function should reverse
the contents of the array without using another array. (main( ) function is not required) 4
b) A two dimensional array A[15][25] having integers (long int), is stored in the memory along the column, find
out the memory location for the element A[8][12], if an element A[10][6] is stored at the memory location
2800. 4
c) Evaluate the following postfix notation of expression : 2
5, 8, 7, +, /, 7, * , 13, -
d) ) Write a user defined function in C++ which accepts a squared integer matrix with odd dimensions (3*3, 5*5
…) & display the sum of the middle row & middle column elements. For ex. :
2 5 7 2
3 7 2
5 6 9
The output should be :
Sum of middle row = 12
Sum of middle column = 18
e) Consider the following program for linked QUEUE : 4
struct NODE

3|Page
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
{ int x; float y; NODE *next; };
class QUEUE
{ NODE *R,*F;; public : QUEUE( )
{ R=NULL; F=NULL; }
void INSERT( );
void DELETE( ); void Show( ); ~QUEUE( ); };
Define INSERT( ) & DELETE( ) functions outside the class.
4. a) Observe the following program carefully and fill in the blanks using seekg( ) and tellg( ) functions :
1
#include<fstream.h>
class school { private :
char scode[10],sname[30];
float nofstu;
public:
void INPUT( ); void OUTPUT( ); int COUNTREC( ); };
int school::COUNTREC( )
{ fstream fin(“scool.dat”,ios::in|ios::binary);
_________________ //statement 1
int B=_______________ //statement 2
int C=B/sizeof(school);
fin.close( );
return C; }
b) Write a function in c++ to count the number of words starting with capital alphabet present in a text file
DATA.TXT. 2
c) Write a function in c++ to add new objects at the bottom of binary file “FAN.DAT”, assuming the binary file
is containing the objects of following class : 3
class FAN
{ private:
int srno;
char name[25];
float pr;
public:
void Enter( ){ cin>>srno; gets(name); cin>>pr; }
void Display( ){ cout<<srno<<name<<pr<<endl;} };
5. a) What do you mean by degree & cardinality of a relation? Explain with example. 2
b) Consider the tables FLIGHTS & FARES. Write SQL commands for the statements (i) to (iv) and give the
outputs for SQL queries (v) & (vi) .
Table : FLIGHTS
FNO SOURCE DEST NO_OF_FL NO_OF_STOP
IC301 MUMBAI BANGALORE 3 2
IC799 BANGALORE KOLKATA 8 3
MC101 DELHI VARANASI 6 0
IC302 MUMBAI KOCHI 1 4
AM812 LUCKNOW DELHI 4 0
MU499 DELHI CHENNAI 3 3

Table : FARES
FNO AIRLINES FARE TAX
IC301 Indian Airlines 9425 5%
IC799 Spice Jet 8846 10%
MC101 Deccan Airlines 4210 7%
IC302 Jet Airways 13894 5%
AM812 Indian Airlines 4500 6%
MU499 Sahara 12000 4%
i) Display flight number & number of flights from Mumbai from the table flights. 1
ii) Arrange the contents of the table flights in the descending order of destination. 1
iii) Increase the tax by 2% for the flights starting from Delhi. 1
iv) Display the flight number and fare to be paid for the flights from Mumbai to Kochi using the tables, Flights
& Fares, where the fare to be paid =fare+fare*tax/100. 1
v) SELECT COUNT(DISTINCT SOURCE) FROM FLIGHTS; 1
vi) SELECT FNO, NO_OF_FL, AIRLINES FROM FLIGHTS,FARES WHERE SOURCE=’DELHI’ AND
FLIGHTS.FNO=FARES.FNO; 1
6. a) State and verify De Morgan’s law. 2
b) If F(A,B,C,D) =  (0,1,2,4,5,7,8,10) , obtain the simplified form using K-Map. 3
c) Convert the following Boolean expression into its equivalent Canonical Sum of Products form (SOP) : 2
(X+Y+Z) (X+Y+Z’) (X’+Y+Z) (X’+Y’+Z’)
d) Write the equivalent Boolean Expression F for the following circuit diagram : 1

4|Page
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
A B

7. a) What is a switch? How is it different from hub? 1


b) What is the difference between optical fibre & coaxial transmission media. 1
c) Define cookies & firewall. 1
d) Expand WLL & XML 1
e) “Kanganalay Cosmetics” is planning to start their offices in four major cities in Uttar Pradesh to provide
cosmetic product support in its retail fields. The company has planned to set up their offices in Lucknow at
three different locations and have named them as “Head office”, “Sales office”, & “Prod office”. The
company’s regional offices are located at Varanasi, Kanpur & Saharanpur. A rough layout of the same is as
follows :

UP LUCKNOW
Sa le s
He a d
offic e
offic e

Pro d
offic e

Va ra na si Ka np ur
offic e Sa ha ra np ur offic e
offic e

Approximate distances between these offices as per network survey team is as follows :

Place from Place to Distance


Head office Sales office 15 KM
Head office Prod office 8 KM
Head office Varanasi Office 295 KM
Head office Kanpur Office 195 KM
Head office Saharanpur office 408 KM
Number of computers :

Head office 156


Sales office 25
Prod office 56
Varanasi Office 85
Kanpur Office 107
Saharanpur office 105
i) Suggest the placement of the repeater with justification. 1
ii) Name the branch where the server should be installed. Justify your answer. 1
iii) Suggest the device to be procured by the company for connecting all the computers within each of its
offices out of the following devices : 1
 Modem
 Telephone
 Switch/Hub
iv) The company is planning to link its head office situated in Lucknow with the office at Saharanpur.
Suggest an economic way to connect it; the company is ready to compromise on the speed of
connectivity. Justify your answer. 1

5|Page
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
2. a) Differentiate between call by value & call by reference with suitable examples in reference
to function. 2
b) Name the header files, to which the following built-in functions belong : 1
i) get( ) ii) random( )
c) Will the following program execute successfully ? If no, state the reason(s) : 2
#include<iostream.h>
#include<stdio.h>
#define int M=3;
void main( )
{ const int s1=10;
int s2=100;
char ch;
getchar(ch);
s1=s2*M;
s1+M = s2;
cout<<s1<<s2 ;}

d) Give the output of the following program segment ( Assuming all required header files are included in the
program ) : 2
int m=50;
void main( )
{
int m=25;
{ int m= 20*:: m; 
cout<<”m=”<<m <<endl;
cout<<”::m=”<< ::m <<endl;
}
::m=++m+ m;
cout<<”m=”<<m <<endl;
cout<<”::m=”<< ::m <<endl;
}

e) Give the output of the following program : 3


#include<iostream.h>
double area(int l, double b)
{ return (l*b) ;}
float area(float b, float h)
{ return(0.5*b*h) ; }
void main( )
{ cout<<area(5,5)<<endl;
cout<<area(4,3.2)<<endl;
cout<<area(6,3)<<endl;
}

f) Observe the following program carefully & choose the correct possible output from the options (i) to (iv)
justifying your answer. 2
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void main( )
{
clrscr( );
randomize( );
int RN;
RN=random(4)+5;
for(int i=1;i<=RN;i++)
cout<<i<<' ';
getch(); }

i) 0 1 2 ii)1 2 3 4 5 6 7 8 iii) 4 5 6 7 8 9 iv) 5 6 7 8 9 10 11 12

2. a) Define Multilevel & Multiple inheritance in context to OOP. Give suitable examples to illustrate the same. 2
b) Answer the questions (i) and (ii) after going through the following class : 2
class number
{ float M;
char str[25];
public:

6|Page
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
number( ) //constructor 1
{ M=0;
str=’\0’;}
number(number &t); //constructor 2
};
i) Write c++ statement such that it invokes constructor 1.
ii) Complete the definition for constructor 2.

b) A class TRAVEL with the following descriptions : 4


Private members are :
Tcode, no_of_pass, no_of_buses integer (ranging from 0 to 55000)
Place string
Public members are:
 A constructor to assign initial values of Tcode as 101, Place as “Varanasi”, no_of_pass
as 5, no_of_buses as 1.
 A function INDETAILS( ) to input all information except no_of_buses according to
the following rules :
Number of passengers Number of buses
Less than 40 1
Equal to or more than 40 & less than 80 2
Equal to or more than 80 3
 A function OUTDETAILS( ) to display all the information.

c) Answer the following questions (i) to (iv) based on the following code : 4
class DRUG
{ char catg[10];
char DOF[10], comp[20];
public:
DRUG( );
void endrug( );
void showdrug( );
};
class TABLET : public DRUG
{ protected:
char tname[30],volabel[20];
public:
TABLET( );
void entab( );
void showtab( );
};
class PAINKILLER : public TABLET
{ int dose, usedays;
char seffect[20];
public :
void entpain( );
void showpain( );
};
i) How many bytes will be required by an object of TABLET?
ii) Write names of all the member functions of class PAINKILLER.
iii) Write names off all members accessible from object of class PAINKILLER.
iv) Write names of all data members accessible from functions of class PAINKILLER.

3. a) Why are arrays called static data structure?


1
b) Given a two dimensional array AR[5][10], base address of AR being 1000 and width of each element is 8
bytes. Find the location of AR[3][6] when the array is stored as a) Column wise b) Row wise .
3
c) Convert the following infix notation into postfix expression : 2
(A+B)*C-D/E*F
d) Write a user defined function in C++ to find and display the column sums of a two dimensional array MAT[7]
[7]. 2
e) Give necessary declarations for a queue containing name and float type number ; also write a user defined
function in C++ to insert and delete a node from the queue. You should use linked representation of queue. 4
f) Write a C++ function to sort an array having N integers in descending order using insertion sort method. 3
g) What are the precondition(s) for Binary Search ? 1

4. a) Observe the program segment given below carefully and answer the question that follows : 1
7|Page
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
class school
{ private :
char name[25];
int numstu;
public:
void inschool( );
void outschool( );
int retnumstu( )
{ return numstu; }
};
void modify(school A)
{ fstream INOUT;
INOUT.open(“school.dat”,ios::binary|ios::in|ios::ate);
school B;
int recread=0, found=0;
while(!found && INOUT.read((char*)&B,sizeof(B))
{ recread++;
if(A.retnumstu( )= = B.retnumstu( ))
{
____________________________//missing statement

INOUT.write((char*)&A,sizeof(A));
Found=1;
}
else
INOUT.write((char*)&B,sizeof(B));
}
if(!found)
cout<<”\nRecord for modification does not exist”;
INOUT.close( ); }

If the function modify( ) is supposed to modify a record in file school.dat with the values of school A
passed to its argument, write the appropriate statement for missing statement using seekp( ) or seekg( ),
whichever needed, in the above code that would write the modified record at its proper place.

b) Write a function in c++ to add new objects at the bottom of a binary file “STU.DAT”, assuming that the
binary file is containing the objects of the following class : 3
class STUDENT
{ int rno;
char Name[25];
public:
void Enter( ){ cin>>rno; gets(Name);}
void Display( ){ cout<<rno<<Name<<endl;}
int retrno( ) {return rno;} };

c) Write a function in c++ to count & display the number of lines not starting with ‘A’ present in a text file
“PARA.TXT”. 2

5. a) What do you understand by the terms Candidate key and Cardinality of a relation? 2
b) Write SQL commands for (i) to (vii) on the basis of the table LAB
Table : LAB
NO ITEM COST QTY DATEOFPURCHASE WARRANTY OPERATIONAL
NAME
1. COMPUTER 45000 9 21/5/96 2 7
2. PRINTER 15000 3 21/5/97 4 2
3. SCANNER 21000 1 29/8/98 3 1
4. CAMERA 12000 2 13/6/96 1 2
5. HUB 4000 1 31/10/99 2 1
6. UPS 5000 5 21/5/96 1 4
7. PLOTTER 13000 2 11/1/2000 2 2
i) to select the item name purchased after 31/10/97. 1
ii) to list item name, which are within the warranty period till present date 1
iii) to list the name in ascending order of the date of purchase where quantity is more than 3. 1
iv) to count the number of items whose cost is more than 10000. 1
v) Give the output of the following SQL commands : 2
a) SELECT MIN(DISTINCT QTY) FROM LAB;
b) SELECT MIN(WARRANTY) FROM LAB WHERE QTY=2 ;
c) SELECT SUM(COST) FROM LAB WHERE QTY>2 ;
d) SELECT AVG(COST) FROM LAB WHERE DATEOFPURCHASE<{1/1/99} ;
8|Page
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
6. a) State De’Morgans law and verify one of the laws using truth table . 2
b) If F(w,x,y,z) =  (0,2,4,5,7,8,10,12,13,15) , obtain the simplified form using K-Map. 3
c) Represent AND using NOR gate(s). 1
d) Write the POS form of a Boolean function G, which is represented in a truth table as follows :
1
P Q R G
0 0 0 0
0 0 1 0
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 1

e) Write the equivalent Boolean Expression for the following logic circuit : 1
X Y

7. a) What are routers? 1


b) Expand SMSC, DHTML. 1
c) What are backbone networks? 1
d) What do you mean by twisted pair cable? Write its advantages & disadvantages. .(any two) 1
e) Sunbeam Group of Institutions in Varanasi is setting up the network among its different branches. There are
four branches named as Bhagwanpur (BGN), Lahartara (LHT), Varuna (V) and Annapurna (A). Distance
between various branches are given below :

Branch BGN to V 7 Km
Branch V to LHT 4 Km
Branch V to A 3 Km
Branch BGN to LHT 4 Km
Branch BGN to A 3.5 km
Branch LHT to A 1 km

Number of computers :

Branch BGN 137


Branch V 65
Branch A 29
Branch LHT 98

v) Suggest a suitable topology for networking the computer of all the branches. 1
vi) Name the branch where the server should be installed. Justify your answer. 1
vii) Suggest the placement of hub or switches in the network. 1
viii) Mention any economic way to provide internet accessibility to all branches. 1

1. (a) “While implementing encapsulation, abstraction is also implemented”. Comment 2


(b) Name the header file to which the following functions belong: 1
(i) itoa() (ii) getc()
(c) Rewrite the following program after removing the syntactical errors (if any).Underline each
correction: 2
class ABC
{ int x=10;
float y;
ABC() {y=10; }

9|Page
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
~() {}
}
void main()
{
ABC a1(10);
}
(d) Write the output of the following program : 3
#include <iostream.h>
#include <string.h>
#include <ctype.h>
void swap(char &c1,char &c2)
{ char temp;
temp=c1;
c1=c2;
c2=temp;
}
void update(char *str)
{
int k,j,l1,l2;
l1 = (strlen(str)+1)/2;
l2=strlen(str);
for(k=0,j=l1-1;k<j;k++,j--)
{
if(islower(str[k]))
swap(str[k],str[j]);
}
for(k=l1,j=l2-1;k<j;k++,j--)
{
if(isupper(str[k]))
swap(str[k],str[j]);
}
}
void main()
{
char data[100]={"bEsTOfLUck"};
cout<<"Original Data : "<<data<<endl;
update(data);
cout<<"Updated Data "<<data;
}
(e) In the following program, find the correct possible output(s) from the options and justify your answer:
2
#include <iostream.h>
#include <stdlib.h>
10 | P a g e
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
#include <string.h>
struct card { char suit[10];
int digit;
};
card* cards = new card[52]; // Allocate Memory
void createdeck()
{ char temp[][10] = {"Clubs","Spades","Diamonds","Hearts"};
int i,m=0,cnt=1;
for(i=1;i<=52;i++)
{ strcpy(cards[i].suit,temp[m]);
cards[i].digit=cnt;
cnt++;
if(i % 13 == 0)
{ m++;cnt=1; }
}
}
card drawcard(int num)
{ int rndnum;
randomize();
rndnum = random(num)+1;
return (cards[rndnum]);
}
void main()
{ createdeck();
card c;
c = drawcard(39);
if(c.digit > 10 || c.digit == 1)
{
switch(c.digit)
{ case 11: cout<<"Jack of "; break;
case 12: cout<<"Queen of "; break;
case 13: cout<<"King of "; break;
case 1: cout<<"Ace of ";
}
}
else
cout<<c.digit<<" of ";
cout<<c.suit;
delete[] cards; //Deallocate memory
}

Outputs:
i) Kind of Spades ii) Ace of Clubs
11 | P a g e
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
iii) Ace of Diamond iv) Queen of Hearts
(f) Give the output of the following program code: 2
#include <iostream.h>
strcut Pixel
{
int c,r;
};
void display(Pixel p)
{
cout<<”Col “<<p.c<<” Row “<<p.r<<endl;
}
void main()
{
Pixel x = = {40,50}, y, z;
z= x;
x.c = x.c + 10;
y = z;
y.c = y.c + ;
y.r = y.r + 20;
z.c = z.c  15;
display(x);
display(y);
display(z);
}
2.(a) How does the visibility mode control the access of members in the derived class? Explain with
example. 2
(b) Answer the questions (i) and (ii) after going through the following class: 2
class player
{
int health;
int age;
public:
player() { health=6; age=18 } //Constructor1
player(int s, int a) {health =s; age = a ; } //Constructor2
player( player &p) { } //Constructor3
~player() { cout<<”Memory Deallocate”; } //Destructor
};
void main()
{
player p1(7,24); //Statement1
player p3 = p1; //Statement3
}
(i) When p3 object created specify which constructor invoked and why?
12 | P a g e
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
(ii) Write complete definition for Constructor3?
(c) Define a class Employee in C++ with the following specification: 4
Private Members:
 ename an array of char of size[50] ( represent employee name)
 deptname an array of char of size[20] ( represent department name)
 salary integer ( represent total salary of an employee)
 bonus float
 CalBonus() This function calculate the total bonus given to an employee according to
following conditions
Deptname Bonus
Accounts 4 % of salary
HR 5% of salary
IT 2% of salary
Sales 3% of salary
Marketing 4% of salary
Public Members:
 Constructor to initialise ename and deptname to NULL and salary and bonus to 0.
 A function read_info to allow user to enter values for ename, deptname,salary & Call function
CalBonus() to calculate the bonus of an employee.
 A Function disp_info() to allow user to view the content of all the data members.

(d) Consider the following code and answer the questions: 4


class typeA
{
int x;
protected:
int k1;
public:
typeA(int m);
void showtypeA();
};
class typeB : public typeA
{
float p,q;
protected:
int m1;
void intitypeB();
public:
typeB(float a, float b);
void showtypeB();
};
class typeC : public typeA, private typeB

13 | P a g e
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
{
int u,v;
public:
typeC(int a, int b);
void showtypeC();
};
(i) How much byte does an object belonging to class typeC require?
(ii) Name the data member(s), which are accessible from the object(s) of class typeC.
(iii) Name the members, which can be accessed from the member functions of class typeC?
(iv) Is data member k1 of typeB accessible to objects of class typeB?
3 (a) Given two arrays A and B. Array ‘A’ contains all the elements of ‘B’ but one more element extra.
Write a c++ function which accepts array A and B and its size as arguments/ parameters and find out the
extra element in Array A. (Restriction: array elements are not in order) 3
Example
If Array A is {14, 21, 5, 19, 8, 4, 23, 11}
and Array B is {23, 8, 19, 4, 14, 11, 5 }
Then output will be 5 (extra element in Array A)
(b) Write a function in C++ which accepts an integer array and its size as arguments/parameters and
assigns the elements into a two dimensional array of integers in the following format. 3
if the array is 9,8,7,6,5,4 if the array is 1, 2, 3
The resultant 2D array is given below The resultant 2D array is given below
9 9 9 9 9 9
8 8 8 8 8 0
1 1 1
7 7 7 7 0 0
2 2 0
6 6 6 0 0 0
3 0 0
5 5 0 0 0 0
4 0 0 0 0 0

(c) Each element of an array DATA[10][10] requires 8 bytes of storage. If base address of array DATA is
2000, determine the location of DATA[4][5], when array is stored
(i) Row-wise. (ii) Column-wise 4
(d) Write the function to perform push and pop operation on a dynamically allocated stack of customers
implemented with the help of the following structure: 4
struct employee
{
int eno;
char ename[20];
employee *link;
};
(e) Evaluate the following postfix notation of expression: 2
5, 11, , 6, 8, +, 12, *, /
4.(a) Observe the program segment given below carefully and fill in the blanks marked as Statement 1
and Statement 2 for performing the required task. 1
#include <iostream.h>
#include <fstream.h>

14 | P a g e
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
void main(void)
{
  char filename[] = "C:\\testfileio3.txt";
     fstream inputfile, outputfile;
   int length;
   char * buffer;
     // --------create, open and write data to file--------
     outputfile.open(filename, ios::out);
     // ----write some text-------
     outputfile<<"This is just line of text."<<endl;
     // --------close the output file------------
     outputfile.close();
     // ----opening and reading data from file-----
     inputfile.open(filename, ios::in);
          cout<<"The "<<filename<<" file was opened successfully!\n";
          cout<<"\nMove the pointer to the end\n"
            <<"Then back to the beginning with\n"
            <<"10 offset.  The pointer now at...\n"<<endl;
     // flush the stream buffer explicitly...
     cout<<flush;
       // get length of file move the get pointer to the end of the stream
          inputfile.seekg(0, ios::end);
       // This statement returns the current stream position.
          length = _____________________________ //Statement1
       cout<<"length variable = "<<length<<"\n";
       // dynamically allocate some memory storage for type char...
          buffer = new char [length];
          // move back the pointer to the beginning with offset of 10
____________________________________ //Statement2
          // read data as block from input file...
       inputfile.read(buffer, length);
          cout<<buffer;
            // free up the allocated memory storage...
          delete [] buffer;
        inputfile.close();
 }
(b) Assume a text file “coordinate.txt” is already created. Using this file create a C++ function to count
the number of .words having first character capital.. 2
Example:
Do less Thinking and pay more attention to your heart. Do Less Acquiring and pay more Attention to
what you already have. Do Less Complaining and pay more Attention to giving. Do Less criticizing and
pay more Attention to Complementing. Do less talking and pay more attention to SILENCE.
Output will be : Total words are 16
15 | P a g e
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
(c) Given a binary file “TABLE.TXT”, containing the records of the following class type
class perdata 3
{ int age;
int weight;
int height;
char name[40];
public:
void getdata() { cin>>age>>weight>>height>>name; }
void showdata() { cout<<age<<” “<<weight<<” “<<height<<” “<<name<<endl; }
int retage()
{ return age; }
};
Write a function in c++ that would read contents from the file personal.dat and creates a file named
eligible.dat copying only those records from personal.dat having age >= 18.

5. (a) What are the various levels of data abstraction in a database system? 2
(b) Consider the following tables FACULTY and COURSES. Write SQL commands for the statements
(i) to (iv) and give outputs for SQL queries (v) to (viii)
FACULTY 6
F_ID Fname Lname Hire_date Salary
102 Amit Mishra 12-10-1998 12000
103 Nitin Vyas 24-12-1994 8000
104 Rakshit Soni 18-5-2001 14000
105 Rashmi Malhotra 11-9-2004 11000
106 Sulekha Srivastava 5-6-2006 10000
107 Niranjan Kumar 26-8-1996 16000
COURSES
C_ID F_ID Cname Fees
C21 102 Grid Computing 40000
C22 106 System Design 16000
C23 104 Computer Security 8000
C24 106 Human Biology 15000
C25 102 Computer Network 20000
C26 105 Visual Basic 6000
C27 107 Dreamweaver 4000

(I) To display details of those Faculties whose salary is greater than 12000.
(II) To display the details of courses whose fees is in the range of 15000 to 50000
(both values included).
(III) To increase the fees of all courses by 500.
(IV) To display details of those courses which are taught by ‘Sulekha’.
(V) Select COUNT(DISTINCT F_ID) from COURSES;
(VI) Select MIN(Salary) from FACULTY,COURSES
where COURSES.C_ID = FACULTY.F_ID;
(VII) Select SUM(Fees) from courses
Group By F_ID having count(*) > 1;
(VIII) Select Fname, Lname from FACULTY

16 | P a g e
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
Where Lname like “M%”;

6. (a) State and verify Distributive law in Boolean Algebra. 2


(b) Convert the following Boolean expression into its equivalent Canonical Product of Sum (POS) form.
PQR + PQ’R + PQ’R’ + P’Q’R 2
(c) Obtain a simplified form for a Boolean expression 2
F (a, b , c, d) = ∏ ( 0, 1, 3, 4, 5, 6, 7, 9, 10, 11, 13, 15) using Karnaugh Map.
(d) Represent the Boolean expression A’. (B+C) with the help of NOR gates only. 2

7. (a) What is gateway? 1

(b) Write the two advantages and two disadvantages of Bus Topology in Network? 1
(c) Expand the following terms with respect to Networking. 2
i). PPP
ii). SMTP
iii). URL
iv). FDMA
(d) SunRise Pvt. Ltd. is setting up the network in the Ahmedabad. There are four departments named as
MrktDept, FunDept, LegalDept, SalesDept. 4

FunDept
MrktDept

SalesDept
LegalDept

Distance between various buildings is as given:

MrktDept to FunDept 80 m
MrktDept to LegalDept 180m
MrktDept to SalesDept 100 m
LegalDept to SalesDept 150 m
LegalDept to FunDept 100 m
FunDept to SalesDept 50 m

Number of Computers in the buildings:

MrktDept 20
LegalDept 10
FunDept 08
SalesDept 42

17 | P a g e
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
a) Suggest a cable layout of connections between the Departments and specify topology.
b) Suggest the most suitable building to place the server a suitable reason with a suitable reason.
c) Suggest the placement of Hub / Switch in the network.
d) Name the Department to place the modem so that all the building can share internet
connection.
Q-1
(a) Name the header file to which the following belong: (i) isupper() (ii) random().
(1)
(b) Illustrate the use of inline function in C++ with help of an example.
(2)
(c) Rewrite the following program after removing the syntactical error(s), if any. Underline each
correction.
# include<iostream.h>
CLASS STUDENT
{
int admno;
float marks;
public:
STUDENT() { admno=0; marks=0.0; }
void input() { cin>>admno>>marks; }

void output() { cout<<admno<<marks; }


} }
void main()
{
STUDENT S;
Input(S);
}
(2)
(d) Observe the following program RANDNUM.CPP carefully. If the value of VAL entered by the user
is 10, choose the correct possible output(s) from the options from i) to iv) and justify your option.
(2)
//program RANDNUM.CPP
#include<iostream.h>
#include<stdlib.h>
#include<time.h>
void main()
{
randomize();
int VAL, Rnd; int n=1;
cin>>VAL;
Rnd=8 + random(VAL) * 1;
1
while(n<=Rnd)
{
cout<<n<< “\t”;
n++;
}
}
output options:
i) 1 2 3 4 5 6 7 8 9 10 11 12 13
ii) 0 1 2 3
iii) 1 2 3 4 5
iv) 1 2 3 4 5 6 7 8

e) What will be the output of the following program:


(3)
#include<iostream.h>
#include<ctype.h>
#include<conio.h>
#include<string.h>
void PointersFun(char Text[], int &count)
{
char *ptr=Text;
int length=strlen(Text);
for(; count<length-2; count+=2, ptr++)
18 | P a g e
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
{
*(ptr + count) = toupper( * (ptr + count) );
}
}
void main()
{
clrscr();
int position=0;
char Data[]= “ChangeString”;
PointersFun(Data, position);
cout<<Data<< “@”<< position;
cout.write(Data + 3, 4);
}
(f) Write a function in C++ which accepts an integer and a double value as arguments/parameters.
The function should return a value of type double and it should perform sum of the following series:
x - x2 / 3! + x3 / 5! – x4 / 7! + x5 / 9! …… upto n terms
(3)

Q-2
a. Define Multilevel and Multiple Inheritance in context of Object Oriented Programming. Give suitable
example to illustrate the same.
(2)
b. class cat
{
public:
cat(int initialAge)
{
itsAge=initialAge;
}
~cat()
{
}
int getAge()
{
return itsAge;
}
void setAge(int Age)
{
itsAge=Age;
}
void Meow()
{
cout<< “Meow\n”;
}
private:
int itsAge;
}
void main()
{
cat Friskey(5);
_____________ //Statement 1
cout<< “Friskey is a cat who is”;
cout<<_______________ << “years old\n”; //Statement 2
______________ //Statement 3
Friskey.setAge(7);
cout<< “\n Now Friskey is”;
cout<<______________ << “years old\n”; //Statement 4
}

Observe the program given above carefully and fill the blanks marked as Statement 1, Statement 2,
Statement 3 and Statement 4 to produce the following output:
Meow
Friskey is a cat who is 5 years old
Meow
Now Friskey is 7 years old
(2)

c. Define a class named Publisher in C++ with the following descriptions :


19 | P a g e
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
Private members
Id long
title 40 char
author 40 char
price , stockqty double
stockvalue double
valcal() A function to find price*stockqty with double as return type
Public members
 a constructor function to initialize price , stockqty and stockvalue as 0
 Enter() function to input the idnumber , title and author
 Takestock() function to increment stockqty by N(where N is passed as argument
to this function) and call the function valcal() to update the stockvalue().
 sale() function to decrease the stockqty by N (where N is sale quantity passed to
this function as argument) and also call the function valcal() to update the
stockvalue
 outdata() function to display all the data members on the screen.
(4)
d. Answer the question (i) to (iv) based on the following code:
Class Medicines
{
char Category[10];
char Dateofmanufacture[10];
char Company[20];
public:
Medicines();

void entermedicinedetails();
void showmedicinedetails();
};
class Capsules : public Medicines
{
protected:
char capsulename[30];
char volumelabel[20];
public:
float Price;
Capsules();
void entercapsuledetails();
void showcapsuledetails();
};
class Antibiotics : public Capsules
{
int Dosageunits;
char sideeffects[20];
int Usewithindays;
public:
Antibiotics();
void enterdetails();
void showdetails();
};
i. How many bytes will be required by an object of class Medicines and an object of class
Antibiotics respectively?
ii. Write names of all the member functions accessible from the object of class Antibiotics.
iii. Write names of all the members accessible from member functions of class Capsules.
iv. Write names of all the data members which are accessible from objects of class Antibiotics.
(4)

Q-3
a. Define function stackpush( ) to insert nodes and stackpop( ) to delete nodes, for a linklist
implemented stack having the following structure for each node:
struct Node
{ char name[20];
int age;
Node *Link;
};
class STACK
{ Node * Top;
Public:
STACK( ) { Top=NULL;}

20 | P a g e
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
void stackpush( );
void stackpop( );
~STACK( );
};
(4)
b. An array S[40][30] is stored in the memory along the row with each of the element occupying 4
bytes, find out the memory location for the element S[15][5], if an element s[20][10] is stored at memory
location 5700.
(4)
c. Evaluate the following postfix expression using a stack and show the contents of stack after
execution of each operation:
TRUE,FALSE, TRUE FALSE, NOT, OR, TRUE , OR,OR,AND
(2)
d. Write UDF in C++ which accepts an integer array and its size as arguments/ parameters and assign the
elements into a 2 D array of integers in the following format:
If the array is 1,2,3,4,5.
The resultant 2D array is given below
10000
12000
12300
12340
12345
(4)
e. Write UDF in C++ to print the row sum and column sum of a matrix.
(2)

Q- 4
(a) Observe the program segment given below carefully and fill the blanks marked as Statement1
and Statement2 using seekp( ) and seekg( ) functions for performing the required task.
#include <fstream.h>
class Item
{
int Imno; char Item[20];
public:
//Function to search and display the content from a particular record number
void Search (int) ;
//Function to modify the content of a particular record number
void Modify(int);
};
void Item :: Search (int RecNo)
{
fstream File;
File.Open(“STOCK.DAT” , ios :: binary | ios :: in);
__________________________ //Statement 1
File.read((char*)this , sizeof(Item));
Cout <<Ino <<” = = >” << Item << endl;
File.close ( );
}
void Item :: Modify (int RecNo)
{
fstream File;
File.open (“STOCK.DAT”, ios ::binary | ios :: in | ios :: out);
cin>> Ino;
cin.getline(Itm,20 );
_________________________ //Statement 2
File.write ((char*) this, sizeof(Item ));
File.close ( );
(1)
}

(b) Write a program to create a text file “ TEXT.DOC “ . Tranfer the lines that start with a vowel ( not case
sensitive ) to the file in reverse order . ( do not use strrev ) to a new file “EXAM.DOC” . Merge the content
of both the files into a third file “ FINAL.DOC “ , contents of “TEXT.DOC” followed by “ EXAM.DOC “ .
Also find the total number of bytes occupied by the file.
(2)

(c) Write a function in C++ to search for BookNo from a binary file “BOOK.DAT”, assuming the binary
file is contained the objects of the following class:
class BOOK
21 | P a g e
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
{
int Bno; char Title [20];
public :
int Rbno ( ) { return Bno; }
void Enter ( ) { cin >> Bno; gets (Title); }
void Display ( ) { cout << Bno <<Title <<endl; }
};
(2)
Q-5
a. Define entity and referential integrity.
(2)

Write a SQL commands for (b) to (g) with the help of the table given below:
EMP
Ename char (20)
Deptt char (20)
Salary number (8,2)
Desig char (10)
b. Show sum and average salary for marketing deptt.
c. Check all employees have unique names.
d. Find all employees whose deptt. is same as of “amit”.
e. Increase the salary of all employees by 10%.
f. Find the deptt. that is paying max salaries to its employees.
g. Display the details of all the employees having salary less than 10000.
(6)

Q-6
a. Simplify the Boolean expression of F using Karnaugh Maps:
F (a, b, c) =  (1, 3, 5, 7)
(2)
b. State and verify the De Morgan’s law using Algebraic method?
(1)
c. there are four railway tracks at a place. It is desired to design a logic circuit, which can give a
signal when three or more trains pass together at any given time.
(i) Draw the truth table for the above problem.
(ii) Simplify the expression using K-Map.
(iii) Draw a Logic circuit.
(3)
d. Given the following truth table, write the sum-of-product form of the function F(x, y, z).
(1)

X Y Z F
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
e. Represent NOT using only NOR gate(s).
(1)

Q-7
a) Compare packet switching and message switching.
(1)
b) Expand the following terminologies:
(1)
i) URL
ii) NFS
c) What is web browser? Name any one.
(1)
d) What do you understand by network security?
(1)
e) A company in Oman has 4 wings of buildings as shown in the diagram:
(4)

22 | P a g e
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
W1
W2

W4
W3

Center to center distances between various Buildings:


W3 to W1 50m
W1 to W2 60m
W2 to W4 25m
W4 to W3 170m
W3 to W2 125m
W1 to w4 90m
Number of computers in each of the wing:
W1 150
W2 15
W3 15
W4 25
Computers in each wing are networked but wings are not networked. The company has now decided to
connect the wings also.
i) Suggest a most suitable cable layout of the connection between the wings and topology.
ii) Suggest the most suitable wing to house the server of this company with a suitable reason.
iii) Suggest the placement of the following devices with justification:
1) Internet connecting device/modem
2) Repeater
iv) The company is planning to link its head office situated in India with the offices at Oman.
Suggest an economic way to connect it; the company is ready to compromise on the speed of
connectivity. Justify your answer.
SECTION A
Q 1(a) Define the # define with a suitable example. [2]
(b) Write the names of the header files to which the following belong:
[2] (i) random ( ) (ii) isalnum ( )

(c) Rewrite the following program after removing the syntactical errors
(if any).Underline each correction. [4]
#include <iostream.h>
struct Pixels
{
int Color,Style;
}
Void ShowPoint(Pixels P)
{
cout<<P.Color,P.Style<<endl;
} (1)

void main()
{
Pixels Point1=(5,3);
ShowPoint(Point1);
Pixels Point2=Point1;
Color.Point1+=2;
ShowPoint(Point2);
}

(d) Find the output of the following program: [4]

#include <iostream.h>

23 | P a g e
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
void Changethecontent(int Arr[ ], int Count)
{
for (int C=1;C<Count;C++)
Arr[C-1]+=Arr[C];
}

void main()
{
int A[]={3,4,5},B[]={10,20,30,40},C[]={900,1200};
Changethecontent(A,3);
Changethecontent(B,4);
Changethecontent(C,2);
for (int L=0;L<3;L++) cout<<A[L]<<'#';
cout<<endl;
for (L=0;L<4;L++) cout<<B[L] <<'#';
cout<<endl;
for (L=0;L<2;L++) cout<<C[L] <<'#';
}

(2)

(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 [4]

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

(f) Give the output of the following program segment ( Assuming all required header
files are included in the program ) :
(4)
int m=50;
void main( )
{
int m=25;
{ int m= 20*:: m; 
cout<<”m=”<<m <<endl;
cout<<”::m=”<< ::m <<endl;
}

(3)

SECTION B

Q 2 Answer the questions (i) to (iv) based on the following: [5]


class MNC
{

24 | P a g e
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
char Cname[25];
protected :
char Hoffice[25];
public :

MNC();
char Country[25];
void Enterdata();
void displaydata();
};
class Branch :public MNC
{ long NOE;
char ctry[25];
protected :
void Association ();
public :
Branch();
void add();
void show();
};
class outlet :public branch
{ char state[25];
public:
outlet();
void enter();
void output();
}; (4)

1. Which class’s constructor will be called first at the time of


declaration of an object of class outlet?
2. How many bytes does an object belonging to class outlet require?
3. From the following , which cannot be called directly from the object
of class outlet :
void Association();
void enter();
void show();
4. If the class MNC is inherited by using protected visibility mode, then
name the members which are accessible through the functions of
outlet class.
5. Name the types of inheritance used in above code.
Q 3 Write a function to compute the distance between two points and
use it to develop another function that will compute the area of
the triangle whose vertices are A(x1, y1), B(x2, y2),and C(x3, y3).
Use these functions to develop a function which returns a value 1 if
the point (x, y) lines inside the triangle ABC, otherwise a value 0.
[5]
Q4 Create a class angle that includes three member variables:
an int for degrees, a float for minutes, and a char for the
direction letter(N, S, E, or W). This class can hold either a
latitude variable or a longitude variable. Write one member
function to obtain an angle value (in degrees and minutes)
and a direction from the user, and a second to display the
angle value in 179859.9’E format. Also write a three–argument
constructor. Write a main() program that displays an angle
initialized with the constructor, and then, within a loop, allows
the user to input any angle value, and then displays the value.
You can use the hex character constant ‘\xF8’ which usually
prints a degree (°) symbol. [5]
(5)

Q 5 The total distance travelled by vehicle in 't' seconds is given by


25 | P a g e
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
distance =ut+1/2at2 where 'u' and 'a' are the initial velocity
m/sec.) and acceleration (m/sec2). Write C program to find the distance travelled at regular
intervals of time given the values of 'u' and 'a'. The program should provide the flexibility to
the user to select his own time intervals and repeat the calculations for different values of
'u' and 'a'.
Description:
The total distance travelled by vehicle in 't' seconds is given by
distance =ut+1/2at2 where 'u' and 'a' are the initial velocity (m/sec.) and acceleration(m/sec2).
[5]
Q6 Create a SavingsAccount class. Use a static data member [5]
annualInterestRate to store the annual interest rate for each of the savers.
Each member of the class contains a private data member savingsBalance indicating the amount the saver
currently has on deposit. Provide member function calculateMonthlyInterest that calculates the monthly
interest by multiplying the balance by annualInterestRate divided by 12; this interest should be added to
savingsBalance. Provide a static member function modifyInterestRate that sets the static
annualInterestRate to a new value.

Write a driver program to test class SavingsAccount. Instantiate two different objects of class
SavingsAccount, saver1 and saver2, with balances of 2000.00 and 3000.00, respectively.
Set the annualInterestRate to 3 percent. Then calculate the monthly interest and print the new balances for
each of the savers. Then set the annualInterestRate to 4 percent, calculate the next month's interest and
print the new balances for each of the savers.

(6)

Q 7 To perform the addition of two matrices Description:program takes the two matrixes of
same size and performs the addition an also takes the two matrixes of different sizes and
i
checks for possibility of multiplication and perform multiplication if possible.
[5]
Q 8 To read the two complex numbers and perform the addition and
multiplication of these two numbers.
Description:
In this program the complex number means it contains the two
parts .
first one is real part and second one is imaginarypart(2+3i).by
taking these two complex numbers we can perform the addition
and multiplication operation. [5]

SECTION C
Q 9 Write a function in C++ to count the number of alphabets present in a
text file "NOTES.TXT". [5]
Q 10 Write a C++ program to copy one file (Name Source.txt) to another file
(Name Target.txt) but make sure that source file must be present and
target file must not be present in the disk. [5]
Q 11 Observe the program segment given below carefully and answer the
question that follows : [5]
class school
{ private :
char name[25];
int numstu;
public:
void inschool( );
void outschool( );
int retnumstu( )
{ return numstu; }
};

(7)
void modify(school A)
{ fstream INOUT;
INOUT.open(“school.dat”,ios::binary|ios::in|ios::ate);
school B;

26 | P a g e
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
int recread=0, found=0;

while(!found && INOUT.read((char*)&B,sizeof(B))


{ recread++;

if(A.retnumstu( )= = B.retnumstu( ))
{
________________//missing statement
INOUT.write((char*)&A,sizeof(A));
Found=1;
} else
INOUT.write((char*)&B,sizeof(B));
}
if(!found)
cout<<”\nRecord for modification does not exist”;
INOUT.close( );

}
If the function modify( ) is supposed to modify a record in file school.dat with the values of school A
passed to its argument, write the appropriate statement for missing statement using seekp( ) or seekg( ),
whichever needed, in the above code that would write the modified record at its proper place.
Note: Rewrite the code with the appropriate missing code.

27 | P a g e
MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal
(1). (a) What is the difference between #define and const? Explain with suitable
i

example. 2
(b). Differentiate between global & local variable with a suitable example in C++. 2
(c). Name the Header file(s) that shall be needed for successful compilation of the following
C++ code? 1
void main( )
{ char st[20];
cin.getline(st,15);
if(islower(st[0]))
cout<<”Starts with alphabet”;
else
cout<<strlen(st);
}
(d). Rewrite the following program after removing the syntactical errors(s), if any. Underline
each correction. 2
#include<iostream.h>
#define SIZE =10
void main( )
{ int a[SIZE]={10,20,30,40,50};
float x=2;
SIZE=5;
for(i=0,i<SIZE;i++)
cout<<a[i]%x ;
}
(e). Write the output of the following program: 2
#include<iostream.h>
int g=20;
void func(int &x,int y)
{ x=x-y;
y=x*10;
cout<<x<<”,”<<y<<’\n’;
}
void main( )
{ int g=7;
func(g,::g);
2
Mohd Hashim, PGT (Computer Sc.), Class- XII (2010-11)
cout<<g<<”,”<<::g<<’\n’;
func(::g,g);
cout<<g<<”,”<<::g<<’\n’;
}
(f) Observe the following program carefully & choose the correct possible output from the
options (i) to (iv), justifying your answer. 2
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void main( )
{
clrscr( );
randomize( );
int RN;
RN=random(4)+5;
for(int i=1;i<=RN;i++)
cout<<i<<” “;
getch( );
}
i) 0 1 2 ii) 1 2 3 4 5 6 7 8 iii) 4 5 6 7 8 9 iv) 5 6 7 8 9 10 11 12
(2). (a)“While implementing encapsulation, abstraction is also implemented”. Comment. 2
(b) Why do you think function overloading must be part of OOPs? 2
(c). Rewrite the following program after removing the syntactical errors(s), if any. Underline
each correction. 2
#include<iostream.h>
class FLIGHT
{ long FlightCode;
char Description[25];
public
void AddInfo( ){cin>>FlightCode; gets(Description);}
void ShowInfo{cout<< FlightCode<<”:”<<Description<<endl;}
};
void main()
{ FLIGHT F;
AddInfo.F();
ShowInfo.F();
}
(d). Write the output of the following program: 2
#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]=='A' || msg[cnt]=='a')
3
Mohd Hashim, PGT (Computer Sc.), Class- XII (2010-11)
msg[cnt]=ch;
else
if (cnt%2==0)
msg[cnt]=toupper(msg[cnt]);
else msg[cnt]= msg[cnt-1];
}
}
void main( )
{ char mytext[]="ApEACeDriVE";
mycode(mytext,'@');
cout<<"new text:"<<mytext<<endl;
}
(e). Write the output of the following program segment: 3
#include<iostream.h>
struct package
{
int length, breadth, height;
};
void occupies(package m )
{
cout<<m.length<<”x” <<m.breadth<<”x”<<m.height<<endl;
}
void main( )
{
package p1={100, 150,50}, p2,p3;
++p1.length;
occupies(p1);
p3=p1;
++p3.breadth;
p3.breadth++;
occupies(p3);
p2=p3;
p2.breadth+=50;
p2.height--;
occupies(p2);
}
(3). (a) Differentiate between default & parameterized constructor with suitable
example. 2
(b) What is the significance of private, protected and public access specifiers in a class? 2
(c) Answer the questions (i) and (ii) after going through the following class. 2
class player
{ int health;
int age;
public:
player( ) { health=6; age=18; } //Function 1
player(int s, int a) {health =s; age = a ; } // Function 2
player( player &p); // Function 3
~player( ) { cout<<”Memory Deallocate”; } // Function 4
4
Mohd Hashim, PGT (Computer Sc.), Class- XII (2010-11)
};
void main( )
{ player p1(7,24); //Statement1
player p3 = p1; //Statement3
}
(i) When p3 object created specify which constructor invoked and why? Write complete
definition for Function 3?
(ii) Which concept of C++ is demonstrated by Function 1, 2 and 3? Write the calling
statement of Function 1.
(d). Define a class BALANCED_MEAL in C++ with following description: 4
Private Members:
Access_no Integer
Name_of_Food String of 25 characters
Calories Integer
Food_type String
Cost Float
AssignAccess( ) Generates random numbers between 0 to
99 and return it.
Public Members
A function INTAKE( ) to allow the user to enter the values of Name_of_Food,
Calories, Food_type, cost and call function AssignAccess( ) to assign Access_no.
A function OUTPUT( ) to allow user to view the content of all the data members, if
the Food_type is Fruit.
(e). Define a class Employee in C++ with the following specification : 4
Private Members:
ename an array of char of size[50] ( represent employee name)
deptname an array of char of size[20] ( represent department name)
salary integer ( represent total salary of an employee)
bonus float
CalBonus() This function calculate the total bonus given to an employee
according to following conditions
Deptname Bonus
Accounts 4 % of salary
HR 5% of salary
IT 2% of salary
Sales 3% of salary
Marketing 4% of salary
Public Members:
Constructor to initialise ename and deptname to NULL and salary and bonus to 0.
A function read_info to allow user to enter values for ename, deptname,salary & Call
function CalBonus() to calculate the bonus of an employee.
A Function disp_info() to allow user to view the content of all the data members.
(4). (a) What do you mean by memory leaks? What are possible reasons for it? How can
memory leaks be avoided? 2
(b). Write the output of the following program segment: 3
#include<iostream.h>
void main()
{
5
Mohd Hashim, PGT (Computer Sc.), Class- XII (2010-11)
int Numbers[] = {2,4,8,10};
int *ptr = Numbers;
for (int C = 0; C<3; C++)
{
cout<< *ptr << “@”;
ptr++;
}
cout<<endl;
for(C = 0; C<4; C++)
{
(*ptr)*=2;
--ptr;
}
for(C = 0; C<4; C++)
cout<< Numbers [C]<< “#”;
cout<<endl;
}
(5). (a) Consider the following declarations and answer the questions given below: 4
class RED
{ char n [ 20 ];
void input ( );
protected:
int x , y ;
void read ( );
public:
RED ( );
RED ( int a );
void get_red ( );
void put_red ( );
};
class WHITE : protected RED
{ int a , b ;
protected :
int c , d ;
void get_white( );
public:
WHITE ( );
void put_white ( );
};
class BLACK : private WHITE
{ char st[20];
protected :
int q;
void get_black( );
public:
BLACK ( );
void put_black ( );
}ob;
i. Name the data members and member functions which are accessible by the object ob.
ii. Give the size of object ob and class WHITE.
iii. Name the OOPS concept implemented above and its type.
6
Mohd Hashim, PGT (Computer Sc.), Class- XII (2010-11)
iv. Name the members accessible by function get_black( ).
(b). Can a derived class get access privilege for a private member of the base
class? If yes, how? 2
(6). (a) Name two modes common to classes ifstream and ofstream? 1
(b) Write a user defined function in C++ to read the content from a text file “MYBOOK.TXT”
and count & display the number of word “India” present in the file. 2
(c). Following is the structure of each record in a data file named “COLONY.DAT” 3
struct Colony
{
char colony_code[10];
char colony_name[10];
int no_of_people;
};
Write a function to update the file with a new value of no_of_people. The value of
colony_code
and no_of_people are read during the execution of the program.
(d).Write a function to count the number of VOWELS present in a text file
named “PARA.TXT”. 2
(e). Observe the program segment given below carefully and fill the blanks marked as
Statement 1 and Statement 2 using seekp() and seekg() functions for performing the required
task. 1
#include <fstream.h>
class Item
{
int Ino;char Item[20];
public:
//Function to search and display the content from a particular //record number
void Search(int );
//Function to modify the content of a particular record number
void Modify(int);
};
void Item::Search(int RecNo)
{
fstream File;
File.open(“STOCK.DAT”,ios::binary|ios::in);
______________________
//Statement 1
File.read((char*)this,sizeof(Item));
cout<<Ino<<”==>”<<Item<<endl;
File.close();
}
void Item::Modify(int RecNo)
{
fstream File;
7
Mohd Hashim, PGT (Computer Sc.), Class- XII (2010-11)
File.open(“STOCK.DAT”,ios::binary|ios::in|ios::out);
cout>>Ino;cin.getline(Item,20);
______________________
//Statement 2
File.write((char*)this,sizeof(Item));
File.close();
}
(7). (a). Write a function in C++ which accepts an integer array and its size as arguments and
exchanges the values of first half side elements with the second half side elements of the
array. 4
Example : If an array of 8 elements initial content as 2, 4, 1, 6, 7, 9, 23, 10
The function should rearrange array as 7, 9, 23, 10, 2, 4, 1, 6
(b). An array MAT [15] [7] is stored in the memory along the column with each element
occupying 2 bytes of memory. Find out the base address and the address of element MAT[2]
[5], if the location of MAT [5] [4] is stored at the address 100. 4
(c). Write a user defined function in C++ which accepts a squared integer matrix with odd
dimensions (3*3, 5*5 …) & display the sum of the middle row & middle column
elements. For eg.: 4
257
372
569
The output should be:
Sum of middle row = 12
Sum of middle column = 18
(d). Write a function LowerHalf ( ) which takes a two dimensional array A, with size N rows
and N columns as argument and point the lower half of the array. 2
Eg: If A is 2 3 1 5 0 The output will be 2
7153171
25781257
015010150
3491534915
“LIFE and TIME are two great teachers. LIFE teaches you the use of TIME and
TIME teaches you the value of LIFE”.

Вам также может понравиться