Vous êtes sur la page 1sur 24

COMPUTER

SCIENCE
PREFACE
The home assignment , being given to the students ,
aims at strengthening the concepts of each student
through reinforcement of topics covered in class
lectures by practicing the questions given in the
assignment.
Some sample papers in each subject have been
given.
The maximum benefit can be gained only if the
student goes through all the topics of fragment 1
thoroughly before attempting the sample paper. The
assignment will not only act as a reinforcement tool
but will also help the students acquire the tendency of
solving the entire paper in one sitting, just like he/she
sits in an examination for three hours. Hence,
improving student’s time management skill in
examination.

This assignment will also fetch the student 5 marks in


practical. The solutions of all the question papers
given in the home assignment have to be written on
separate A-4 sheets.
For all the subjects , the assignments have to be
submitted in different folders respectively.
Last date to submit the assignment for each subject
5th July ’19.
- PRINCIPAL
ASSIGNMENT 1 : 2019-2020
COMPUTER SCIENCE : XII MARKS: 70

Q.1 a. What is function overloading ? Explain with a suitable example. 2


b.Write the prototype of the overloaded function namely SUM(), that adds three
integers and return an integer, that adds two double numbers and return a double
value, that adds one integer and one float value and return float result. 1
c.Which function is called during each function call in the program given below :
1
int add( int x ); (I)
char choice ( char a, char b ); (II)
char choice ( char a) (III)
float add ( int x, float y ); (IV)
void main()
{
int n;
char ch,ch1;
float n1;
add (n);
choice (ch);
add(n,n1);
choice(ch,ch1);
}
d. What will be the output of the following program : 2
#include < iostream.h>
int area ( int s )
{
return s *s ;
}
float area ( int a, int b )
{
return 0.5 * b * h;
}
main()
{
cout << area ( 8) << endl;
cout<< area ( 4, 3) << endl;
cout << area ( 6 , area(4) )<<endl;
}

Q.2 a.Write the names of ‘ access specifier ‘ , which can be used in a class. 1
b.What will be the output of the following program segment : 3
#include < iostream.h>
class myclass
{
int a;
public:
void set_a ( int num );
int get_a();
};
void myclass :: set_a( int num )
{
a = num;
}
int myclass :: get_a ()
{
return a ;
}
void main ( )
{
myclass ob1, ob2;
ob1.set_a( 25);
ob2.set_a ( 120 );
cout<< ob1.get_a( ) << endl;
cout<< ob2.get_a( ) << endl;
}
d.Define a class TRAIN in c++ with the following description: 4
data members
train_no integer
train_name 20 characters
source 20 characters
dest 20 characters
fare float
member function GETFARE ( ) to assign the following values for charges:

Dest Fare
MUMBAI 2000
CHENNAI 3000
KOLKATA 3500
Public members :
A constructor to initialize the data members as Train_no = 0,
Train_name =”XXXXX”, source = “YYYYY”, dest=”ZZZZZZ” and fare =0
A function InputData( ) to allow the user to enter the data members values
except fare
A function DisplayData( ) to display all data members and call function
GetFare ( )

Q. 3 a. Write any two differences between class member function and a constructor.2
b. Write any two differences between constructor and destructor. 2
c. Why constructor and destructor must always be mentioned under public access
specifier only. Justify your answer with a suitable example. 2

d. Find the output of the following program: 2


# include < iostream . h>
class metro
{
int mno, tripno, pc;
public:
metro ( int tmno=1)
{
mno = tmno; tripno = 0; pc = 0;
}
void trip( int pct=20)
{
tripno++; pc + = pct;
}
void status_show()
{
cout<< mno<<”;”<< tripno<<”;”<< pc <<endl;
}
};
void main()
{
metro m(5), t;
m.trip( );
t.trip ( 60 );
m. status_show( );
m.trip ( 50);
t.status_show( );
m.status_show ( );
}
e. Rewrite the following program after removing the syntactical errors is any.
Underline each correction : 2
# include < iostream.h>
CLASS STUDENT
{
float marks;
int admno;
public:
student ( )
{ admno=0;
marks=0.0 }
void input ()
{ cin >> admno; cin>> marks; }
void output ( )
{ cout<<admno<<marks ; } }

