Professional Documents
Culture Documents
C++ Sample Programs
C++ Sample Programs
#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();
}
{
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();
}
#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();
}