Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Q1) Write a program using classes to represent a book in a library.

Include the following members:


Data Members : Book Number, Book Name, Author, Publisher, Price,
No. of copies issued.
Member functions :
(i) To assign initial Values
(ii) To issue a book after checking for its availablity.
(iii) To return a book
(iv) To display book information

#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<stdio.h>
class book {
int bk_no;
char bk_name[20];
char author[20];
char publisher[20];
float price;
int no_of_cop;
int cop_issue;
public:
void get();
void issue_bk();
void return_bk();
void display();
};
void book::get()
{
cout<<"\n Enter Book Number : ";
cin>>bk_no;
cout<<"\n Enter Book Name : ";
gets(bk_name);
cout<<"\n Enter Name of Author :";
gets(author);
cout<<"\n Enter Name of Publisher :";
gets(publisher);
cout<<"\n Enter Price for Book : ";
cin>>price;
cout<<"\n Enter Total Number of copies :";
cin>>no_of_cop;

}
void book::issue_bk()
{ cout<<"\n How many copies do u want to issue ? ";
cin>>cop_issue;
if(no_of_cop>cop_issue)
{
cout<<"\n Book issued. ";
cop_issue++;
cout<<no_of_cop-cop_issue<<" copies left";
}
else
{
cout<<"\n Sorry...Desired number of copies are not available ";
}
}
void book::return_bk()
{
if(cop_issue<=0)
{
cout<<"\n There are no copies issued. How can you return one ?";
}
else
{
cout<<"\n Book returned.";
cop_issue--;
}
}
void book::display()
{
cout<<"\n The details of the book is as follows : ";
cout<<"\n Book Number : ";
cout<<bk_no;
cout<<"\n Book Name : ";
cout<<bk_name;
cout<<"\n Name of Author :";
cout<<author;
cout<<"\n Name of Publisher :";
cout<<publisher;
cout<<"\n Price for Book : ";
cout<<price;
cout<<"\n Total Number of copies :";
cout<<no_of_cop;
}

void main()
{
clrscr();
book bk;
bk.get();
cout<<"\n Welcome to Book Management System \n \n \n";
while(1)
{
cout<<"\n1. Issue a book\n";
cout<<"\n2. Return a book";
cout<<"\n3. Display a book";
cout<<"\n4. Exit Program";
cout<<"\n please enter your choice ";
int ch;
cin>>ch;
switch(ch)
{
case 1:bk.issue_bk();
cout<<"\n";
break;
case 2:bk.return_bk();
cout<<"\n";
break;
case 3:bk.display();
cout<<"\n";
break;
case 4:exit(0);
break;
default:cout<<"\n no option matched ";
}
}
getch();
}

Q 2) Write a program using classes to represent fixed_deposit


account of 2 customers with the following data members:Name of
the depositor, Account Number, Time Period(1or3or5 years),
Amount. The class also contains member funcyions:
(i)
To intialise data members.
(ii) Tofor withdrawl of money(after half of the time period has
passed).
(iii) To display the data mambers.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
class FD
{ char name[20];
float acc_no;
int time;
float amt;
public:
void get_detail();
void withdrawl();
void disp_detail();
};
void FD::get_detail()
{
cout<<"\n Enter the name of the depositor : ";
gets(name);
cout<<"\n Enter account number : ";
cin>>acc_no;
cout<<"\n Enter time period ( 1 or 3 or 5 years : ";
cin>>time;
cout<<"\n Enter FD amount : ";
cin>>amt;
}
void FD::disp_detail()
{
cout<<"\n Depositor Name :"<<name;
cout<<"\n Account number :"<<acc_no;
cout<<"\n Time Period :"<<time;
cout<<"\n FD amount :"<<amt;
}
void FD::withdrawl()

{
float rate=0.1, withdrew_amt,temp,t1;
temp=time/2.0;
t1= amt*rate*temp;
withdrew_amt=amt+t1;
cout<<"\n The amount withdrawl after half of the time period is :
"<<withdrew_amt;
}
void main()
{
clrscr();
FD deposit[10];
for(int i=0;i<10;i++)
{
cout<<"\n Enter Details of Depositor :";
deposit[i].get_detail();
deposit[i].disp_detail();
deposit[i].withdrawl();
cout<<endl<<endl<<endl;
}
getch();
}

Q3) Write a C++ program using class to represent batsmen in a


cricket team. Include the following members:
Data members:
First name,Last name,Runs made,Number of fours, Number of sixes.
Member Functions:
(i)
To assign the initial values.
(ii) To update runs made(It should simultaneously update fours
and sixes,if requred).
(iii) To display the batsmans information.
Make appropriate assumptions about access labels.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class batsmen {
char f_name[20];
char l_name[20];
int runs,no_of_fours, no_of_sixes;
public:
void get_detail();
void update();
void disp_detail();

};
void batsmen::get_detail()
{
cout<<"\n Enter first name of batsman : ";
gets(f_name);
cout<<"\n Enter Last name of batsman : " ;
gets(l_name);
cout<<"\n Enter runs playing at : ";
cin>>runs;
cout<<"\n Enter number of fours hit till now :";
cin>>no_of_fours;
cout<<"\n Enter number ofsixes hit till now : ";
cin>>no_of_sixes;
}
void batsmen::update()
{ int new_fours, new_sixes, new_runs;
cout<<"\n Enter new fours : ";
cin>>new_fours;
cout<<"\n enter new sixes :";
cin>>new_sixes;
new_runs=(new_fours*4)+(new_sixes*6);
cout<<"\n New runs scored : "<<new_runs;
runs=runs+new_runs;
no_of_fours+=new_fours;
no_of_sixes+=new_sixes;
}
void batsmen::disp_detail()
{ cout<<"\n Batsman name :"<<f_name<<" "<<l_name;
cout<<"\n Number of fours hit : "<<no_of_fours;
cout<<"\n Number of sixes hit : "<<no_of_sixes;
cout<<"\n Total runs scored : "<<runs;
}
void main()
{
clrscr();
cout<<"\n Welcome to India vs South Afica Airtel Series.";
batsmen bat;
bat.get_detail();
bat.update();
cout<<endl;
bat.disp_detail();

getch();
}

You might also like