void main( )
{
STUDENT S;
Input ( S);
}
Q.4 a. Define multiple Inheritance in context of Object Oriented Programming. 1
b. What is the benefit of Inheritance ? Explain it with a suitable example. 2
c. Differentiate between Public and Protected visibility mode in context of Object
Oriented Programming giving suitable example. 2
d. Define Abstract class . 1
e. What is the order of invocation of constructor and desGtructor, in context of
Inheritance. 1
f. Given the following base class 4
class area_c1
{
Public:
Double height;
Double width;
};
Create two derived classes rectangle and isosceles that inherit area_c1. Have each
class included a function called area() that returns the area of a rectangle or isosceles
triangle, as appropriate. Use parameterized constructor to initialize height and width.

g. Given the following declarations : 2


class A
{
Protected :
Int x;
Public:
Void get ( int );
Void put ( int );
Void show ( int );
};
Class B
{
Protected :
Int y;
Public :
Void getB( int );
Void show ( int );
};
Class C : public A, public B
{
Public:
Void showdata ( int );
};

i. List the data and functions inherited by class C


ii. Name the class(es) that can access showB( ) declared in class B
ASSIGNMENT 2 : 2019-2020
COMPUTER SCIENCE : XII MARKS: 70

General Instructions:
(a) All questions are compulsory.
(b) Programming Language : C++
(c) Read the questions before writing answers.

1 a) i) Write the function prototype to accept any two Names and return the length of 1
smaller string.
ii) To call a function int MakeOver(int,int&); which are valid statements and why?. 1
a. int R=MakeOver(10,20);
b. cout<<MakeOver(10,B); //B is a integer variable
c. MakeOver(B,B); //B is a integer variable
d. MakeOver(B,10); //B is a integer variable

b) Find the output of the following program: 2


#include<iostream.h>
void PICK(int Temp=20)
{ for(int I=10;I<=Temp;I+=5)
cout<<I<<”,”;
cout<<endl;
}
void PICK_IT(int &Num)
{ Num+=10;
PICK(Num);
}
void main( )
{ int Number=20;
PICK_IT(Number);
PICK( );
cout<<”Number =”<<Number<<endl;
}

c) Rewrite the following program after removing the syntactical errors (if any). 2
Underline each correction.
#include<iostream.h>
void main( )
{
int One=10,Two=20;
Callme(One,Two);
Callme(Two);
Callme();
}
void Callme(int Arg1=24,int Arg2);
{
Arg1=Arg1+Arg2;
cout<<Agr1<<Agr2;
}

d) Which of the following option/s represents Inheritance feature: 1


i. Extending classes
ii. Transitive nature of classes.
iii. Procedure oriented approach.
iv. Both i & ii
e) Which C++ header file(s) will be essentially required to be included to execute the 1
following C++ code:
void main()
{
ofstream R(“abc.txt”);
char Info[ ]="The beginning of the World";
R<<info<<endl;
puts(Info);
R.close();
}
f) Identify the base class and derive class in the following code: 1
class Father
{
int age;
};
class child:Father
{
char Name[20];
};
class grandchild
{
int age;
};

g) Define role of membership label with respect to object oriented programming. 1


2 a) How a class variable differs from instance variable? Which keyword is used to declare 1
data member as class variable?

b) Mention the criteria to define a member function as inline function. 1

c) Explain Data Encapsulation and Data Abstraction using an example program code. 2
d) Rewrite the following program after removing the syntactical errors (if any). 2
Underline each correction.
#include <iostream.h>
CLASS MEMBER
{
int Mno;
float Fees=1000;
PUBLIC:
void Register()
{
cin>>Mno>>Fees;
}
void Display();
};
void Display()
{
cout<<Mno<<" : "<<Fees<<endl;
}

void main()
{
MEMBER M;
Register();
M.Display();
}

e) Explain Data hiding with respect to object oriented programming using a suitable 2
program.

f) Find and write the output of the following C++ program code : 3
Note : Assume all required header files are already being included in the program.
class Stock
{
long int ID;
float Rate;
int Date;
public:
Stock(){
ID=1001;
Rate=200;
Date=1;
}
void RegCode(long int I,float R)
{
ID=I;
Rate=R;
}
void Change(int New,int DT)
{
Rate+=New;
Date=DT;
}
void Show()
{
cout<<”Date :”<<Date<<endl;
cout<<ID<<”#”<<Rate<<endl;
}
};
void main()
{
Stock A,B,C;
A.RegCode(1024,150);
B.RegCode(2015,300);
B.Change(100,29);
C.Change(–20,20);
A.Show();
B.Show();
C.Show();
}

