JB Academy, Faizabad Half Yearly Examination - 2017-18 Subject: Computer Science (083) Class XII Time: 3 Hours Max. Marks: 70 Instructions: i) All questions are compulsory and so attempt all. ii) Programming language: C++. Q1. (a) What does Overloaded function mean? How is constructor overloading different from function overloading. [3] (b) Name the header file required for successful compilation of the given code: [2] ifstream fin( story.dat ); char ch1; int alpha=0; if (isalpha(fin.get(ch1)) ++alpha; fin.close(); getch(); (c) Rewrite the following program after removing all the syntactical errors underlining each correction also.(if any): [3] #include<iostream.h> Void main() Int a[5]=2,4,6,8,9; Int *pt; for(int i=0;i<5;i++) cout<<*(pt); (d) Find the Errors in the following program code and rewrite the correct code. [3] Include<iostream.h> class deposite int acno; char cnm[20]; float balance; void deposite() void input() cout<< Enter the acno ; cin>>acno; deposite b(123, xyz,5000); input(); Q2. (a) Define following terms- [4] (i) Inline function (ii) Data encapsulation (iii) Dynamic memory allocation (iv) Memory leaks. (b) Define a class Tour with the following specifications. [4] Private Members : Tcode string No_of_adults int No_of_kids int Kilometers int Totalfare float Pg-1
Public members: A constructor to assign initial values as follows Tcode with NULL No_of_adult with 0 No_of_kids with 0 Kilometers with 0 Totalfare with 0.0 A function AssignFare() which calculates and assigns the value of the data member totalfare as follows- For each Adult Fare(Rs) For Kilometers 500 >=1000 300 <1000 and >= 500 200 <500 For each kid the above fare will be 50% of the fare mentioned in the above table For example: If Kilometers is 850, no_of_adults=2 and no_of_kids=3 Then totalfare should be calculated as Totalfare=No_of_adults*300+no_of kids*150 i.e. 2*300+3*150=1050 A function Entertour() to input the values of data members tcode, no_of_adults, no_of_kids and kilometers and invoke the AssignFare() function. A function show() which displays the content of all the data members for a tour. (c) Define a class CABS in C++ with following description: [4] Private members : Cno- to store cab number Type- to store a character A, B or C as city type PKM- to store per Kilo Meter charges Dist- to store distance travelled (in KM) Member Functions: A constructor function to initialize type as A and cno 1111. A function charges() to assign PKM as per the following table: Type A B C PKM 25 20 15 A function register() to allow administrator to enter the values for cno and type. Also this function should call charges() to assign PKM charges. A function showcab() to allow user to enter the value of distance and display cno, type PKM, PKM*distance(as amount) on screen (d) Answer the questions (i) and (ii) after going through the following class. [2] Class Match int time; Public: Match() time=0; Cout<< Match comments <<endl; //function1 Pg-2
; Void Details() cout<< Intersection Basketball Match <<endl; Match(int Duration) Time=Duration; Cout<< Another Match begins now <<endl; Match (Match &M) Time=M.Duration; Cout<< Like previous Match <<endl; //function2 //function3 //function4 (i) Which category of constructor-function 4 belongs and what is purpose of using it? (ii) Write statements that would call the member functions 1 and 3 Q.3 (a) Consider the following declarations and answer the questions given below [4] class Btech char streamcode[5]; protected: int seats; void allot(); Btech( ); void streamread(); void streamwrite(); ; class dept : protected Btech char deptname[20]; int strength; dept(); void deptread(); void deptwrite(); ; class course: public dept char coursename[20]; float fees; course(); void courseread(); void coursewrite(); ; (i) (ii) (iii) (iv) Which type of inheritance is shown in the above example? How many bytes will be required by an object of the class course? Write the name of all the data members accessible from member functions of the class dept. Write the name of member functions which are accessible from the object of the class course. (b) What is containership? How does it differ from inheritance? [3] ( c ) When does ambiguity arise in multiple inheritance? How can one resolve it? [3] Q.4 (a) 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. [2] #include <fstream.h> Class Libraray Long ano; Char title[20]; Int qty; Pg-3
Public: Void enter(int); Vid display(); Void buy(int q); qty=qty+q Long getano() return(ano); ; Void BuyBook(long bano, int bqty) // bano- ano of book purchased // bqty- Number of books purchased Fstream file; File.open( stock.in, ios::in ios::out ios::binary); Int position=-1; Library L; While(position==-1 && file.read((char*)&l,sizeof(l))) if(l.getano()==bano) L.buy(bqty); Position=file.tellg( )- sizeof(l); statement 1 statement 2 If(position==-1) Cout<< No updation done ; File.close(); (b) (c) Write a function in C++ to count the number of word Delhi present in a text file TOUR.TXT. [3] Write a programme to store a paragraph in a data file Test.txt and delete appearance of word he from the file. Also display content of file after deletion. [4] (d) Write a function showfile( ) to read all records present in an already created file [3] speed.dat and display them on screen, also count the number of records present in the file. Assume that there is a class Vehicle and object of Vehicle are stored in file. (e) Differentiate between (1) Text file and Binary files. (2) read() and getline() [6] (3) ios::app and ios::out Q.5 (a) Write a programme to display content of a 2 D array using pointers. [3] int A[3][3]=1,2,3,6,5,4,9,8,7; (b) An array P[20][30] is stored in the memory along with column with each of the Element occupying 4 bytes, find out the Base address of the array, if an element P[2][20] is stored at the memory location 5000. [3] ( c) Write a programme to sort an array of 10 element using bubble sort technique. [3] Also display the array after sorting. (d) Suppose A,B and C are arrays of integers of size m,n and m+n respectively. The Numbers in array A are in ascending order and in array B in descending order. Write A programme to create a third array C containing all the data of array A and B in ascending order. [4] Pg-4
(e) Predict the output- [2+2] (1) for(i=3; i<10; i++) (II) if(i==4) i=i+5; for(j=4; j>0; j--) cout<<j*i<< ; cout<<endl char *p= Difficult ; char c; c=++ *p ; cout<<c ; ************************* Pg-5