THE INDIAN COMMUNITY SCHOOL, KUWAIT SERIES : I SE / 2016-2017 CODE : N 083 MAX. MARKS : 70 TIME ALLOWED : 3 HOURS NO. OF PAGES : 9 COMPUTER SCIENCE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Note: All questions are compulsory Read the questions carefully 1. a. Define Macro with suitable example. b. Rani has started learning C++ and has typed the following program. When she compiled the (1) following code written by her, she discovered that she needs to include some header files to successfully compile and execute it. Write the names of those header files, which are required to be included in the code. float A,Number,Outcome; cin>>a>>number; Outcome=pow(A,Number); cout<<outcome<<endl; c. Rewrite the following C++ code after removing any/all syntactical errors with each correction underlined. Note: Assume all required header files are already being included in the program. #define Formula(a,b) = 2*a+b float X=3.2;Y=4.1; Z=Formula(X,Y); cout<< Result= <<Z<<endl; d. Find and write the output of the following C++ program code: Note: Assume all required header files are already included in the program. typedef char STRING[80]; void MIXITNOW(STRING S) int Size=strlen(S); for (int I=0;I<Size1;I+= 2) char WS=S[I]; S[I]=S[I+1]; S[I+1]=WS; for (I=1;I<Size;I+=2) if (S[I]>= M && S[I]<= U ) S[I]= @ ; STRING Word= CRACKAJACK ; MIXITNOW(Word); cout<<word<<endl; 1
e. Find and write the output of the following C++ program code: Note: Assume all required header files are already being included in the program. class Share long int Code; float Rate; int DD; Share()Code=1000;Rate=100;DD=1; void GetCode(long int C,float R) Code=C; Rate=R; void Update(int Change,int D) Rate+=Change; DD=D; void Status() cout<< Date: <<DD<<endl; cout<<code<< # <<Rate<<endl; ; Share S,T,U; S.GetCode(1324,350); T.GetCode(1435,250); S.Update(50,28); U.Update(25,26) ; S.Status(); T.Status(); U.Status(); 2
f. Study the following program and select the possible output(s) from the options (i) to (iv) following it. Also, write the maximum and the minimum values that can be assigned to the variable NVM. Note: Assume all required header files are already being included in the program. random(n) function generates an integer between 0 and n - 1. randomize(); int NOM; NOM=random+2; char TEXT[]="ABCDEFGHIJK"; for (int I=1;I<=NOM; I++) for(int J=NUM; J<=7iJ++) cout<<text[j]; cout<<end1; (i) FGHI FGHI FGHI FGHI (ii) BCDEFGH BCDEFGH (iii) EFGH EFGH EFGH EFGH (iv) CDEFGH CDEFGH g. Find the output of the following Program: #include<iostream.h> Struct THREE_D int x,y,z; ; void MoveIn(THREE_D &T, int Step=1) T.x + =Step; T.y - =Step; T.z - =Step; void MoveOut(THREE_D &T, int Step=1) T.x - =Step; T.y + =Step; T.z - =Step; void main( ) THREE_D T1=10,20,5; T2=30,10,40; MoveIn(T1); MoveOut(T2,5); cout<<t1.x<<, <<T1. y<<, <<T1.z<<, <<endl; cout<<t2.x<<, <<T2. y<<, <<T2.z<<, <<endl; MoveIn(T2.10); cout<<t2.x<<, <<T2. y<<, <<T2.z<<, <<endl; 2. a. What is a copy constructor? Give a suitable example in C++ to illustrate with its definition within a class and a declaration of an object with the help of it. 3
b. Write any four important characteristics of Object Oriented Programming? Give example of any one of the characteristics using C++. c. Rewrite the following program after removing the syntactical error(s)(if any). Underline each correction. #include<iostream.h> class Transport char Model[20]; char Name[20]; void Get( ) gets(model); gets(name); void Show( ) cout<<model<<endl; puts(name); ; void main( ) Transport T; Get.T( ); Show( ); d. Define a class RESORT in C++ with following description : Private Members : Rno //Data member to store Room No. Name //Data member to store customer name. Charges //Data member to store per day charges. Days //Data member to store number of days of stay. COMPUTE()//A function to calculate and return Amount as Days*Charges and if the value of Day*Charges is more than 11000 then as 1.02*Days*Charges Public Members Getinfo() //A function to enter the content Rno, Name,Charges and Days Dispinfo() //A function to display Rno, Name, Charges,Days and Amount (Amount to be displayed by calling function COMPUTE()) e. Answer the questions (i) and (ii) after going through the following class: class WORK int WorkId; char WorkType; ~WORK() //Function 1 cout<< Un-Allocated <<endl; void status() //Function 2 cout<<workid<< : <<Work Type<<endl; WORK() //Function 3 WorkId=10 ; WorkType= T ; WORK(WORK & W) //Function 4 WorkId=W.WorkId+12; Work Type=W.WorkType+1 ; 4
(i) Which member function out of Function 1, Function 2, Function 3 and Function 4 shown in the above definition of class WORK is called automatically, when the Scope of an object gets over? Is it known as Constructor OR Destructor OR Overloaded Function OR Copy Constructor? (ii) WORK W; //Statement 1 WORK Y (W); //Statement 2 Which member function out of Function 1, Function 2, Function 3 and Function 4 shown in the above definition of class WORK is called on execution of statement 2? What is it specifically called Destructor, Copy constructor, parameterized constructor or default constructor. 3. a. Answer the questions (i) to (iv) based on the following : class Regular char School Code [10]; public : void InRegular(); void outregular(); ; class Distance char StudyCentreCode[5]; public : void Indistance ( ); void OutDistance ( ); ; class Course: public Regular, private Distance char Code[5]; float Fees ; int Duration; void InCourse (); void Out Course (); ; (i) Which type of Inheritance is shown in the above example? (ii) Write names of all the member functions accessible from OutCourse function of class Course. (iii) Write name of all the members accessible through an object of class Course. (iv) Is the function InRegular() accessible inside the function InDistance()? Justify your answer. b. Answer the questions (i) to (iv) based on the following : class Toys char TCode[5]; protected: float Prince; void Assign(float) ; Toys(); void TEntry(); void TDisplay(); ; class SoftToys : public Toys char STname[20]; float Weight; SoftToys(); 5
Void STEntry(); Void STDisplay(); ; Class ElectronicToys : public Toys char ETname[20]; int No_of_Batteries; Public: Electronic Toys(); Void ETEntry(); Void ETDisplay(); ; (i) (ii) (iii) Which type of inheritance is shown in the above example? How many bytes will be required by an object of the class SoftToys? Write name of all the data members accessible from member functions of the class SoftToys. (iv)write name of all the member functions which are accessible from an object of the class Electronic Toys. 4. a. Find the output of the following program : #include<iostream.h> int X[] = 10, 25, 30, 55, 110; int *p = X; while (*p < 110) if (*p%3!= 0) *p = *p + 1; else *p = *p + 2; p++; for (int I = 4; I>=1 ; 1 I ) cout<<x [I] << * ; if (I%3 == 0) cout<<endl; cout<<x [0] * 3<<endl; b. In the following program,what will be the possible output(s) from the following options (i),(ii),(iii) and (iv)?justify your answer. #include<iostream.h> #include<stdlib.h> #include<string.h> #include<conio.h> clrscr(); char *Text= 1234 ; int L=strlen(Text); randomize (); for(int I=0;I<L;I++) int start=random(i)+1; Char p=text[start]; 6
Cout<<P<< : ; getch(); (i)1:3:2:4 (iii)2:2:3:2 (ii)2:2:3:2 (iv)2:2:2:3 5. a. Write function definition for WORD4CHAR() in C++ to read the content of a text file FUN.TXT, and display all those words, which has four characters in it. Example: If the content of the file fun.txt is as follows: When I was a small child, I used to play in the garden with my grand mom. Those days were amazingly funful and I remember all the moments of that time The function WORD4CHAR() should display the following: When used play with days were that time b. Write a definition for function Economic ( ) in C++ to read each record of a binary file ITEMS.DAT, find and display those items, which costs less than 2500. Assume that the file ITEMS.DAT is created with the help of objects of class ITEMS, which is defined below: class ITEMS int ID;char GIFT[20]; float Cost; public : void Get () cin>>code;gets(gift);cin>>cost; void See () cout<<id<<":"<<gift<<":"<<cost<<end1; float GetCost() return Cost;. ; c. Observe the program segment given below carefully and fill the blanks marked as Line 1 and Line 2 using fstream functions for performing the required task. #include <fstream.h> class Stock long Ino; //Item Number char Item [20];//Item Name int Qty; //Quantity void Get(int); //Function to enter the content void show(); //Function to display the content void Purchase (int Tqty) Qty+=Tqty; //Function to increment in Qty long KnowIno () return Ino; ; void Purchaseitem (long PINo, int PQty) //PINo > Ino of the item purchased //PQty > Number of item purchased fstream File; File. open ( STOCK.DAT, ios: : 7
binary ios: : in ios: : out); int Position= 1; Liberary L; while (Position = = 1 && File. read ((char * ) &L, sizeof (L))) if (L. GetAno() = =BANo) L. Buy (BQty); //To update the number of Books Positions=File. tellg() sizeof (L); //Line 1: To place the file pointer to the required position. ; //Line 2: To write the object L on to the binary file ; if (Position== 1) cout<< No updation done as required Ano not found... ; File. Close(); 6. a. Write the definition of a function FixPay(float Pay[], int N) in C++, which should modify each element of the array Pay having N elements, as per the following rules: b. Write a COLSUM function in C++ to find sum of each column of a N * M matrix. c. A two dimensional array P[20] [50] is stored in the memory along the row with each of its element occupying 4 bytes, find the address of the element P[10] [30], if the element P[5] [5] is stored at the memory location 15000. d. Convert the following infix expression to its equivalent Postfix expression, showing the stack contents for each step of conversion. X / Y + U* (V-W) e. Evaluate the following Postfix notation of expression showing the stack contents for each step of conversion. FALSE,NOT,True,AND,True,False,OR,AND f. Write the definition of a member function INSERT() for a class QUEUE in C++, to insert an ITEM in a dynamically allocated Queue of items considering the following code is already written as a part of the program. struct ITEM int INO; char INAME[20]; ITEM *Link; ; class QUEUE ITEM *R, *F; QUEUE()R=NULL;F=NULL; void INSERT(); void DELETE(); ~QUEUE(); ; 8
g. Write a function in C++ to delete a node containing Book s information, from a dynamically allocated stack of Books implemented with the help of the following structure. struct Book int BNO; char BName[20]; Book *Next; ; 9