c) Write the definition of a class CITY in C++ with following description: 4

private Members
-Ccode //Data member for City Code (an integer)
-CName //Data member for City Name (a string)
-Pop //Data member for Population (a long int)
KM //Data member for Area Coverage (a float)
-Density //Data member for Population Density (a float)
-DenCal() //A member function to calculate Density as Pop/KM

public Members
-Record() //A function to allow user to enter values ofAcode,Name,Pop,KM
//and call DenCal() function
-View() //A function to display all the data membersalso display a message
//”Highly Populated City”if the Density is more than 10000

3 a) Which function(s) out of the following can be considered as overloadedfunction(s) in the 1


same program? Also, write the reason for not considering theother(s) as overloaded
function(s).
void Execute(char A,int B); //Function 1
void Execute(int A,char B); //Function 2
void Execute(int P=10); //Function 3
void Execute(); //Function 4
int Execute(int A); //Function 5

b) Give one similarity and one difference between constructor and destructor. 1

c) Observe the following C++ code and answer the questions (i) and (ii). Assume all 2
necessary files are included:
class BOOK
{
long Code ;
char Title[20];
float Price;
public:
BOOK() //Member Function 1
{
cout<<”Bought”<<endl;
Code=10;strcpy(Title,”NoTitle”);Price=100;
}
BOOK(int C,char T[],float P) //Member Function 2
{
Code=C;
strcpy(Title,T);
Price=P;
}
void Update(float P) //Member Function 3
{
Price+=P;
void Display() //Member Function 4
{
cout<<Code<<”:”<<Title<<”:”<<Price<<endl;
}
~BOOK() //Member Function 5
{
cout<<”Book Discarded!”<<end1;
}
};
void main() //Line 1
{ //Line 2
BOOK B,C(101,”Truth”,350); //Line 3
for (int I=0;I<4;I++) //Line 4
{ //Line 5
B.Update(50);C.Update(20); //Line 6
B.Display();C.Display(); //Line 7
} //Line 8
} //Line 9
i) Which specific concept of object oriented programming out of the following is illustrated
by Member Function 1 and Member Function 2 combined together?
● Data Encapsulation ● Polymorphism
● Inheritance ● Data Hiding
ii) How many times the message ”Book Discarded!” will be displayed afterexecuting the
above C++ code? Out of Line 1 to Line 9, which line isresponsible to display the
message ”Book Discarded!”

d) Explain copy constructor using an example program. 2

e) Define a class named Admission in C++ with following description? 4


Private members:
admno integer (Ranges 10-1500)
name string of 20 characters
cls integer
fees float
Public members:
• A constructor which initialized admno with 10, name with “NULL”, cls with 0 & fees
with 0
• A parameterizied constructor to accept name,cls and fees and initialize instance
variable.
• Function putdata() to print the details of object of admission type.
• Function draw_nos() to generate the admission no. randomly to match with
admno and display the detail of object.
Write main() function body to create two objects ,one with implicit call to default
constructor and other with explicit call to parameterized constructor.Call
draw_nos() function for both objects.

4 a) Observe the following C++ code and answer the questions (i) and (ii).
Note : Assume all necessary files are included.
class FIRST
{
int Num1;
public:
void Display() //Member Function 1
{
cout<<Num1<<endl;
}
};
class SECOND: public FIRST
{
int Num2;
public:
void Display() //Member Function 2
{
cout<<Num2<<endl;
}
};
void main()
{
SECOND S;
___________________ //Statement 1
___________________ //Statement 2
}
i) Which Object Oriented Programming feature is illustrated by the definitions of 1
classes FIRST and SECOND?
ii) Write Statement 1 and Statement 2 to execute Member Function 1 and Member 1
Function 2 respectively using the object S

b) Explain the difference between containership and derivation using an example c++ code. 2

c) Explain the visibility modes private, public and protected using a c++ program. 3

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


