You are on page 1of 7

5.

Program to find the sum of rows and column


of an array.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10][10],r,c,s1=0,s2=0,i,j;
cout<<"enter the no. of rows and columns\n";
cin>>r>>c;
cout<<"enter the array\n";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>a[i][j];
}
}
cout<<"Matrix is\n";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<a[i][j]<<'\t';
}
cout<<endl;
}
if(r==c)
{
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(i==j)
{
s1=s1+a[i][j];
}
if((i+j)==2)
{
s2=s2+a[i][j];
}
}
}
cout<<"sum of main diagonal elements is="<<s1<<'\n';
cout<<"sum of another diagonal elements is="<<s2<<'\n';
}
else
cout<<"no diagonal sum possible\n";
getch();
}

11. PROGRAMME TO CALCULATE THE TOTAL


AMOUNT IN STAYING A RESORT
#include<iostream.h>
#include<string.h>
#include<iomanip.h>
#include<stdio.h>
#include<conio.h>
class resort
{
char adr[20]; //permanent adress
long pno;
int rno;
//room no.
char name[10];
//customer name
int charge; //charges per day
int day; //no. of days of stay
int amount; //total bill
public:
void getinfo()
{
cout<<"Enter name of the customer\n";
gets(name);
cout<<"Enter the phone no.\n";
cin>>pno;
cout<<"Enter the permanent adress\n";
gets(adr);
cout<<"Enter the room no.\n";
cin>>rno;
cout<<"enter the charge per day\n";
cin>>charge;
cout<<"Enter no. of days of stay\n";
cin>>day;
}
void dispinfo()
{
amount=charge*day;
cout<<"Details are\n";
cout<<"Name-->";
puts(name);
cout<<"Phone no.-->"<<pno<<'\n';
cout<<"Permanent adress-->";
puts(adr);
cout<<"Room no="<<rno<<'\n';
cout<<"Charge per day="<<charge<<'\n';
cout<<"No. of days of stay="<<day<<'\n';
cout<<"Amount payable="<<amount<<'\n';
}};
void main()
{
clrscr();
resort c;

c.getinfo();
c.dispinfo();
getch();
}

12. CONSTRUCTOR OVERLOADING


#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
class student
{
int rollno;
char name[20];
float marks;
public:
student() // default constructor
{
rollno=0;
strcpy(name,"no entry");
marks=0;
}
student(int r,char nm[],float m)
{
//parametrised constructor
rollno=r;
strcpy(name,nm);
marks=m;
}
student(student&s) //copy constructor
{
rollno=s.rollno;
strcpy(name,s.name);
marks=s.marks;
}
void getdata()
{
cout<<"Enter rollno\n";
cin>>rollno;
cout<<"Enter name\n";
gets(name);
cout<<"Enter marks\n";
cin>>marks;
}
void showdata()
{
cout<<"Roll no.="<<rollno<<'\n';
cout<<"Name="<<name<<'\n';
cout<<"Marks="<<marks<<'\n';
}};
void main()
{

clrscr();
student s1,s2;
cout<<"Enter the details:-->";
s1.getdata();
s2.getdata();
student s3(s1);
student s4=student(11,"Kapil",98);//explicit call
cout<<"Details are:-->";
s1.showdata();
s2.showdata();
s3.showdata();
s4.showdata();
getch();
}

13. Programme of inheritance


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class school
{
int regno;
char schoolname[10];
public:
void getschooldata()
{
cout<<"Enter registration number of school\n";
cin>>regno;
cout<<"Enter name of school\n";
gets(schoolname);
}
void showschooldata()
{
cout<<"REGISTRATION NUMBER= "<<regno<<'\n';
cout<<"SCHOOL NAME= "<<schoolname<<'\n';
}
};
class student:private school
{
int rollno;
char name[10];
float marks;
public:
void getstudentdata()
{
getschooldata();
cout<<"Enter the rollno\n";
cin>>rollno;
cout<<"Enter the name\n";
gets(name);

cout<<"Enter marks\n";
cin>>marks;
}
void showstudentdata()
{
showschooldata();
cout<<"ROLL NUMBER= "<<rollno<<'\n';
cout<<"NAME ="<<name<<'\n';
cout<<"MARKS ="<<marks<<'\n';
}
};
void main()
{ clrscr();
student s;
cout<<"Enter the details:-\n";
//s.getschooldata();
s.getstudentdata();
cout<<"Information is as under:-\n";
//s.showschooldata();
s.showstudentdata();
getch();
}

14. PROGRAMME OF MULTIPLE INHERITENCE


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class school
{
int regno;
char schoolname[10];
public:
void getschool()
{
cout<<"Enter registration number of school\n";
cin>>regno;
cout<<"Enter name of school\n";
gets(schoolname);
}
void showschool()
{
cout<<"REGISTRATION NUMBER= "<<regno<<'\n';
cout<<"SCHOOL NAME= "<<schoolname<<'\n';
}
};
class student
{
int rollno;
char name[10];
protected:

int pmarks,cmarks,mmarks;
public:
void getstudentdata()
{
void getschooldata();
cout<<"Enter the rollno\n";
cin>>rollno;
cout<<"Enter the name\n";
gets(name);
cout<<"Enter marks in physics,chemistry and maths\n";
cin>>pmarks>>cmarks>>mmarks;
}
void showstudentdata()
{
void showschooldata();
cout<<"ROLL NUMBER= "<<rollno<<'\n';
cout<<"NAME ="<<name<<'\n';
cout<<"PHYSICS MARKS="<<pmarks<<'\n';
cout<<"CHEMISTRY MARKS="<<cmarks<<'\n';
cout<<"MATHS MARKS="<<mmarks<<'\n';
}
};
class result:public school,public student
{
int total;
float average;
public:
void calculateresult()
{
total=pmarks+cmarks+mmarks;
average=total/3;
if(average>=80)
cout<<"Your grade is A\n";
else if(average>=60 && average<80)
cout<<"Your grade is B\n";
else if(average<60)
cout<<"Your grade is C\n";
else
cout<<"Invalid choice\n";
}
void showresult()
{
cout<<"TOTAL MARKS="<<total<<'\n';
cout<<"AVERAGE MARKS="<<average<<'\n';
}};
void main()
{
clrscr();
result s1;
cout<<"Enter the school data\n";
s1.getschool();
cout<<"Enter the student data\n";

s1.getstudentdata();
s1.calculateresult();
cout<<"RESULT IS\n";
s1.showresult();
}

You might also like