Sei sulla pagina 1di 17

Code for Program of maintaining banking account information system

using inheritance in C++ Programming


#include <iostream.h>
#include <conio.h>
class account
{
char cust_name[20];
int acc_no;
char acc_type[20];
public:
void get_accinfo()
{
cout<<"\n\nEnter Customer Name :- ";
cin>>cust_name;
cout<<"Enter Account Number :- ";
cin>>acc_no;
cout<<"Enter Account Type :- ";
cin>>acc_type;
}
void display_accinfo()
{
cout<<"\n\nCustomer Name :- "<<cust_name;
cout<<"\nAccount Number :- "<<acc_no;
cout<<"\nAccount Type :- "<<acc_type;
}
};
class cur_acct : public account
{
staticfloat balance;
public:
void disp_currbal()
{
cout<<"\nBalance :- "<<balance;
}
void deposit_currbal()
{
float deposit;
cout<<"\nEnter amount to Deposit :- ";
cin>>deposit;
balance = balance + deposit;
}
void withdraw_currbal()
{
float penalty,withdraw;
cout<<"\n\nBalance :- "<<balance;
cout<<"\nEnter amount to be withdraw :-";
cin>>withdraw;
balance=balance-withdraw;
if(balance < 500)
{
penalty=(500-balance)/10;
balance=balance-penalty;
cout<<"\nBalance after deducting penalty : "<<balance;
}
elseif(withdraw > balance)

{
cout<<"\n\nYou have to take permission for Bank Overdraft Facility\n";
balance=balance+withdraw;
}
else
cout<<"\nAfter Withdrawl your Balance revels : "<<balance;
}
};
class sav_acct : public account
{
staticfloat savbal;
public:
void disp_savbal()
{
cout<<"\nBalance :- "<<savbal;
}
void deposit_savbal()
{
float deposit,interest;
cout<<"\nEnter amount to Deposit :- ";
cin>>deposit;
savbal = savbal + deposit;
interest=(savbal*2)/100;
savbal=savbal+interest;
}
void withdraw_savbal()
{
float withdraw;
cout<<"\nBalance :- "<<savbal;
cout<<"\nEnter amount to be withdraw :-";
cin>>withdraw;
savbal=savbal-withdraw;
if(withdraw > savbal)
{
cout<<"\n\nYou have to take permission for Bank Overdraft Facility\n";
savbal=savbal+withdraw;
}
else
cout<<"\nAfter Withdrawl your Balance revels : "<<savbal;
}
};
float cur_acct :: balance;
float sav_acct :: savbal;
void main()
{
clrscr();
cur_acct c1;
sav_acct s1;
cout<<"\nEnter S for saving customer and C for current a/c customer\n\n";
char type;
cin>>type;
int choice;
if(type=='s' || type=='S')
{

s1.get_accinfo();
while(1)
{
clrscr();
cout<<"\nChoose Your Choice\n";
cout<<"1)
Deposit\n";
cout<<"2)
Withdraw\n";
cout<<"3)
Display Balance\n";
cout<<"4)
Display with full Details\n";
cout<<"5)
Exit\n";
cout<<"6)
Choose Your choice:-";
cin>>choice;
switch(choice)
{
case 1 : s1.deposit_savbal();
getch();
break;
case 2 : s1.withdraw_savbal();
getch();
break;
case 3 : s1.disp_savbal();
getch();
break;
case 4 : s1.display_accinfo();
s1.disp_savbal();
getch();
break;
case 5 : goto end;
default: cout<<"\n\nEntered choice is invalid,\"TRY AGAIN\"";
}
}
}
else
{
{
c1.get_accinfo();
while(1)
{
cout<<"\nChoose Your Choice\n";
cout<<"1)
Deposit\n";
cout<<"2)
Withdraw\n";
cout<<"3)
Display Balance\n";
cout<<"4)
Display with full Details\n";
cout<<"5)
Exit\n";
cout<<"6)
Choose Your choice:-";
cin>>choice;
switch(choice)
{
case 1 : c1.deposit_currbal();
getch();
break;
case 2 : c1.withdraw_currbal();
getch();
break;
case 3 : c1.disp_currbal();
getch();
break;
case 4 : c1.display_accinfo();
c1.disp_currbal();
getch();
break;
case 5 : goto end;

default: cout<<"\n\nEntered choice is invalid,\"TRY AGAIN\"";


}
}
}
end:
}
}