class Teacher
{
int TCode;
protected:
char Name[20];
public:
Teacher();
void Enter(); void Show();
};
class Course
{
int ID;
protected:
Char Title[30];
public:
Course();
void Initiate();
void Display();
};
class Schedule: public Course, private Teacher
{
int DD,MM,YYYY;
public:
Schedule();
void Start();
void View();
};
void main()
{
Schedule S;
}
i) Which type of Inheritance out of the following is illustrated in the above example?
Single Level Inheritance, Multilevel Inheritance, Multiple Inheritance.
ii) Write the names of all the members, which are directly accessible by the member
function View() of class Schedule.
iii)Write the names of all the members, which are directly accessible by the object S of
class Schedule declared in the main() function.
iv)What will be the order of execution of the constructors, when the object S of class
Schedule is declared inside main() function?

e) Consider the following class HUMAN : 4


class HUMAN
{
protected :
char NAME[90];
int age;
public :
HUMAN ( )
{
strcpy(NAME,”noname”);
Age=0;
}
void enter( )
{
cin>>age;
gets(NAME);
};
void display()
{
cout<<NAME<<”,”<<age<<endl;
}
};
Write a code in C++ to publically derive another class ‘TEACHER’ from HUMAN
with the following additional members in the private visibility mode.
Data Members :
• Salary double
Member functions :
• ENTER(double ) : To initialize name,age and set salary by the value passed to
the function
• DETAILS( ) : To display all the details of teacher

f) Define function overriding using an example code. 1

5 a) What is the role of eof( ) function? what type of value eof( ) returns? 1

b) Give difference between ios::app and ios::ate modes. 1

c) Write a function to read a text file “POET.TXT” that stores names of poets and copy all 2
the poets names starting with letter ‘P’ or ‘K’ to new file “NPOETS.TXT”.

d) A text file named MATTER.TXT contains some text, which needs to be displayed 2
such that every next character is separated by a symbol ‘#’.
Write a function definition for HashDisplay () in C++ that would display the entirecontent
of the file MATTER.TXT in the desired format.
Example:
If the file MATTER.TXT has the following content stored in it:
THE WORLD IS ROUND
The function HashDisplay () should display the following content:
T#H#E# #W#O#R#L#D# #I#S# #R#O#U#N#D#

e) Define a function to read a text file “profile.txt” and return the average length of word in 3
the file.
6 a) Find the output of the following C++ code considering that thebinary file sp.dat already 1
exists on the hard disk with 2 records in it.
class sports
{
int id;
char sname[20],coach[20];
public:
void entry();
void show();
void writing();
void reading();
}s;
void sports::reading()
{
ifstream i;
i.open("sp.dat");
1
while(1)
{
i.read((char*)&s,sizeof(s));
if(i.eof())
break;
else
cout<<"\n"<<i.tellg();
}
i.close();
}
void main()
{
s.reading();
}
b) Given a binary file “BUS.DAT”, containing records of the following class type. 3
class bus
{
int bus_no;
char desc[40];
int distance; //in km
public:
void bread()
{ cin>>bus_no; gets(desc) ; cin>>distance;
}
void bdisplay()
{ cout<<bus_no; puts(desc); cout<<distance;
}

int retdist()
{
return distance;
}
};
Write a function in C++ that would read contents of file “BUS.DAT” and display and
transfer the details of those buses which travels distance more than 100 km to other file
“Temp.DAT”.

c) Write a definition for function TotalTeachers( ) in C++ to read each object of abinary file 2
SCHOOLS.DAT, find the total number of teachers, whose data is storedin the file and
display the same. Assume that the file SCHOOLS.DAT is createdwith the help of objects
of class SCHOOLS, which is defined below:
class SCHOOLS
{
int SCode; // School Code
char SName[20]; // School Name
int NOT; // Number of Teachers in the school
public:
void Display()
{
cout<<SCode<<"#"<<SName<<"#"<<NOT<<endl;
}
int RNOT(){return NOT;
}};
d) Find the output of the following C++ code considering that the binary fileSCHOOLS.DAT 1
exists on the hard disk with the following records of 10 schools ofthe class SCHOOLS as
declared in the previous question (6 c).
SCode SName NOT
1001 Brains School 100
1003 Child Life School 115
1002 Care Share School 300
1006 Educate for Life School 50
1005 Guru Shishya Sadan 195
1004 Holy Education School 140
1010 Rahmat E Talim School 95
1008 Innovate Excel School 300
1011 Premier Education School 200
1012 Uplifted Minds School 100
void main()
{
void main()
{ fstream SFIN;
SFIN.open("SCHOOLS.DAT",ios::binary|ios::in);
SCHOOLS S;
SFIN.seekg(5*sizeof(S));
SFIN.read((char*)&S, sizeof(S));
S.Display();
cout<<"Record :"<<SFIN.tellg()/sizeof(S) + 1<<endl;
SFIN.close();
}

e) Define a C++ function UPDATE(int) to increase the price by 10% of the STOCK code 3
passed to the function from the binary file “stock.dat” containing records having
following structure:
struct STOCK{
int code;//item code
char name[60];
float price;
};
*****************
ASSIGNMENT 3 : 2019-2020
COMPUTER SCIENCE : XII MARKS: 70

