You are on page 1of 12

OOP (Text book questions)

(i) Book Class:- (Library)

class Library
{
intBookNumber, No_of_copies, No_of_copies_issued;
char Book_Name [20];
char Author [20];
char Publisher [20];
float Price;
public:
void initial()
{
cout<<”\n Enter Book Number”;
cin>>BookNumber;
cout<<”\n Enter Book Name”;
gets (Book_Name);
cout<<”\n Enter Author Name”;
gets (Author);
cout<<”\n Enter Publisher”;
gets (Publisher);
cout<<”\n Enter Price”;
cin >>Price;
cout<<”\n Enter No of Copies”;
cin >> No-of-copies;
}
Void BookIssue()
{
initial();
if (No_of_copies >0)
{
cout<<”\n Enter How many copy required”;
cin>> No_of_copies_issued;
if(No_of_copies>=No_of_copies_issued)
{
No_of_copies = (No_of_copies-No_of_copies_issued)
cout<<”\n No-of-copy issued”<<No_of_copies_issued;
display()
}
else
cout<<”\n Books are not available”;
}
}
void return()
{
cout<<”\n Enter Book Number”
cin>>Book Number;
cout<<”\n Enter Book name”;
gets (Book_Name);
No_of_copies = No_of_copies + No_of_copies_issued;
cout<<”\n Book Return Successful”;
}
void Display()
{
cout<<”\n Book Number”<<BookNumber;
cout<<”\n Book Name”<<Book_Name;
cout<<”\n Author Name”<<Author;
cout<<”\n Publisher Name”<<Pubisher;
cout<<”\n Price”<<Price;
}
}

