You are on page 1of 33

SAMPLE PAPER 2008-09

INTRODUCTORY COMPUTER SCIENCE (Theory) CLASS XII


Time allowed : 3 hours Note :
i. ii. 1.

Maximum marks : 70

All the questions are compulsory . Programming Language : C++ .

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: state( )

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

{ 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

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

Type string 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 : 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. ii. iii. iv.

Mention the member names that are accessible by MyToy declared in main( ) function.

Name the data members which can be accessed by the functions of BUYER class. Name the members that can be accessed by function RTOY( ). 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

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

Sum of middle column = 18

e) Consider the following program for linked QUEUE :

struct NODE { 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 IC301 IC799 MC101 IC302 AM812 MU499 SOURCE MUMBAI BANGALORE DELHI MUMBAI LUCKNOW DELHI DEST NO_OF_FL NO_OF_STOP 2 3 0 4 0 3

BANGALORE 3 KOLKATA VARANASI KOCHI DELHI CHENNAI 8 6 1 4 3

Table : FARES FNO IC301 IC799 MC101 IC302 AM812 AIRLINES Indian Airlines Spice Jet Deccan Airlines Jet Airways Indian Airlines FARE 9425 8846 4210 13894 4500 TAX 5% 10% 7% 5% 6%

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

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 Morgans 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

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 companys regional offices are located at Varanasi, Kanpur & Saharanpur. A rough layout of the same is as follows :

Approximate distances between these offices as per network survey team is as follows : Place from Head office Head office Head office Head office Head office Number of computers : Head office Sales office Prod office Varanasi Office Kanpur Office Saharanpur office
i. ii. iii.

Place to Sales office Prod office Varanasi Office Kanpur Office Saharanpur office

Distance 15 KM 8 KM 295 KM 195 KM 408 KM

156 25 56 85 107 105

iv.

Suggest the placement of the repeater with justification. 1 Name the branch where the server should be installed. Justify your answer. 1 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 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

2 | 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. b) Name the header files, to which the following built-in functions belong : i) get( ) ii) random( ) c) Will the following program execute successfully ? If no, state the reason(s) : #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 ;}

2 1 2

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 : #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; } 3

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];

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

public: 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 : 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. 4

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

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

4. a) Observe the program segment given below carefully and answer the question that follows : 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 : 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. 5. a) What do you understand by the terms Candidate key and Cardinality of a relation? b) Write SQL commands for (i) to (vii) on the basis of the table LAB Table : LAB NO 1. 2. 3. 4. 5. 6. ITEM NAME COMPUTER PRINTER SCANNER CAMERA HUB UPS COST 45000 15000 21000 12000 4000 5000 QTY 9 3 1 2 1 5 DATEOFPURCHASE 21/5/96 21/5/97 29/8/98 13/6/96 31/10/99 21/5/96 WARRANTY 2 4 3 1 2 1 OPERATIONAL 7 2 1 2 1 4

2 2

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

7.

PLOTTER

13000

11/1/2000

2 1 1 1 1 2

i) to select the item name purchased after 31/10/97. ii) to list item name, which are within the warranty period till present date iii) to list the name in ascending order of the date of purchase where quantity is more than 3. iv) to count the number of items whose cost is more than 10000. v) Give the output of the following SQL commands : 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} ; 6. a) State DeMorgans law and verify one of the laws using truth table . b) If F(w,x,y,z) = (0,2,4,5,7,8,10,12,13,15) , obtain the simplified form using K-Map. c) Represent AND using NOR gate(s). d) Write the POS form of a Boolean function G, which is represented in a truth table as follows : 1 P 0 0 0 0 1 1 1 1 Q 0 0 1 1 0 0 1 1 R 0 1 0 1 0 1 0 1 G 0 0 1 0 1 0 1 1

2 3 1

e) Write the equivalent Boolean Expression for the following logic circuit : 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 : 7 Km 4 Km 3 Km 4 Km 3.5 km 1 km

Branch BGN to V Branch V to LHT Branch V to A Branch BGN to LHT Branch BGN to A Branch LHT to A Number of computers : Branch BGN Branch V Branch A Branch LHT

137 65 29 98

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

v. vi. vii. viii.

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

1 1 1 1

1. (a) While implementing encapsulation, abstraction is also implemented. Comment (b) Name the header file to which the following functions belong: (i) itoa() (ii) getc()

2 1

(c) Rewrite the following program after removing the syntactical errors (if any).Underline each correction: class ABC { int x=10; float y; ABC() {y=10; } ~() {} } void main() { ABC a1(10); } (d) Write the output of the following program : #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])) 3 2

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

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> #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) {

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