General Instructions:
(a) All questions are compulsory.
(b) Programming Language : C++
(c) Read the questions before writing answers.

1 a) iii) Write the function prototype to accept any two Names and return the length of smaller
string.
iv) To call a function int MakeOver(int,int&); which are valid statements and why?.
e. int R=MakeOver(10,20);
f. cout<<MakeOver(10,B); //B is a integer variable
g. MakeOver(B,B); //B is a integer variable
h. MakeOver(B,10); //B is a integer variable

b) Find the output of the following program:


#include<iostream.h>
void PICK(int Temp=20)
{ for(int I=10;I<=Temp;I+=5)
cout<<I<<”,”;
cout<<endl;
}
void PICK_IT(int &Num)
{ Num+=10;
PICK(Num);
}
void main( )
{ int Number=20;
PICK_IT(Number);
PICK( );
cout<<”Number =”<<Number<<endl;
}

c) Rewrite the following program after removing the syntactical errors (if any). Underline
each correction.
#include<iostream.h>
void main( )
{
int One=10,Two=20;
Callme(One,Two);
Callme(Two);
Callme();
}
void Callme(int Arg1=24,int Arg2);
{
Arg1=Arg1+Arg2;
cout<<Agr1<<Agr2;
}

d) Which of the following option/s represents Inheritance feature:


v. Extending classes
vi. Transitive nature of classes.
vii. Procedure oriented approach.
viii. Both i & ii
e) Which C++ header file(s) will be essentially required to be included to execute the
following C++ code:
void main()
{
ofstream R(“abc.txt”);
char Info[ ]="The beginning of the World";
R<<info<<endl;
puts(Info);
R.close();
}

f) Identify the base class and derive class in the following code:
class Father
{
int age;
};
class child:Father
{
char Name[20];
};
class grandchild
{
int age;
};

g) Define role of membership label with respect to object oriented programming.

2 a) How a class variable differs from instance variable? Which keyword is used to declare data
member as class variable?

b) Mention the criteria to define a member function as inline function.

c) Explain Data Encapsulation and Data Abstraction using an example program code.

d) Rewrite the following program after removing the syntactical errors (if any).
Underline each correction.
#include <iostream.h>
CLASS MEMBER
{
int Mno;
float Fees=1000;
PUBLIC:
void Register()
{
cin>>Mno>>Fees;
}
void Display();
};
void Display()
{
cout<<Mno<<" : "<<Fees<<endl;
}

void main()
{
MEMBER M;
Register();
M.Display();
}

e) Explain Data hiding with respect to object oriented programming using a suitable program.

f) 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 Stock
{
long int ID;
float Rate;
int Date;
public:
Stock(){
ID=1001;
Rate=200;
Date=1;
}
void RegCode(long int I,float R)
{
ID=I;
Rate=R;
}
void Change(int New,int DT)
{
Rate+=New;
Date=DT;
}
void Show()
{
cout<<”Date :”<<Date<<endl;
cout<<ID<<”#”<<Rate<<endl;
}
};
void main()
{
Stock A,B,C;
A.RegCode(1024,150);
B.RegCode(2015,300);
B.Change(100,29);
C.Change(–20,20);
A.Show();
B.Show();
C.Show();
}

c) Write the definition of a class CITY in C++ with following description:

private Members
-Ccode //Data member for City Code (an integer)
-CName //Data member for City Name (a string)
-Pop //Data member for Population (a long int)
KM //Data member for Area Coverage (a float)
-Density //Data member for Population Density (a float)
-DenCal() //A member function to calculate Density as Pop/KM