(ii) Batsmen:-
class Batsmen
{
private:
char FIRST_NAME[20];
char LAST_NAME [20];
int RUNS_MADE, NUMBER_OF_FOURS, NUMNER_OF_SIXES;
public:
void initial()
{
cout<<”\n Enter First Name”;
gets (FIRST_NAME);
cout<<”\n Enter Last Name”;
gets (LAST_NAME);
cout<<”\n Enter Runs Made”;
cin>>RUNS_MADE;
cout<<”\n Enter No-of fours & sixes”;
cin>>NO_OF_FOURS>>NO_OF_SIXES;
}
void update()
{
int New_Runs, NEW_FOURS, NEW_SXES;
int Cal_Fours, Cal-Sixes, FOURS, SIXES;
cout<<”\n Enter New Run”;
cin>>New_Run;
cout<<”\n Enter new four and sixes”;
cin>> NEW_FOURS>>NEW-SIXES;
FOURS = FOURS + NEW_FOURS;
SIXES = SIXES + NEW_SIXES;
Cal_Fours = FOURS * 4;
Cal_Sixes = SIXES * 6;
RUNS_MADE = RUMS_MADE + NEW_RUN + Cal_Fours +
Cal_Sixes;
}
void Display()
{
cout<<\n FName =”<< FIRST_NAME;
cout<<\n LName =”<< LAST_NAME;
cout<<\n No of Fours =”<< FOURS;
cout<<\n No of sixes =”<< SIXES;
cout<<\n Runs_made =”<< RUNS_MADE;
}
};
Fixed Deposit Acc
class BANKACC
{
private:
char Name [20];
int ACCNO, time;
double Amount;

public:
void initial()
{
int t;
cout<<”\n Enter Name”;
gets (name);
cout<<”\n Enter ACCNO”;
cin>> ACCNO;
cout<<”\n Enter time period”’
cin>> t;
if (t = = 3 || t = = 5)
time = t;
cout<<”\n Enter Amount:”;
cin>>Amount;
}
void withdraw()
{
double d;
int a;
cout<<”\nAmount to be withdrawl;”;
cin>> d;
cout<<”\n Enter time period after creating the ACC:”;
cin>>a;
if (a>= time/2)
{
if (d<= Amount)
Balance = Amount-d;
else
cout<<”Not Sufficient Amount”;
}
void Display()
{
cout<<”\n NAME:”<<Name;
cout<<”\n AccNo:”<<AccNo;
cout<<”\n Amount:”<<Amount;
cout<<”\n Balance:”<<Balance;
}
};
(iii) class Bowles
{
private:
charFName[20];
charLName[15];
intOverbowled, Noofmaiden, Runsgives, wickets;
public:
void Initial()
{
cout<<”Enter Fname:”;
gets(Fname);
cout<<”\n Enter LName:”;
cout<<”\nOversbowled;
cout<<”\n Noofmaidden:”;
cout<<”\n Wickets take:”;
cin>> wickets;
}
{
void update()
{
int Newover, Maidden, N_Runs, N_Wicket;
cout<<\n Enter Newover”;
cin>>Newover;
cout<<”\n Enter new maiden”;
cin>>Maidden;
cout<<”\n Enter new run give:”;
cin>>N_Runs;
cout<<”\n Enter Wickets taken:’;
cin>>N_Wicket;
Overbowled += Newover;
Noofmaidden +=Maidden;
Runsgives += N_Runs;
wickets =+ N_Wicket;
void display()
{
cout<<<”\n FName:”<<FName”;
cout<<<”\n LName:”<<LName”;
cout<<<”\n Total Over bowled:”<<Oversbowled”;
cout<<<”\n No of maiddenover:”<<Noofmaidden”;
cout<<<”\n Runsgives:”<<Runsgives”;
cout<<<”\n Wickets taken:”<<wickets”;
}
};

(iv) Bank ACC for customers:-

class BankACC
{
private:
char name [20];
intAccno;
char type [5];
double Balance;
public:
void Initial()
{
cout<<”\n Enter Name:”
gets (name);
cout<<”\n Enter Accno:”;
cin>>Accno;
cout<<”\n Acc type:”;
cin>> type;
cout<<”\n Initial Balance;
cin>>Balance;
void deposit()
{
double Deposit, New_Balance
cin>>Deposit;
New_Balance= Balance + Deposit;
void withdraw()
{
double withdraw, cur_balance;
cout<<’\n Enter Amount to be withdraw”;
cin>> withdraw;
if (Balance>1000)
{
cur_Balance= cur_Balance - withdraw;
}
else
cout<<”\n Not Sufficient Amount”;
}
void Display();
{
cout<<”\n Name:”<<Name;
cout<<”\n Accno:”<<Accno;
cout<<”\n Balance:”<<Balance;
cout<<”\n Balance after deposit Deposit:”<<New_Balance;
cout<<”\n WithdrawlAmt:”<<Withdrawl;
cout<<”\n Current Balance:”<<cur_Balance;
}
};

circular class (Write a program)

#include<iostream.h>
#include<conio.h>
class circle
{
private:
float radious, x, y;
public:
void get_radious (float r)
{
radious=r;
}
void get_xycoor (float a, float b)
{
x=a;
x=b;
}
void area()
{
cout<<\n Area of circle”<<3.14 x radius * radius;
}
void Circum()
{
cout<<\n Circumference”<< 2 * 3.14 * radius;
}
};
void main()
{
clrscr();
float rad;
cout<<\n Enter radius”;
cin>>rad;
c1. get-radius (rad);
c2. area();
c1. circum();
getch()
}

(v) Vector:

class vector
{
intArr [10]
public:
vector()
{
for (int I = 0; i<10; i++)
Arr [i] = 0;
}
vector (int a [*])
{
for (int i= 0; i<10; i++ )
{
Arr [i] = a[i];
}
}
void create ()
{
for (int i=0; i<10; i++)
{
cout<<”\n Enter an element:”;
cin>>Arr [1];
}
}
void modify (int pos, int cle)
{
Arr [pos] = ele;
}
void Display()
{
cout<<”\n Element of the array are:”;
for (int i=0; i<10; i++)
{
cout<<Arr [i]<<” ”;
}
}
int Disp_large()
{
Int lar = Arr [0];
for (int i = 1; i<10; i++)
{
it (lar<Arr [i])
{
lar = Arr [i];
}
}
}
return lar;
}
};
void main()
{
vector v1;
v1.create();
v1. Display();
int max = v1.disp_lar();
cout<<”\n Maximum is” <<max;
}

(vi) Ticket Selling Booth:

class ticket
{
int nops;
float amount;
public:
void Record();
{
nops = 0;
amount = 0.0;
}
void Increment()
{
Int i;
while (i != -1)
{
cout<<”\n Enter No of tickets bought”;
cin>>i;
nops = nops + i;
}
void Display()
{
cout<<”\n No of People entered”<<nops
cout<<”\n Total Amount:”<<nops*2.5;
}
};
void main()
{
Ticket T;
T. Record();
T. Increment();
T. Display();
}

(vii) Clothing:
class clothing
{
char code [25];
char Type [15];
int size;
char Material [15];
float Price;
void Calc-Price();
{
if (strcmp (Material, “COTTON”)==0)
{
if (strcmp (Type, “TROUSER”) = = 0)
price = 1500;
if (strcmp (Type, “shirt”) = = 0)
price = 1200;
}
else
{
if(strcmp (Type, “TROUSER”) = = 0)
price = 1500-1500*0.25;
elseif (strcmp (Type, “shirt”) = = 0)
price=1200-1200*0.25;
}
}
public:
clothing()
{
strcpy (code, “NOT ASSIGNED”);
strcpy (Type, “NOT ASSIGNED”);
size = 0;
price=0;
}
void Enter()
{
cout<<”\n Enter code”;
gets (Code);
cout<<”\n Enter type”;
gets (Type);
cout<<”\n Enter Size”;
cin>>SIZE;
cout<<”\n Enter Material”;
gets (Material);
calc_Price();
}
void SHOW()
{
cout<<”\n Code:”<< Code;
cout<<”\n Type:”<<Type;
cout<<”\n Size:”<<Size;
cout<<”\n Material:”<<Material;
cout<<”\n Price:”<<Price;
}
};

(viii) CABS:
class CABS
{
int CNO;
char Type;
int PKM;
int DIST;
public:
CABS()
{
TYPE = ‘A’;
CNO = 1111;
}
void charge()
{
if (Type = = ‘A’)
PKM = 25;
else if (Type = = ‘B’)
PKM = 20;
else if (Type = = ‘C’)
PKM = 25;
}
void Register()
{
cout<<”\n Enter Cab. No & Type:”;
cin>>CNO>>Type;
charges();
}
void Showcab()
{
cout<<”\n Enter Distance”;
cin>>Dist;
cout<<”\n Enter Cab. No:”<<CNO;
cout<<”\n Type:”<<Type;
cout<<”\n PKM charges:”<<PKM * DISTANCE;
}
};

Q.6. BUS
class BUS
{
private:
int BUSNO;
char From [20];
char To [20];
char Type [10];
int Distance;
float Fare;
public:
BUS()
{
Type = 0;
Fare = 500;
}
void CalcFare()
{
if (Type = = ‘0’)
{
Fare = Distance * 15;
else if (Type = = ‘E’)
Fare = DISTANCE *20;
else if (Type = = ‘L’)
Fare = DISTANCE*24;
}
}
void Allocate()
{
cout<<”\n Enter BUSNO:”;
cin>>BUSNO;
cout<<”\n Enter From:”;
gets(From);
cout<<”\n Enter TO:”;
gets (TO);
cout<<”\n Enter Type:”;
cin>> Type;
CalcFare ();
}
void show()
{
cout<<”BUS NO:”<<BUSNO;
cout<<”From”<<From;
cout<<”To:”<<To;
cout<<”Type:”<<Type;
cout<<”Distance:”<<Distance;
cout<<”Fare:”<<Fare;
}
}

Q.7 Tour:
class Tour
{
char Tcode[15];
int NoofAdults;
int NoofKids;
int Kilometers;
float TotalFare;
public:
Tour()
{
strcpy (Tcode, “NULL”);
NoofAdults = 0;
NoofKids = 0;
Kilometers = 0;
Totalfare = 0;
}
void Assignfare()
{
float TotalFare = 0;
if (kilometres.=1000)
TotalFare = NoofAdulta*500+NoofKilometer*250;
else if (Kilometer>=500 && Kilometer<1000)
TotalFare = NoofAdult *300+Noofkids*150;
else
Fare = NoofAdults*200+NoofKids*100;
TotalFare = Fare;
}
voidEnterTour()
{
cout<<”\n Enter Tcode”;
gets (Tcode);
cout<<”\n Enter NoofAdults & NoofKids”;
cin>>NoofAdults>>NoofKids;
cout<<”\n Enter Kilometers”;
cin>>Kilometers;
Assignfare();
}
voidShowTour()
{
cout<<”\n Travel Code:”<<Tcode;
cout<<”\n No of Adults:”<<No of Adults;
cout<<”\n No of Kids:”<<No of Kids;
cout<<”\n Distance:”<<Distance;
cout<<”\n Total fare:”<<fare;
}
};

You might also like