Chap - OPPS CONCEPT
Chap - OPPS CONCEPT
Concept of OOP
Exam Practice
Very Short Answer Type Questions [1 Mark]
Question 1:
How are the object‟s behaviour and object‟s characteristics represented in
OOP?
Answer:
An object‟s behaviours and object‟s characteristics are represented in terms of
member functions of a class and data members of a class.
Question 2:
Why function overloading is used?
Answer:
Function overloading plays very important role to implement polymorphism. It
is also used to make the program run faster and reduces the number of
comparison in a program.
Question 3:
When do you think function overloading be used?
Answer:
Function overloading is used when a function is required to perform for
alternatives argument types and there is a definite way of optimising the
function for the argument type. In such kind of case, function overloading
should be used.
Question 4:
Is this possible to declare two functions with same name and same argument
but different return type in C++?
Answer:
No, it is not possible to declare two functions with same name and same
argument but different return type in C++, because the control will be confused
at the time of calling which of these function will be executed first.
Question 5:
Which function is called during each function call in the program given below?
int x=20;
int a=sum(x); //Call 1
float b=sum(x); //Call 2
double c=sum(x); //Call 3
getch();
Question 6:
How are abstraction and encapsulation interrelated?
Answer:
Encapsulation means binding of data members and member functions (which
operates on the data) into a single unit and ensure that only important features
get represented without representing background details, i.e. called
abstraction. Encapsulation is a way to implement data abstraction. Therefore,
both are interrelated.
Question 7:
Inheritance allows code reusability in OOP. Explain how?
Answer:
Inheritance allows us to add additional features to an existing class without
modifying it. Thus, the class can be raised by inheriting it. We look for a class
that can be reused in our program. If such a class exists, we simple use it or
inherit it. Thus, inheritance allows code reusability.
Question 8:
In function overloading how is matching done?
Answer:
In function overloading, the matching is done on the basis of number of
argument and types of argument. If two functions have same argument, then
matching is done on the basis of sequence or type of arguments. There is no
rule of matching on the basis of return type.
Question 9:
How an object differs from a program module?
Answer:
object is a real world entity that consists of both data and function and this
integrated unit provides the necessary behaviour expected from the object.
While a program module is a piece of code, which performs a particular
function or set of functions.
Question 10:
Write declaration for two overloaded functions named bar(). They both return
float type. The first takes one argument of type char and second takes two
argument of type char. If this is impossible, explain why?
Answer:
Declaration of function is possible with overloading concept: float bar(char ch)
Question 11:
Why are the functions arguments called as “Signature”?
Answer:
The arguments differentiate functions with the same name. The name alone
cannot identify a unique function. However, the name and its arguments
(signature) will uniquely identify function. In real life, also we can see this
happening. In a class, two students with same name can be identified by their
signature.
Question 12:
Does the return type of a function also help in finding the best match in
function overloading?
Answer:
No, compiler does not have any criteria to check function match using return
type of a function. Two functions can have same name and return type in
function overloading. If the signatures of two function are same but different
return type, it is not allowed by the compiler.
Question 13:
To relate classes with real world, if book is a class then give example of its
objects.
Answer:
If „book‟ is a class then the objects of this class are Hindi, English, Social
science, Computer science, etc.
Question 14:
Name the features by which classes acquire the properties of other classes.
Answer:
Inheritance is the feature by which classes acquire the properties of other
classes.
Question 15:
How does a compiler decide as to which function should be invoked when there
are many functions with the same name?
Answer:
The compiler differentiates between functions with same name by the number
of arguments and the data type of arguments that are given with function
declaration and the function call.
Question 17:
With the multiple definition of single function name, what makes them
significantly different?
Answer:
With the multiple definition of single function name, the function signature
makes them significantly different. The function signature can be recognised by
the list of argument. Either number of argument may be differ or types of
argument may differ in function declaration. Another difference is that the
sequence of argument type may differ. So in short, we can say that function‟s
signature makes them significantly different in making function with same
name with multiple definition.
Question 18:
Why do you think function overloading must be a part of an OOP?
Answer:
A function overloading must be a part of an OOP because it is a feature that
implements the polymorphism in object oriented programming, i.e. the ability
of an object to behave differently in different circumstance can effectively be
implemented in programming through overloading.
Also, with the function overloading, the programmer is relieved from the
burden of choosing right function for a given set of values. This important
responsibility is carried out by the compiler, when function is overloaded.
Question 19:
How does a class enforce data hiding, abstraction and encapsulation?
Answer:
Question 20:
Write a program using overloaded function to compute the area of rectangle
and area of triangle using hero‟s formula.
Answer:
A program using overloaded function to compute the area of rectangle and area
of triangle using hero‟s formula.
#include<iostream.h>
#include<conio.h>
#includeCmath.h>
double area(int x, int y);
double area(int x, int y, int z);
void main()
{
int A,B,a,b,c;
double AREA;
clrscr();
cout<<"Enter the side of rectangle";
cin>>A>>B;
AREA=area(A,B);
cout<<"\nArea of rectangle="<<AREA;
cout<<"\nEnter the side of triangle";
cin>>a>>b>>c;
AREA=area(a,b,c);
cout<<”\nArea of triangle="<<AREA;
getch();
}
double area(int x ,int y)
{
return (x*y);
}
double area(int x, int y, int z)
{
float s=((x+y+z)/2);
return(sqrt(s*(s-x)*(s-y)*(s-z)));
Question 21:
How are large problems divided in object oriented programs? Give an example.
Answer:
In object oriented programming, large programs are divided into real world
entity called object, which are consist of function and the data on which these
functions have to be performed.
e.g. if a function has to be written to calculate the sum of two numbers then
the entity will include the data, whose sum has to be calculated and also
include the functions to calculate the sum and display the result.
Question 22:
How concrete class is differ from abstract class?
Answer:
Abstract Class and Concrete Class
An abstract class is one which cannot be used to create objects and is designed
only to work as a base class. Only pointers or reference to this type of class can
be declared.
On the other hand, the classes which are intended for the creation of objects or
instances are called instance or concrete classes.
e.g. automobiles is an abstract class. Because, in real world there exists an
instance of car, truck, etc., all these are child classes of class automobiles. But
no instance of automobiles class can exist. So, automobiles is an abstract class
and car and truck are concrete classes.
Question 23:
Why data encapsulation is so important in C++?
Answer:
Data encapsulation plays very important role in C++ because it ties data and
function into a single unit so that data cannot move freely from one program to
another and data cannot be accidently corrupted by the external world. It
ensure that changes to the data and functions of an object can be made
without affecting other objects. Objects are independent of each other.
Therefore, each object can be studied properly for better understanding of the
design, encapsulation links together the state and the behaviour of an object.
Question 24:
What will be the output of the following program?
#include<iostream.h>
#include<conio.h>
int volume(int a);
double volume(float r.int h);
int volume(int l.int b.int h);
void main()
{
int a , l , b,h;
float r;
clrscr();
cout<<"Enter the side of cube
cin>>a;
cout<<"Enter the radius
and height of cylinder ”;
cin>>r>>h;
cout<<"\nEnter the side of
rectangular cube\n";
cin>>l>>b>>h;
Question 26:
What do you understand by function overloading? Give an example illustrating
its use in a C++ program. All India 2011
or
What is function overloading? Write an example using C++ to illustrate the
concept of function overloading. All India 2014
Answer:
Function overloading
Function overloading is the process of using the same name for two or more
functions. Each redefinition of a function must use different type of
parameters, sequence of parameters or number of parameters.
The number, type or sequence of parameters for a function is called the
function signature. When we have multiple functions with the same name, the
compiler identifies the function based on the parameters to the function. This
is a very useful feature as illustrated in the following program. The function
area() displays the area of different shapes.
#include<iostream.h>
#include<conio. h>
#include<math.h>
int sroot(int x);
float sroot(float y);
Question 27:
What do you understand by polymorphism? Give an example, illustrating its
use in a C++ program.
Answer:
e.g. the function area( ) will work differently for different shapes like circle,
triangle, rectangle, etc. i.e. function area( ) exhibits polymorphic behaviour.
Chapterwise Question Bank CBSE Class 12 Computer Science (C++) - Object
Oriented Programming-27 Delhi 2010
e.g.
#include<iostream. h>
#includeCconio.h>
#include<math.h>
double area(int x);
double area(int x,int y);
double area(int x,int y.int z); void main()
{
int A,B,a,b,c,r;
double AREA;
clrscr();
cout<<"\nEnter the radius of circle cin >> r;
AREA=area(r);
cout<<"\nArea of circle="<<AREA; cout<<"\nEnter the side of rectangle ";
cin>>A>>B;
AREA=area(A,B);
cout<<"\nArea of rectangle="<<AREA;
cout<<”\nEnter the side of triangle
cin>>a>>b>>c;
AREA=area(a , b,c);
cout<<"\nArea of tri angl e=''<<AREA;
getch();
}
double area(int x)
{
return ((22*x*x)/7);
}
double area(int x,int y)
{
return (x*y);
}
double areaCint x,int y,int z)
{
float s=((x+y+z)/2);
return(sqrt(s*(s-x)*(s-y)*(s-z)));
}
Question 28:
Write the output of the following C++ code. Also, write the name of feature of
object oriented programming used in the following program jointly illustrated
by the functions [I] to [IV], Delhi 2011
#include<iostream.h>
void Print() //Function[I]
{
for(int K=1; K<=60; K++)
cout<<”-"; cout<<endl ;
}
void Print(int N) //Function[II]
{
for(K=1; K<=N; K++)
cout<<"*"; cout<<endl ;
}
void Print(int A, int B) //Function[III]
{
for(K=1; K<=B; K++)
cout<<A*K; cout<<endl ;
}
void Print(char T,int N) //Function[IV]
{
for(K=l; K<=N; K++) cout<<T; cout<<endl;
}
void main()
{
int U=9, V=4, W=3;
char C='@';
Print(C,V);
Print(U.W);
}
Answer:
Output
@@@@
91827
In the above example, the function overloading concept is used from function
[I] to [IV].
Topic – 2
Implementation of OOPs Concept in C++
Exam Practice
Short Answer Type Questions [2 Marks]
Question 1:
What is the significance of (::) scope resolution operator?
Answer:
Member functions can be defined within the class definition or separately using
scope resolution operator(::). Scope resolution operator specifies that the scope
of the function is restricted to the class_name.
#include<iostream.h>
class Box
{
double length;
double breadth;
double height;
public:
double getVolume(void);
};
double Box :: getVolume(void)
{
return length*breadth*height;
}
Question 2:
What is the difference between a struct and a class in C++?
Answer:
The struct default access type is public. A struct should typically be used for
grouping data. The class default access type is private and the default mode for
inheritance is private.
A class should be used for grouping data and methods that operate on that
data.
In short, the convention is to use struct when the purpose is to group data and
use classes, when we require data abstraction and perhaps inheritance. In
C++, structures and classes are passed by value, unless explicitly de-
referenced. In other languages, classes and structures may have distinct
semantics, i.e. objects (instances of classes) may be passed by reference and
structures may be passed by value.
Technically, there are only two differences between classes and structures:
Question 3:
Rewrite the following program after removing the syntactical errors (if any).
Underline each corrections. Delhi 2012
#include<iostream.h>
class Product
{
long PId.Qty;
public:
void Purchase
{
cin>>PId>>Qty;
}
void sale()
{
cout<<setw(5)<<PId<<"0ld: ”<<Qty<<endl;
cout<<”New:”<<--Qty<<endl;
}
};
void main()
{
Product P;
Purchase();
P.Sale();
P.Sale();
}
Answer:
#include<iostream.h>
# include<iomanip.h>
class Product
{
long PId.Qty;
public:
void Purchase()
{
cin>>PId>>Qty;
}
void Sale()
{
cout<<setw(5)<<PId<<''0ld: "<<Qty<<endl;
cout<<"New:"<<--Qty<<endl;
#include<iostream.h>
class Item
{
long IId, Qty;
public:
void Purchase
{
cin>>IId>>Qty ;
}
void Sale()
{
cout<<setw(5)<<IId<<"old:"<<Qty<<endl;
cout<<"New:"<<--Qty<<endl;
}
};
void main()
{
Item I;
Purchase();
I .Sale();
I .Sale()
}
Answer:
#include<iostream.h>
#include<iomanip.h>
class Item
{
long IId, Qty;
public:
void Purchase()
{
ci n>>IId>>Qty ;
#include<iostream.h>
class FLIGHT
{
long FlightCode;
char Description(25);
public;
void AddInfo()
{
cin>>FlightCode;
gets(Description);
}
void ShowInfo()
{
cout<<FlightCode<<":";
<<Description<<endl ;
}
};
void main()
{
Flight F;
AddInfo.F();
ShowInfo.F();
Answer:
#include<iostream.h>
//# is required before include
#include<stdio.h> //for gets() function
#include<iostrearn.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;
T.Get();
#include<iostream.h>
#include<stdio.h>
class Transport
{
char Model[20];
char Name[20];
public:
void Get()
{
gets(Model);
gets(Name);
}
void Show()
{
cout<<Model<<endl ;
puts(Name);
}
}:
void main()
{
Transport T;
T.Get();
T.Show():
}
Question 7:
Rewrite the folio wing C++program code after removing the syntax error(s) (if
any). Underline each correction.
# include<iostream.h>
Class student
{
int roll No:
char Name;
Public
void get Data();
{
cout<<"RollNo = "<<rollNo;
cout<<"Name = "<<Name;
}
void setdata();
{
cin>>roll No;
#include<iostream. h>
class student /* class keyword should be small and first letter
of class will be capital letter according to main ()*/
{
int roll No;
char Name[20]:
// the string must have an array
public:
// public keyword will be small letter
//and: should be written after public
void getdata()
{
cout<<"Roll No="<<roll No:
cout<<"Name=''<<Name;
}
void setdata()
{
cin>>roll No;
cin>>Name;
}
};
void main()
{
student S1;
SI.getdata();
Sl.setdata();
}
Question 8:
How are objects implemented in C++?
Answer:
Objects are implemented in C++ as follows:
(i) The properties/characteristics are implemented by the data members or
member variables.
(ii) Behaviour of an object is determined by its member function or method.
Question 9:
What do you understand by data encapsulation and data hiding? Also, give an
example in C++ to illustrate both. All India 2010
Answer:
When member data and member function are binded into a single unit then
the data is not accessible to the outside world and only those functions, which
are wrapped in that class can access it.
These functions are referred to as member functions and also provide the
interface between the object‟s data and the program. This insulation of data
from direct access by the program is called data hiding or information hiding.
In other words, we can say that encapsulation is implemented through data
hiding.
Note Encapsulation is implemented in C++ with the help of classes. Data
hiding is implemented in C++ with the help of private and protected keywords.
Chapterwise Question Bank CBSE Class 12 Computer Science (C++) - Object
Oriented Programming-1
Question 10:
What is the relationship between class and object? Illustrate with a suitable
example. Delhi 2013 C
Answer:
A class cannot be assigned to memory until the object is created. An object is a
class variable, i.e. class is a data type and object is a variable of class type.
Without class, object instantiation is not possible. Hence, we can say that an
object does not exist without class and a class has no value without object. So,
they are related to each other,
e.g. A class Box is given as follows:
class Box
{
int height;
int width;
int length;
public:
double volume (int h , int w, int l)
{
height = h;
width = w;
length = l ;
return (height * width * length);
}
};
The above class will not assigned memory until the object is instantiated.
The object instantiation is given below:
Question 11:
Write a class in C++ that will implement the concept of function overloading
techniques to find the area of rectangle and circle.
Answer:
class Shape
{
double area;
publlc:
double area(int r)
{
area = 3.146*r*r;
return(area);
}
double area(int 1, int w)
{
area = 1 * w;
return (area);
}
}:
Question 12:
How does object occupy memory in C++?
Answer:
The member functions are created and placed in the memory space only once
when they are defined as a part of a class specification. Since, all the objects
belonging to that class use the same member functions, no separate space is
allocated for member functions when the objects are created.
Space for member variables is allocated separately for each objects. Separate
memory locations for the objects are essential, because the member variables
will hold different data values for different objects.
This is shown in figure:
Chapterwise Question Bank CBSE Class 12 Computer Science (C++) - Object
Oriented Programming-t2-12
Question 13:
When object is used as function argument, then how call by value is differ from
call by reference?
Answer:
Difference between call by value and call by reference, when object is used as a
function argument are as follows:
Chapterwise Question Bank CBSE Class 12 Computer Science (C++) - Object
Oriented Programming-3
classname ArrayofObjectName[size];
consider a class student
Question 15:
Rewrite the following program after removing the syntactical error(s) (if any).
Underline each correction. Delhi 2012C
#include<iostream.h>
#include<stdio.h>
class OFFER
{
int Offerld;
char Description[80];
Void show
{
cout<<offerId<<”:"<<Descri pti on ;
cout<<endl;
}
public
void Enter
{
cin>>0fferld; gets>>Description;
}
};
void main()
{
Offer obj;
obj . Enter();
#includeCiostream.h>
#include<stdio.h>
class OFFER
{
int Offerld:
char Description[80];
void show()
{
cout<<0fferId<<":”<<Description<<endl;
}
public:
void Enter()
{
cin>>0fferId; gets(Description);
}
};
void main()
{
OFFER obj;
obj . Enter();
//obi.show():
//show cannot be called because in
//class declared as private
{
Question 16:
Difference between members, which are presented within the private visibility
mode with those which are presented within the public visibility mode.
or
Differentiate between public and private visibility modes in context of object
oriented programming using a suitable example. Delhi 2011,2008
Answer:
A member declared as private remains hidden from outside world and it can
only be accessed by the member function of the class.
A member declared as public is made available to the outside world, i.e. it can
be accessed by any function, any expression in the program but only by using
an object of the same class type.
Question 17:
What do you understand by a member function? How does a member function
differ from an ordinary function?
Answer:
Question 18:
Rewrite the following C++ program code after
removing the syntax error(s) (if any). Underline each correction. All India 2010
include<iostream.h>
class TRAIN
{
long int TrainNo;
char Description[25];
public
void Entry()
{
cin>>TrainNo;
gets(Description);
}
void Display()
{
cout<<T rainNo<<":"
<<Description<<endl;
}
};
void main()
{
TRAIN T;
Entry .T();
Display.T();
}
Answer:
#include<iostream.h>
//# sign will before include.
#include<stdio.h>
//should be include this for gets()function class TRAIN
{
long int TrainNo;
char Description[25];
public:
//: sign is required after public void Entry()
{
FType Sticker
Vegetarian GREEN
Contains Egg YELLOW
Non-vegetarian RED
Public members
• A function GetFoodf) to allow user to enter values for Food Code, Food, FType
and call function GetSticker() to assign Sticker.
• A function ShowFood() to allow user to view the content of all the data
members.
Answer:
class RESTRA
{
int FoodCode;
char Food[30], FType[20], Sticker[20]; void GetSticker()
{
Answer:
Answer:
class Applicant
{
class ITEM
int Code;
char Iname[20];
float Price;
int Qty;
float Offer;
void Getoffer();
public:
void GetStock()
{
cout<<"Enter the values of code, Item name, Price and Quantity”;
cin>>Code;
gets(Iname);
cin>>Price>>Qty;
Getoffer();
}
void Showitem()
}
};
cout<<Code<<endl<<Iname<<endl <<Price<<endl<<Qty<<endl<<0ffer;
}
};
void ITEM Getoffer()
{
if(Qty <= 50)
Offer = 0;
else if(Qty <= 100)
Offer = 5;
else
Offer = 10;
}
Question 23:
Define a class STOCK in C++ with the following specification: All India 2010
Private members
• ICode of type integer (Item Code)
• Item of type string (Item Name)
• Price of type float(Price of each item)
• Qty of type integer(Quantity in stock)
• Discount of type float (Discount percentage on the item)
• A member function FindDisc() to calculate discount percentage as follows:
Chapterwise Question Bank CBSE Class 12 Computer Science (C++) - Object
Oriented Programming-7
Public members
Answer:
class STOCK
{
int I Code;
char Item[20];
float Price;
int Qty;
float Discount;
void FindDisc();
public:
void Buy()
{
cout<<"Enter Item code,Item name, Price and Quantity”;
cin>>ICode; gets(Item);
cin>>Price>>Qty;
FindDisc():
}
void ShowAll()
{
cout<<ICode<<endl<<Item<<endl<<Price<<endl<<Qty<<endl<<Discount;
}
};
void STOCK :: FindDisc()
{
if(Qty <= 50)
Discount = 0;
else if(Qty <= 100)
Discount = 5;
else
Discount = 10;
}
Question 24:
Define a class RESORT in C++ with the following specification: Delhi 2009
Private members
• Rno Data member to store room number
• 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() Function to calculate and return amount as days
* charges and if the value of days
* charges is more than 11000, then as 1,02
Answer:
class RESORT
{
int Rno;
char Name[30];
float Charges;
int Days;
float COMPUTE()
{
float temp = Days*Charges;
if(temp > 11000)
return(1.02 * temp);
return temp;
{
public:
void Getinfo()
{
cout<<”Enter the room number";
cin>>Rno;
cout<<"Enter the customer name";
gets(Name);
cout<<"Enter the room charges per day";
cin>>Charges;
cout<<"Enter number of days stayed by customer";
cin>>Days;
}
void Dispinfo()
{
cout<<"Room number:"<<Rno<<endl ;
cout<<"Customer name;";
puts(Name);
cout<<"Charges per day:"
<<Charges<<endl
cout<<"Number of days stayed by customer"<<Days<<endl
cout<<"Total charges of customer"
<<COMPUTE()
}
};
Question 25:
Answer:
class HOTEL
{
int Rno,NOD;
char Name[30];
float Tariff;
float CALC()
{
float temp = NOD*Tariff;
if(temp > 10000)
return(1.05*temp);
}
cout<<"Enter the room number";
cin>>Rno;
cout<<"Enter the customer name";
gets(Name);
cout<<”Enter the room charges per day";
cin>>Tariff;
cout<<"Enter number of days stayed by customer.";
cin>>NOD;
}
void Checkout()
{
cout<<"Room number"<<Rno<<endl ;
cout<<"Customer name";
puts(Name);
cout<<"Charges per day:"<<Tariff<<endl ;
cout<<"Number of days stayed by customer:"<<N0D<<endl;
cout<<"Total charges of customer:"<<CALC();
}
class HOUSING
{
int REG_N0;
char NAME[31];
char TYPE;
float COST; public:
void Read_Data()
{
cout<<"\nEnter the house number:";
cin>>REG_N0;
cout<<"\nEnter the house name:";
gets(NAME);
cout<<"\nEnter the house type:";
cin > >TY P E;
cout<<"\nEnter the house cost:";
cin>>C0ST;
}
void Display()
{
cout<<"\nThe number of the house"
<<REG_N0;
cout<<"\nThe name of the house”
<<NAME;
cout<<"\nThe type of the house"
<<TYPE;
cout<<"\nThe cost of the house"
<<C0ST;
}
Answer:
class BOOK
{
int B00K_N0;
char B00K_TITLE[20];
float PRICE;
float T0TAL_C0ST(int N)
{
float TOTAL;
TOTAL=N * PRICE;
return TOTAL;
}
public:
void INPUT()
}
Answer:
class Bank
{
char name[15];
int acc_no; char acc_type;
float bal_amount;
public:
void readData()
{
cout<<"\nEnter the name:";
gets(name);
cout<<"\nEnter the account number:";
cin>>acc_no;
cout<<"\nEnter the account type:";
cin>>acc_type;
cout<<"\nEnter the balance amount";
cin>>bal_amount;
Answer:
class WORKER
{
int wno;
char wname[25];
float hrwrk,wgrate;
float totwage;
float calcwg()
{
return(hrwrk*wgrate);
}
public;
void In_data()
{
cout<<"\nEnter worker number";
cout<<"\nName,hours worked &
wage rate";
cin>>wno; gets(wname);
void Out_data()
cout<<"\nThe worker number:”<<wno;
cout<<"\nName of the worker:"
<<wname;
cout<<"\nNumber of hours worked
cout<<hrwrk;
cout<<"\nWage rate of the worker:";
cout<<wgrate;
cout<<"\nTotal wages of the worker:";
cout<<totwage;
cin>>hrwrk>>wgrate;
totwage = calcwg();
}
};
Question 30:
Define a class STUDENT with the following specifications:
Private members
• Admno integer
• Sname 20 character
• English float
• Math float
• Science float
Answer:
class STUDENT
{
int Admno;
char Sname[20];
float English,Math,Science,Total;
float Ctotal()
{
return(English+Math+Science);
}
public:
void Takedata()
{
cout<<"\nEnter the admission
number:";
cout<<"\nName of the student:";
cin>>Admno;
gets(Sname);
cout<<"\nEnter marks of E, M & S:";
cin>>English>>Math>>Science;
Total=Ctotal();
}
void Showdata()
{
cout<<"\nAdmission number of the student:";
cout<<Admno;
cout<<"\n The Name of the student:";
cout<<Sname;
cout<<"\nMarks are E, M & S...";
cout<<English<<"\t”<<Math<<"\t";
cout<<Science<<"\n";
cout<<"\nTotal marks of student:";
cout<<\nTotal;
}
};
Question 31:
Answer:
class EMPLOYEE
//class and function of EMPLOYEE class
{
int empno;
char ename[20];
float basic,hra,da,netpay;
float calculate()
{
return (basic+hra+da);
}
public:
void havedata()
{
cout<<"\nEnter the employee
number and name:”;
cin>>empno;
gets(ename);
cout<<”\nEnter basic,hra ,da";
cin>>basic>>hra>>da;
netpay = calculate();
}
void display()
{
cout<<"\nThe employee number of the employee"<<empno;
cout<<"\nThe name of the
employee"<<ename; cout<<"\nbasic, hra and da are...”;
cout<<basic<<”\t"<<hra<<"\t”
<<da<<”\n";
cout<<"\nTotal pay of the
Answer:
class Seminar
{
long Seminarld;
char Topic[20], VenueLocation[20];
float Fee;
void CalcFee()
{
if(strcmp(VenueLocation,
"Outdoor”)==0)
Fee=5000;
else if(strcmp(VenueLocation,
"Indoor Non-Ac")==0)
Fee=6500;
else if(strcmp(VenueLocation,
"Indoor Ac")==0)
Fee=7500;
}
public:
void Register( )
{
cout<<"Enter Seminar Id"; cin>>Seminarld;
cout<<"Enter Topic"; getsdopi c);
cout<<"Enter Venue Location";
gets(VenueLocation);
CalcFee( );
Answer:
class Directory
{
char Docunames[10][25];
long Freespace;
long Occupied;
public:
void Newdocumentry();
long Retfreespace();
void Showfiles();
};
void Directory :: Newdocumentry()
{
cout<<"Enter any 10 file names:";
for(int i=0;i<=9;i++)
{
cout<<"Enter the"<<i+l<<"file name:"; gets(Docunames[i]);
}
cout<<"Enter the Available
Spacedn Kilobytes):”;
Answer:
class COMPETITION
{
int event_no;
char description[30];
int score;
char qualified;
public:
void Input()
{
cout<<"Enter event no:";
cin>>event_no;
Answer:
class Flight
{
int FlightNumber;
char Destination[20];
float Distance;
float Fuel;
void Cal Fuel ()
{