public Members
-Record() //A function to allow user to enter values ofAcode,Name,Pop,KM
//and call DenCal() function
-View() //A function to display all the data membersalso display a message
//”Highly Populated City”if the Density is more than 10000

3 a) Which function(s) out of the following can be considered as overloadedfunction(s) in the


same program? Also, write the reason for not considering theother(s) as overloaded
function(s).
void Execute(char A,int B); //Function 1
void Execute(int A,char B); //Function 2
void Execute(int P=10); //Function 3
void Execute(); //Function 4
int Execute(int A); //Function 5

b) Give one similarity and one difference between constructor and destructor.

c) Observe the following C++ code and answer the questions (i) and (ii). Assume all
necessary files are included:
class BOOK
{
long Code ;
char Title[20];
float Price;
public:
BOOK() //Member Function 1
{
cout<<”Bought”<<endl;
Code=10;strcpy(Title,”NoTitle”);Price=100;
}
BOOK(int C,char T[],float P) //Member Function 2
{
Code=C;
strcpy(Title,T);
Price=P;
}
void Update(float P) //Member Function 3
{
Price+=P;
void Display() //Member Function 4
{
cout<<Code<<”:”<<Title<<”:”<<Price<<endl;
}
~BOOK() //Member Function 5
{
cout<<”Book Discarded!”<<end1;
}
};
void main() //Line 1
{ //Line 2
BOOK B,C(101,”Truth”,350); //Line 3
for (int I=0;I<4;I++) //Line 4
{ //Line 5
B.Update(50);C.Update(20); //Line 6
B.Display();C.Display(); //Line 7
} //Line 8
} //Line 9
i) Which specific concept of object oriented programming out of the following is illustrated by
Member Function 1 and Member Function 2 combined together?
● Data Encapsulation ● Polymorphism
● Inheritance ● Data Hiding
ii) How many times the message ”Book Discarded!” will be displayed afterexecuting the
above C++ code? Out of Line 1 to Line 9, which line isresponsible to display the message
”Book Discarded!”

d) Explain copy constructor using an example program.

e) Define a class named Admission in C++ with following description?


Private members:
admno integer (Ranges 10-1500)
name string of 20 characters
cls integer
fees float
Public members:
• A constructor which initialized admno with 10, name with “NULL”, cls with 0 & fees
with 0
• A parameterizied constructor to accept name,cls and fees and initialize instance
variable.
• Function putdata() to print the details of object of admission type.
• Function draw_nos() to generate the admission no. randomly to match with admno
and display the detail of object.
Write main() function body to create two objects ,one with implicit call to default
constructor and other with explicit call to parameterized constructor.Call draw_nos()
function for both objects.

4 a) Observe the following C++ code and answer the questions (i) and (ii).
Note : Assume all necessary files are included.
class FIRST
{
int Num1;
public:
void Display() //Member Function 1
{
cout<<Num1<<endl;
}
};
class SECOND: public FIRST
{
int Num2;
public:
void Display() //Member Function 2
{
cout<<Num2<<endl;
}
};
void main()
{
SECOND S;
___________________ //Statement 1
___________________ //Statement 2
}
i) Which Object Oriented Programming feature is illustrated by the definitions of
classes FIRST and SECOND?
ii) Write Statement 1 and Statement 2 to execute Member Function 1 and Member
Function 2 respectively using the object S

b) Explain the difference between containership and derivation using an example c++ code.

c) Explain the visibility modes private, public and protected using a c++ program.

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


class Teacher
{
int TCode;
protected:
char Name[20];
public:
Teacher();
void Enter(); void Show();
};
class Course
{
int ID;
protected:
Char Title[30];
public:
Course();
void Initiate();
void Display();
};
class Schedule: public Course, private Teacher
{
int DD,MM,YYYY;
public:
Schedule();
void Start();
void View();
};
void main()
{
Schedule S;
}
i) Which type of Inheritance out of the following is illustrated in the above example?
Single Level Inheritance, Multilevel Inheritance, Multiple Inheritance.
ii) Write the names of all the members, which are directly accessible by the member
function View() of class Schedule.
iii)Write the names of all the members, which are directly accessible by the object S of class
Schedule declared in the main() function.
iv)What will be the order of execution of the constructors, when the object S of class
Schedule is declared inside main() function?