switch(c.digit) { case 11: case 12: case 13: case 1: } } else cout<<c.digit<<" of "; cout<<c.suit; delete[] cards; } //Deallocate memory cout<<"Jack of "; break;

cout<<"Queen of "; break; cout<<"King of "; cout<<"Ace of "; break;

Outputs: i) iii) Kind of Spades Ace of Diamond ii) iv) Ace of Clubs Queen of Hearts 2

(f) Give the output of the following program code: #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 display(x); display(y); display(z); } 15;

2.(a) How does the visibility mode control the access of members in the derived class? Explain with example. (b) Answer the questions (i) and (ii) after going through the following class: 2 2

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

class player { int health; int age; public: player() { health=6; age=18 } player(int s, int a) {health =s; age = a ; } player( player &p) { } ~player() { cout<<Memory Deallocate; } }; void main() { player p1(7,24); player p3 = p1; } (i) When p3 object created specify which constructor invoked and why? (ii) Write complete definition for Constructor3? (c) Define a class Employee in C++ with the following specification: Private Members:

//Constructor1 //Constructor2 //Constructor3 //Destructor

//Statement1 //Statement3

ename deptname salary bonus CalBonus()

an array of char of size[50] ( represent employee name) an array of char of size[20] ( represent department name) integer ( represent total salary of an employee) float This function calculate the total bonus given to an employee according to

following conditions Deptname Accounts HR IT Sales Marketing Public Members:


Bonus 4 % of salary 5% of salary 2% of salary 3% of salary 4% of salary

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: class typeA { int x; protected:

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

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 { 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) 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. if the array is 9,8,7,6,5,4 The resultant 2D array is given below if the array is 1, 2, 3 The resultant 2D array is given below 3 3

(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

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

(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: struct employee { int eno; char ename[20]; employee *link; }; (e) Evaluate the following postfix notation of expression: 5, 11, , 6, 8, +, 12, *, / 2 4

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. #include <iostream.h> #include <fstream.h> 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 = _____________________________ 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 //Statement1 1

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

____________________________________ // read data as block from input file... inputfile.read(buffer, length); cout<<buffer; // free up the allocated memory storage... delete [] buffer; inputfile.close(); }

//Statement2

(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.. 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 (c) Given a binary file TABLE.TXT, containing the records of the following class type class perdata { 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() { }; 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. return age; } 3 2

5. (a) What are the various levels of data abstraction in a database system?

(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 F_ID 102 103 104 105 Fname Amit Nitin Rakshit Rashmi Lname Mishra Vyas Soni Malhotra Hire_date 12-10-1998 24-12-1994 18-5-2001 11-9-2004 Salary 12000 8000 14000 11000 6

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

106 107

Sulekha Niranjan COURSES

Srivastava Kumar

5-6-2006 26-8-1996

10000 16000

C_ID C21 C22 C23 C24 C25 C26 C27

F_ID 102 106 104 106 102 105 107

Cname Grid Computing System Design Computer Security Human Biology Computer Network Visual Basic Dreamweaver

Fees 40000 16000 8000 15000 20000 6000 4000

i. ii.

To display details of those Faculties whose salary is greater than 12000. To display the details of courses whose fees is in the range of 15000 to 50000 (both values included).

iii. iv. v. vi.

To increase the fees of all courses by 500. To display details of those courses which are taught by Sulekha. Select COUNT(DISTINCT F_ID) from COURSES; 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 Where Lname like M%;

6. (a) State and verify Distributive law in Boolean Algebra. PQR + PQR + PQR + PQR (c) Obtain a simplified form for a Boolean expression 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.

(b) Convert the following Boolean expression into its equivalent Canonical Product of Sum (POS) form. 2 2

7. (a) What is gateway?

(b) Write the two advantages and two disadvantages of Bus Topology in Network? (c) Expand the following terms with respect to Networking.
i.

1 2

PPP

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

ii. iii. iv.

SMTP URL FDMA

(d) SunRise Pvt. Ltd. is setting up the network in the Ahmedabad. There are four departments named as MrktDept, FunDept, LegalDept, SalesDept.
MrktDept LegalDept FunDept SalesDept

Distance between various buildings is as given:

MrktDept to FunDept MrktDept to LegalDept MrktDept to SalesDept LegalDept to SalesDept LegalDept to FunDept FunDept to SalesDept

80 m 180m 100 m 150 m 100 m 50 m

Number of Computers in the buildings:

MrktDept LegalDept FunDept SalesDept

20 10 08 42

a. b. c.

Suggest a cable layout of connections between the Departments and specify topology. Suggest the most suitable building to place the server a suitable reason with a suitable reason. Suggest the placement of Hub / Switch in the network.

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

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++) { *(ptr + count) = toupper( * (ptr + count) ); }

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

} 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 : Private members

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

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;}

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

void stackpush( ); void stackpop( ); ~STACK( ); }; (4)

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
b. 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)

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