PROGRAM:PAYROLL SYSTEM USING SINGLE


INHERITANCE
#include<iostream.h>
#include<conio.h>
class emp
{
public:
int eno;
char name[20],des[20];
void get()
{
cout<<"Enter the employee number:";
cin>>eno;
cout<<"Enter the employee name:";
cin>>name;
cout<<"Enter the designation:";
cin>>des;
}
};
class salary:public emp
{
float bp,hra,da,pf,np;
public:
void get1()
{
cout<<"Enter the basic pay:";
cin>>bp;
cout<<"Enter the Humen Resource Allowance:";
cin>>hra;
cout<<"Enter the Dearness Allowance :";
cin>>da;
cout<<"Enter the Profitablity Fund:";
cin>>pf;
}
void calculate()
{

np=bp+hra+da-pf;
}
void display()
{
cout<<eno<<"\t"<<name<<"\t"<<des<<"\t"<<bp<<"\t"<<hra<<"\t"<<da<<"\t"<<pf<<"\
t"<<np<<"\n";
}
};
void main()
{
int i,n;
char ch;
salary s[10];
clrscr();
cout<<"Enter the number of employee:";
cin>>n;
for(i=0;i<n;i++)
{
s[i].get();
s[i].get1();
s[i].calculate();
}
cout<<"\ne_no \t e_name\t des \t bp \t hra \t da \t pf \t np \n";
for(i=0;i<n;i++)
{
s[i].display();
}
getch();
}

Output:
Enter the Number of employee:1
Enter the employee No: 150
Enter the employee Name: ram
Enter the designation: Manager
Enter the basic pay: 5000
Enter the HR allowance: 1000

Enter the Dearness allowance: 500


Enter the profitability Fund: 300
E.No E.name des
150

ram

BP HRA DA PF

Manager 5000 1000 500 300

NP
6200

Code for Program of Education System that maintains Institute Database


