Page 126 - C++
P. 126
busno integer to store bus number
from string to store starting place
to string to store ending place
type to store BUS type ‘O’ for ordinary
distance integer to store distance in kilometre
fare integer to store bus fare
Public members:
➢ A constructor function to initialize type as ‘O’ and distance as 500
➢ A function calcfare() to calculate fare as per the following criteria:
Type fare per kilometre
‘O’ Rs 15/
‘E’ Rs 20/
‘L’ Rs 24/
➢ A function allocate() to allow user to enter values for bus number, from, to,
type and distance. Also this function should invoke calcfare() to calculate
fare.
➢ A function show() to display the content of all the data members on
screen.
Ans: class BUS
{
int busno;
char from[20], to[20], type;
inr distance, fare;
public:
BUS()
{
type=’O’,
distance=500;
}
void calcfare();
void allocate();
void show();
};
void BUS::allocate()
{
XII / Comp. Sc. Page 5 of 17