(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 { 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) a. Show sum and average salary for marketing deptt. b. Check all employees have unique names. c. Find all employees whose deptt. is same as of amit. d. Increase the salary of all employees by 10%. e. Find the deptt. that is paying max salaries to its employees. f. 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 Morgans 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 0 0 0 0 1 1 1 1 e. Y 0 0 1 1 0 0 1 1 Z 0 1 0 1 0 1 0 1 F 0 1 1 0 1 0 0 1

Represent NOT using only NOR gate(s). (1)

Q-7
a) Compare packet switching and message switching. (1)

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

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)

W1

W2

W3

W4

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) (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);

isalnum ( )

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

ShowPoint(Point1); Pixels Point2=Point1; Color.Point1+=2; ShowPoint(Point2); } (d) Find the output of the following program: #include <iostream.h> 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] <<'#'; } [4]

(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


files are included in the program ) : (4) int m=50; void main( ) { int m=25;

( Assuming all required header

{ int m= 20*:: m; cout<<m=<<m <<endl; cout<<::m=<< ::m <<endl; }

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

(3)

SECTION B Q 2 Answer the questions (i) to (iv) based on the following: class MNC { char Cname[25]; protected : char Hoffice[25]; public : [5]

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. 2. 3.

Which classs constructor will be called first at the time of declaration of an object of class outlet? How many bytes does an object belonging to class outlet require? void Association(); void enter(); void show();

From the following , which cannot be called directly from the object of class outlet :

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
4.

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

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

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.9E format. Also write a threeargument 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 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 checks for 1 possibility of multiplication and perform multiplication if possible. [5]
1 1 1 1

(1). (a) What is the difference between #define and const? Explain with suitable 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 1 C++ code? 1 1 void main( ) 1 { char st[20]; 1 cin.getline(st,15); 1 if(islower(st[0])) 1 cout<<Starts with alphabet; 1 else 1 cout<<strlen(st); 1 } 1 (d). Rewrite the following program after removing the syntactical errors(s), if any. Underline 1 each correction. 2 1 #include<iostream.h> 1 #define SIZE =10 1 void main( ) 1 { int a[SIZE]={10,20,30,40,50}; 1 float x=2; 1 SIZE=5; 1 for(i=0,i<SIZE;i++) 1 cout<<a[i]%x ;

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

1 1

} (e). Write the output of the following program: 2 1 #include<iostream.h> 1 int g=20; 1 void func(int &x,int y) 1 { x=x-y; 1 y=x*10; 1 cout<<x<<,<<y<<\n; 1 } 1 void main( ) 1 { int g=7; 1 func(g,::g); 1 2 1 Mohd Hashim, PGT (Computer Sc.), Class- XII (2010-11) 1 cout<<g<<,<<::g<<\n; 1 func(::g,g); 1 cout<<g<<,<<::g<<\n; 1 } 1 (f) Observe the following program carefully & choose the correct possible output from the 1 options (i) to (iv), justifying your answer. 2 1 #include<iostream.h> 1 #include<conio.h> 1 #include<stdlib.h> 1 void main( ) 1 { 1 clrscr( ); 1 randomize( ); 1 int RN; 1 RN=random(4)+5; 1 for(int i=1;i<=RN;i++) 1 cout<<i<< ; 1 getch( ); 1 } 1 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 1 (2). (a)While implementing encapsulation, abstraction is also implemented. Comment. 2 1 (b) Why do you think function overloading must be part of OOPs? 2 1 (c). Rewrite the following program after removing the syntactical errors(s), if any. Underline 1 each correction. 2
1 1 1

#include<iostream.h>

class FLIGHT { long FlightCode; 1 char Description[25]; 1 public 1 void AddInfo( ){cin>>FlightCode; gets(Description);} 1 void ShowInfo{cout<< FlightCode<<:<<Description<<endl;} 1 }; 1 void main() 1 { FLIGHT F; 1 AddInfo.F(); 1 ShowInfo.F(); 1 } 1 (d). Write the output of the following program: 2 1 #include<iostream.h> 1 #include<ctype.h> 1 void mycode(char msg[ ], char ch) 1 { for (int cnt=0;msg[cnt]!='\0';cnt++) 1 {if (msg[cnt]>='B' && msg[cnt]<='G') 1 msg[cnt]=tolower(msg[cnt]); 1 else 1 if (msg[cnt]=='A' || msg[cnt]=='a') 1 3

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

1 1

Mohd Hashim, PGT (Computer Sc.), Class- XII (2010-11) msg[cnt]=ch; 1 else 1 if (cnt%2==0) 1 msg[cnt]=toupper(msg[cnt]); 1 else msg[cnt]= msg[cnt-1]; 1 } 1 } 1 void main( ) 1 { char mytext[]="ApEACeDriVE"; 1 mycode(mytext,'@'); 1 cout<<"new text:"<<mytext<<endl; 1 } 1 (e). Write the output of the following program segment: 3 1 #include<iostream.h> 1 struct package 1 { 1 int length, breadth, height; 1 }; 1 void occupies(package m ) 1 { 1 cout<<m.length<<x <<m.breadth<<x<<m.height<<endl; 1 } 1 void main( ) 1 { 1 package p1={100, 150,50}, p2,p3; 1 ++p1.length; 1 occupies(p1); 1 p3=p1; 1 ++p3.breadth; 1 p3.breadth++; 1 occupies(p3); 1 p2=p3; 1 p2.breadth+=50; 1 p2.height--; 1 occupies(p2); 1 } 1 (3). (a) Differentiate between default & parameterized constructor with suitable 1 example. 2 1 (b) What is the significance of private, protected and public access specifiers in a class? 2 1 (c) Answer the questions (i) and (ii) after going through the following class. 2 1 class player 1 { int health; 1 int age; 1 public: 1 player( ) { health=6; age=18; } //Function 1 1 player(int s, int a) {health =s; age = a ; } // Function 2 1 player( player &p); // Function 3 1 ~player( ) { cout<<Memory Deallocate; } // Function 4 1 4 1 Mohd Hashim, PGT (Computer Sc.), Class- XII (2010-11) 1 }; 1 void main( ) 1 { player p1(7,24); //Statement1 1 player p3 = p1; //Statement3 1 } 1 (i) When p3 object created specify which constructor invoked and why? Write complete 1 definition for Function 3? 1 (ii) Which concept of C++ is demonstrated by Function 1, 2 and 3? Write the calling 1 statement of Function 1. 1 (d). Define a class BALANCED_MEAL in C++ with following description: 4

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