using multilevel inheritance in C++ Programming
#include <iostream.h>
#include <conio.h>
class staff
{
protected:
int code;
char name[20];
public:
void getstaff(void)
{
cout<<"\n\nEnter code :-";
cin>>code;
cout<<"Enter name :-";
cin>>name;
}
void dispstaff(void)
{
cout<<"\nNAME
:-"<<name;
cout<<"\nCODE
:-"<<code;
}
};
class teacher : public staff
{
char sub[20];
char pub[20];
public:
void create(void)
{
getstaff();
cout<<"Enter Subject :-";
cin>>sub;
cout<<"Enter Publication :-";
cin>>pub;
}
void display(void)
{
dispstaff();
cout<<"\nSUBJECT
:-"<<sub;
cout<<"\nPUBLICATION:-"<<pub;
}
};
class officer : public staff
{
char grade;

public:
void create(void)
{
getstaff();
cout<<"Enter Grade :-";
cin>>grade;
}
void display(void)
{
dispstaff();
cout<<"\nGRADE
:-"<<grade;
}
};
class typist : public staff
{
float speed;
public:
void gettypist(void)
{
getstaff();
cout<<"Enter speed (wpm):-";
cin>>speed;
}
void disptypist(void)
{
dispstaff();
cout<<"\nSPEED
:-"<<speed;
}
};
class casual : public typist
{
float dailywages;
public:
void create(void)
{
gettypist();
cout<<"Enter Daily Wages :-";
cin>>dailywages;
}
void display(void)
{
disptypist();
cout<<"\nDAILY WAGES:-"<<dailywages;
}
};
void main()
{
clrscr();
teacher o1t[10];
casual o1c[10];
officer o1o[10];
int choice,i;
char test;
while(1)
{
int count;
start:
clrscr();

cout<<"\n=====EDUCATION INSTITUTION DATABASE=====\n\n\n";


cout<<"Choose Category of Information\n";
cout<<"1)
Teachers\n";
cout<<"2)
Officer\n";
cout<<"3)
Typist\n";
cout<<"4)
Exit\n";
cout<<"Enter your choice:-";
cin>>choice;
switch(choice)
{
case 1 : while(1)
{
clrscr();
cout<<"\n=====TEACHERS INFORMATION=====\n\n";
cout<<"\nChoose your choice\n";
cout<<"1) Create\n";
cout<<"2) Display\n";
cout<<"3) Jump to Main Menu\n";
cout<<"Enter your choice:-";
cin>>choice;
switch(choice)
{
case 1 : for(count=0,i=0;i<10;i++)
{
cout<<endl;
o1t[i].create();
count++;
cout<<endl;
cout<<"\n\nAre you Interested in entering data\n";
cout<<"Enter y or n:-";
cin>>test;
if(test=='y' || test=='Y')
continue;
elsegoto out1;
}
out1:
break;
case 2 : for(i=0;i<count;i++)
{
cout<<endl;
o1t[i].display();
cout<<endl;
}
getch();
break;
case 3 : goto start;
default: cout<<"\nEnter choice is invalid\ntry again\n\n";
}
}
case 2 :
while(1)
{
clrscr();
cout<<"\n=====OFFICERS INFORMATION=====\n\n";
cout<<"\nChoose your choice\n";
cout<<"1) Create\n";
cout<<"2) Display\n";
cout<<"3) Jump to Main Menu\n";
cout<<"Enter your choice:-";
cin>>choice;
switch(choice)
{
case 1 : for(count=0,i=0;i<10;i++)

{
cout<<endl;
o1o[i].create();
count++;
cout<<endl;
cout<<"\n\nAre you Interested in entering data\n";
cout<<"Enter y or n:-";
cin>>test;
if(test=='y' || test=='Y')
continue;
elsegoto out2;
}
out2:
break;
case 2 : for(i=0;i<count;i++)
{
cout<<endl;
o1o[i].display();
cout<<endl;
}
getch();
break;
case 3 : goto start;
default: cout<<"\nInvalid choice\ntry again\n\n";
}
}
case 3 : while(1)
{
clrscr();
cout<<"\n=====TYPIST INFORMATION=====\n\n";
cout<<"\nChoose your choice\n";
cout<<"1) Create\n";
cout<<"2) Display\n";
cout<<"3) Jump to Main Menu\n";
cout<<"Enter your choice:-";
cin>>choice;
switch(choice)
{
case 1 : for(count=0,i=0;i<10;i++)
{
cout<<endl;
o1c[i].create();
count++;
cout<<endl;
cout<<"\n\nAre you Interested in entering data\n";
cout<<"Enter y or n:-";
cin>>test;
if(test=='y' || test=='Y')
continue;
elsegoto out3;
}
out3:
break;
case 2 : for(i=0;i<count;i++)
{
cout<<endl;
o1c[i].display();
cout<<endl;
}
getch();
break;
case 3 : goto start;

default: cout<<"\nInvalid choice\ntry again\n\n";


}
}
case 4 : goto end;
}
}
end:
}

Code for Program to illustrate operator overloading for strings in C++


Programming
#include<iostream.h>
#include<string.h>
#include<conio.h>
/*************************************************************************///----------------------------- string
-------------------------------///****************************************************
*********************/classstring
{
private:
char str[80];
public:
string() { strcpy(str,"ttt"); }
string(char s[]) { strcpy(str,s); }
void display() { cout<<str<<endl; }
stringoperator+(string );
};

/*************************************************************************///------------------------- operator+(string)
------------------------///***********************************************************
**************/stringstring::operator+(string ss)
{
string temp;
if(strlen(str)+strlen(ss.str)<80)
{
strcpy(temp.str,str);
strcat(temp.str,ss.str);
}
else
{
cout<<"string overflow"<<endl;
temp=0;
}

return temp;
}
main()
{
clrscr();
string s1(" Best Wishes");
string s2(" Happy New Year");
string s3;
s1.display();
s2.display();
s3=s1+s2;
s3.display();
getch();
return 0;
}

Code for Program that provides an example of friend function of a class in C+


+ Programming
#include<iostream.h>
#include<conio.h>
class data2;
class data1
{
int a,b;
public:
void get1();
friend void sum(data1,data2);
};
class data2
{
int c,d;
public:
void get2();
friend void sum(data1,data2);
};
void sum(data1 a1,data2 a2)
{
cout<<a1.a+a2.c<<endl;
cout<<a1.b+a2.d<<endl;
}
main()
{
data1 a;

data2 b;
a.get1();
b.get2();
sum(a,b);
}
void data1::get1()
{
cout<<"Enter value
cin>>a;
cout<<"Enter value
cin>>b;
}
void data2::get2()
{
cout<<"Enter value
cin>>c;
cout<<"Enter value
cin>>d;
}

for a: ";
for b: ";

for c: ";
for d: ";

