Example
#include<iostream.h>
#include<conio.h>
#include<math.h>
class report
{
int rno,mks[3],total;
float per;
public:
void getdata();
void putdata();
void calculate();
};
void report::getdata()
{
int i,j,tot=0;
cout<<"Enter rollno:";
cin>>rno;
for(j=0;j<3;j++)
{
cout<<"enter marks:";
cin>>mks[j];
}
}
void report::calculate()
{
total=0;
for(int j=0;j<3;j++)
{
total=total+mks[j];
}
per=total/3;
// return per;
}
void report::putdata()
{
cout<<rno<<" ";
for(int j=0;j<3;j++)
{
cout<<mks[j]<<" ";
}
cout<<total<<" "<<per<<endl;
}
int main()
{
report r[5];
int i,n;
clrscr();
cout<<"Enter total no of student :";
cin>>n;
for(i=0;i<n;i++)
{
r[i].getdata();
}
for(i=0;i<n;i++)
{
r[i].calculate();
}
cout<<"ROLLNO SUB1 SUB2 SUB3 TOTAL PER(%)"<<endl;
cout<<"======================================"<<endl;
for(i=0;i<n;i++)
{
r[i].putdata();
}
getch();
return 0;
}
/*===============================================================
OUTPUT
Enter total no of student :2
Enter rollno:1
enter marks:33
enter marks:44
enter marks:55
Enter rollno:2
enter marks:66
enter marks:55
enter marks:44
ROLLNO SUB1 SUB2 SUB3 TOTAL PER(%)
======================================
1 33 44 55 132 44
2 66 55 44 165 55
*/
#include<iostream.h>
#include<conio.h>
#include<math.h>
class report
{
int rno,mks[3],total;
float per;
public:
void getdata();
void putdata();
void calculate();
};
void report::getdata()
{
int i,j,tot=0;
cout<<"Enter rollno:";
cin>>rno;
for(j=0;j<3;j++)
{
cout<<"enter marks:";
cin>>mks[j];
}
}
void report::calculate()
{
total=0;
for(int j=0;j<3;j++)
{
total=total+mks[j];
}
per=total/3;
// return per;
}
void report::putdata()
{
cout<<rno<<" ";
for(int j=0;j<3;j++)
{
cout<<mks[j]<<" ";
}
cout<<total<<" "<<per<<endl;
}
int main()
{
report r[5];
int i,n;
clrscr();
cout<<"Enter total no of student :";
cin>>n;
for(i=0;i<n;i++)
{
r[i].getdata();
}
for(i=0;i<n;i++)
{
r[i].calculate();
}
cout<<"ROLLNO SUB1 SUB2 SUB3 TOTAL PER(%)"<<endl;
cout<<"======================================"<<endl;
for(i=0;i<n;i++)
{
r[i].putdata();
}
getch();
return 0;
}
/*===============================================================
OUTPUT
Enter total no of student :2
Enter rollno:1
enter marks:33
enter marks:44
enter marks:55
Enter rollno:2
enter marks:66
enter marks:55
enter marks:44
ROLLNO SUB1 SUB2 SUB3 TOTAL PER(%)
======================================
1 33 44 55 132 44
2 66 55 44 165 55
*/
No comments:
Post a Comment