1 1

Private Members: Access_no Integer 1 Name_of_Food String of 25 characters 1 Calories Integer 1 Food_type String 1 Cost Float 1 AssignAccess( ) Generates random numbers between 0 to 1 99 and return it. 1 Public Members 1 A function INTAKE( ) to allow the user to enter the values of Name_of_Food, 1 Calories, Food_type, cost and call function AssignAccess( ) to assign Access_no. 1 A function OUTPUT( ) to allow user to view the content of all the data members, if 1 the Food_type is Fruit. 1 (e). Define a class Employee in C++ with the following specification: 4
1 1

Private Members: ename an array of char of size[50] ( represent employee name) 1 deptname an array of char of size[20] ( represent department name) 1 salary integer ( represent total salary of an employee) 1 bonus float 1 CalBonus() This function calculate the total bonus given to an employee 1 according to following conditions 1 Deptname Bonus 1 Accounts 4 % of salary 1 HR 5% of salary 1 IT 2% of salary 1 Sales 3% of salary 1 Marketing 4% of salary 1 Public Members: 1 Constructor to initialise ename and deptname to NULL and salary and bonus to 0. 1 A function read_info to allow user to enter values for ename, deptname,salary & Call 1 function CalBonus() to calculate the bonus of an employee. 1 A Function disp_info() to allow user to view the content of all the data members.
1 1 1