e) Consider the following class HUMAN :


class HUMAN
{
protected :
char NAME[90];
int age;
public :
HUMAN ( )
{
strcpy(NAME,”noname”);
Age=0;
}
void enter( )
{
cin>>age;
gets(NAME);
};
void display()
{
cout<<NAME<<”,”<<age<<endl;
}
};
Write a code in C++ to publically derive another class ‘TEACHER’ from HUMAN with
the following additional members in the private visibility mode.
Data Members :
• Salary double
Member functions :
• ENTER(double ) : To initialize name,age and set salary by the value passed to the
function
• DETAILS( ) : To display all the details of teacher

f) Define function overriding using an example code.

5 a) What is the role of eof( ) function? what type of value eof( ) returns?

b) Give difference between ios::app and ios::ate modes.

c) Write a function to read a text file “POET.TXT” that stores names of poets and copy all the
poets names starting with letter ‘P’ or ‘K’ to new file “NPOETS.TXT”.

d) A text file named MATTER.TXT contains some text, which needs to be displayed
such that every next character is separated by a symbol ‘#’.
Write a function definition for HashDisplay () in C++ that would display the entirecontent of
the file MATTER.TXT in the desired format.
Example:
If the file MATTER.TXT has the following content stored in it:
THE WORLD IS ROUND
The function HashDisplay () should display the following content:
T#H#E# #W#O#R#L#D# #I#S# #R#O#U#N#D#

e) Define a function to read a text file “profile.txt” and return the average length of word in the
file.
6 a) Find the output of the following C++ code considering that thebinary file sp.dat already
exists on the hard disk with 2 records in it.
class sports
{
int id;
char sname[20],coach[20];
public:
void entry();
void show();
void writing();
void reading();
}s;
void sports::reading()
{
ifstream i;
i.open("sp.dat");
1
while(1)
{
i.read((char*)&s,sizeof(s));
if(i.eof())
break;
else
cout<<"\n"<<i.tellg();
}
i.close();
}
void main()
{
s.reading();
}
b) Given a binary file “BUS.DAT”, containing records of the following class type.
class bus
{
int bus_no;
char desc[40];
int distance; //in km
public:
void bread()
{ cin>>bus_no; gets(desc) ; cin>>distance;
}
void bdisplay()
{ cout<<bus_no; puts(desc); cout<<distance;
}

int retdist()
{
return distance;
}
};
Write a function in C++ that would read contents of file “BUS.DAT” and display and transfer
the details of those buses which travels distance more than 100 km to other file
“Temp.DAT”.

c) Write a definition for function TotalTeachers( ) in C++ to read each object of abinary file
SCHOOLS.DAT, find the total number of teachers, whose data is storedin the file and
display the same. Assume that the file SCHOOLS.DAT is createdwith the help of objects of
class SCHOOLS, which is defined below:
class SCHOOLS
{
int SCode; // School Code
char SName[20]; // School Name
int NOT; // Number of Teachers in the school
public:
void Display()
{
cout<<SCode<<"#"<<SName<<"#"<<NOT<<endl;
}
int RNOT(){return NOT;
}};
d) Find the output of the following C++ code considering that the binary fileSCHOOLS.DAT
exists on the hard disk with the following records of 10 schools ofthe class SCHOOLS as
declared in the previous question (6 c).
SCode SName NOT
1001 Brains School 100
1003 Child Life School 115
1002 Care Share School 300
1006 Educate for Life School 50
1005 Guru Shishya Sadan 195
1004 Holy Education School 140
1010 Rahmat E Talim School 95
1008 Innovate Excel School 300
1011 Premier Education School 200
1012 Uplifted Minds School 100
void main()
{
void main()
{ fstream SFIN;
SFIN.open("SCHOOLS.DAT",ios::binary|ios::in);
SCHOOLS S;
SFIN.seekg(5*sizeof(S));
SFIN.read((char*)&S, sizeof(S));
S.Display();
cout<<"Record :"<<SFIN.tellg()/sizeof(S) + 1<<endl;
SFIN.close();
}

e) Define a C++ function UPDATE(int) to increase the price by 10% of the STOCK code
passed to the function from the binary file “stock.dat” containing records having following
structure:
struct STOCK{
int code;//item code
char name[60];
float price;
};
*****************

Vous aimerez peut-être aussi