Code for Program of virtual inheritance that takes input of staff members and
performs an operation on it in C++ Programming
#include <iostream.h>
#include <conio.h>
class person
{
protected:
char name[20];
int code;
public:
void getdetail(void)
{
cout<<"\n\nEnter name :-";
cin>>name;
cout<<"Enter code :-";
cin>>code;
}
void dispdetail(void)
{
cout<<"\n\nNAME
:-"<<name;
cout<<"\nCODE
:-"<<code;
}
};
class account : virtualpublic person
{
protected:
float pay;
public:
void getpay(void)
{
cout<<"\nEnter Pay amount :-";

cin>>pay;
}
void dispay(void)
{
cout<<"\nPAY
:-"<<pay;
}
};
class admin : virtualpublic person
{
protected:
int experience;
public:
void getexpr(void)
{
cout<<"\nEnter Experience in yrs :-";
cin>>experience;
}
void dispexpr(void)
{
cout<<"\nEXPERIENCE:-"<<experience;
}
};
class master : public account, public admin
{
public:
void create(void)
{
cout<<"\n\n=====GETDATA IN=====\n";
getdetail();
getpay();
getexpr();
}
void display(void)
{
cout<<"\n\n=====DISPLAY DETAILS=====\n";
dispdetail();
dispay();
dispexpr();
}
void update(void)
{
cout<<"\n\n=====UPDATE DETAILS=====\n";
cout<<"\nChoose detail you want to update\n";
cout<<"1) NAME\n";
cout<<"2) CODE\n";
cout<<"3) EXPERIENCE\n";
cout<<"4) PAY\n";
cout<<"Enter your choice:-";
int choice;
cin>>choice;
switch(choice)
{
case 1 : cout<<"\n\nEnter name : -";
cin>>name;
break;
case 2 : cout<<"\n\nEnter code :-";
cin>>code;
break;

case 3 : cout<<"\n\nEnter pay :-";


cin>>pay;
break;
case 4 : cout<<"\n\nEnter Expereince :-";
cin>>experience;
break;
default: cout<<"\n\nInvalid choice\n\n";
}
}
};
void main()
{
clrscr();
master ob1;
int choice;
while(1)
{
clrscr();
cout<<"\n=====MASTER DATABASE=====\n\n";
cout<<"\nChoose Operation you want to perform\n";
cout<<"1) Create Record\n";
cout<<"2) Display Record\n";
cout<<"3) Update Record\n";
cout<<"4) Exit\n";
cout<<"Enter your choice:-";
cin>>choice;
switch(choice)
{
case 1 : ob1.create();
break;
case 2 : ob1.display();
getch();
break;
case 3 : ob1.update();
break;
case 4 : gotoout;
default : cout<<"\n\nInvalid Choice\nTry Again\n\n";
}
}
out:
}

Create a base class basic_info with data members name ,roll no, sex and two member
functions getdata and display. Derive a class physical_fit from basic_info which has data
members height and weight and member functions getdata and display. Display all the
information using object of derived class.

SOURCE CODE:
#include<iostream>
using namespace std;
const int MAX=100;

class basic_info
{
private:
float height;
float weight;
public:
void getdata( );
void display( );
};
void basic_info::getdata1( )
{
cout<<"Enter a name \n";
cin>>name;
cout<<"Roll no:\n";
cin>>rollno;
cout<<" Sex:\n";
cin>>sex;
}
void basic_info::display1( )
{
cout<<name<<"\t";
cout<<rollno<<"\t";
cout<<sex<<"\t";
}
void physical_fit::getdata( )
{
getdata1();
cout<<" Height \n";
cin>>height;
cout<<" weight \n";
cin>>weight;
}
void physical_fit::display( )
{
display1( );
cout<<height<<"\t";
cout<<weight<<" ";
}
void main()
{
physical_fit a[MAX];
int i,n;
cout<<"How many students\n";
cin>>n;
cout<<"Enter the following infromation\n";
for(i=0;i<n;i++)
{
cout<<"Record :"<<i+1<<endl;

a[i].getdata( );
}
cout<<endl;
cout<<"__________________________________\n";
cout<<"Name\tRollNo\tSex Height Weight\n";
cout<<"___________________________________\n";
for(i=0;i<n;i++)
{
a[i].display( );
cout<<endl;
}
cout<<endl;
cout<<"___________________________________\n";
}

Potrebbero piacerti anche