(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 1 #include<iostream.h> 1 void main() 1 { 1 5 1 Mohd Hashim, PGT (Computer Sc.), Class- XII (2010-11) 1 int Numbers[] = {2,4,8,10}; 1 int *ptr = Numbers; 1 for (int C = 0; C<3; C++) 1 { 1 cout<< *ptr << @; 1 ptr++; 1 } 1 cout<<endl; 1 for(C = 0; C<4; C++) 1 { 1 (*ptr)*=2; 1 --ptr; 1 } 1 for(C = 0; C<4; C++) 1 cout<< Numbers [C]<< #; 1 cout<<endl; 1 } 1 (5). (a) Consider the following declarations and answer the questions given below: 4 1 class RED 1 { char n [ 20 ]; 1 void input ( );

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

1 1

protected: int x , y ; 1 void read ( ); 1 public: 1 RED ( ); 1 RED ( int a ); 1 void get_red ( ); 1 void put_red ( ); 1 }; 1 class WHITE : protected RED 1 { int a , b ; 1 protected : 1 int c , d ; 1 void get_white( ); 1 public: 1 WHITE ( ); 1 void put_white ( ); 1 }; 1 class BLACK : private WHITE 1 { char st[20]; 1 protected : 1 int q; 1 void get_black( ); 1 public: 1 BLACK ( ); 1 void put_black ( ); 1 }ob; 1 i. Name the data members and member functions which are accessible by the object ob. 1 ii. Give the size of object ob and class WHITE. 1 iii. Name the OOPS concept implemented above and its type. 1 6 1 Mohd Hashim, PGT (Computer Sc.), Class- XII (2010-11) 1 iv. Name the members accessible by function get_black( ). 1 (b). Can a derived class get access privilege for a private member of the base 1 class? If yes, how? 2 1 (6). (a) Name two modes common to classes ifstream and ofstream? 1 1 (b) Write a user defined function in C++ to read the content from a text file MYBOOK.TXT 1 and count & display the number of word India present in the file. 2 1 (c). Following is the structure of each record in a data file named COLONY.DAT 3 1 struct Colony 1 { 1 char colony_code[10]; 1 char colony_name[10]; 1 int no_of_people; 1 }; 1 Write a function to update the file with a new value of no_of_people. The value of 1 colony_code 1 and no_of_people are read during the execution of the program. 1 (d).Write a function to count the number of VOWELS present in a text file 1 named PARA.TXT. 2 1 (e). Observe the program segment given below carefully and fill the blanks marked as 1 Statement 1 and Statement 2 using seekp() and seekg() functions for performing the required 1 task. 1 1 #include <fstream.h> 1 class Item 1 { 1 int Ino;char Item[20]; 1 public: 1 //Function to search and display the content from a particular //record number 1 void Search(int ); 1 //Function to modify the content of a particular record number

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

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]
1 1

void Modify(int); }; 1 void Item::Search(int RecNo) 1 { 1 fstream File; 1 File.open(STOCK.DAT,ios::binary|ios::in); 1 ______________________ 1 //Statement 1 1 File.read((char*)this,sizeof(Item)); 1 cout<<Ino<<==><<Item<<endl; 1 File.close(); 1 } 1 void Item::Modify(int RecNo) 1 { 1 fstream File; 1 7 1 Mohd Hashim, PGT (Computer Sc.), Class- XII (2010-11) 1 File.open(STOCK.DAT,ios::binary|ios::in|ios::out); 1 cout>>Ino;cin.getline(Item,20); 1 ______________________ 1 //Statement 2 1 File.write((char*)this,sizeof(Item)); 1 File.close(); 1 } 1 (7). (a). Write a function in C++ which accepts an integer array and its size as arguments and 1 exchanges the values of first half side elements with the second half side elements of the 1 array. 4 1 Example : If an array of 8 elements initial content as 2, 4, 1, 6, 7, 9, 23, 10 1 The function should rearrange array as 7, 9, 23, 10, 2, 4, 1, 6 1 (b). An array MAT [15] [7] is stored in the memory along the column with each element 1 occupying 2 bytes of memory. Find out the base address and the address of element MAT[2] 1 [5], if the location of MAT [5] [4] is stored at the address 100. 4 1 (c). Write a user defined function in C++ which accepts a squared integer matrix with odd 1 dimensions (3*3, 5*5 ) & display the sum of the middle row & middle column 1 elements. For eg.: 4 1 257 1 372 1 569 1 The output should be: 1 Sum of middle row = 12 1 Sum of middle column = 18 1 (d). Write a function LowerHalf ( ) which takes a two dimensional array A, with size N rows 1 and N columns as argument and point the lower half of the array. 2 1 Eg: If A is 2 3 1 5 0 The output will be 2 1 7153171 1 25781257 1 015010150 1 3491534915 1 LIFE and TIME are two great teachers. LIFE teaches you the use of TIME and 1 TIME teaches you the value of LIFE.
1 1

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal

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; 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.

2 | Page

MAMS/QUESTION BANK- COMP.SC. Compiled By : Ms. Chandni Agarwal