Dec 10, 2015

program in c++ to store husband and wife details & calculate total salary

#include<iostream.h>
#include<conio.h>
class wife;
class husband
{
char name[10];
float sal;
public:
void read()
{
cout<<"Enter the name and salary ";
cin>>name>>sal;
}
void print()
{
cout<<"\n Name :"<<name<<"\n salary :"<<sal<<endl;
}
friend float total(husband,wife);
};
class wife
{
char name[10];
float sal;
public:
void read()
{
cout<<"\n Enter name and sal of wife ";
cin>>name>>sal;
}
void print()
{
cout<<"\n Name :"<<name<<"\n salary :"<<sal<<endl;
}
friend float total(husband,wife);
};
float total(husband h,wife w)
{
return(h.sal+w.sal);
}
void main()
{
husband h;
wife w;
clrscr();
h.read();
w.read();
clrscr();
cout<<"\n Husband details : ";
h.print();
cout<<"\n wife details ";
w.print();
cout<<"Total income "<<total(h,w);
getch();
}

No comments:

Post a Comment