Saturday, 7 March 2015

C++ LAB Part-A 3

//Program : Part A-3
//Write a c++ program to compute total marks and declare the results using array of //object. Assume that the class contains the data members - roll no,name,marks in //three subjects. Result is calculated as follows.
//a)if student gets<35 fail. Otherwise various results calculated on average as
//b)>=70 Distinction
//c)>=60 and <70 First class
//d)>=50 and <60 Second class else pass.
//Name : LDK E-NOTES                                                                                        Reg.No. : **********
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<string.h>
class student
{
private:
int rollno;
char name[20];
int m1,m2,m3;
public:
void accept();
void display();
};
void student :: accept()
{
cout<<"Enter the roll number                       : ";
cin>>rollno;
cout<<"Enter the name                                   : ";
cin>>name;
cout<<"Enter the marks in three subjects : ";
cin>>m1>>m2>>m3;
}
void student :: display()
{
int tot;
float avg;
char grade[20];
tot=m1+m2+m3;
avg=tot/3.0;
if(m1<35||m2<35||m3<35)
strcpy(grade,"Fail");
else if(avg>=70)
strcpy(grade,"Distinction");
else if(avg>=60)
strcpy(grade,"First class");
else if(avg>=50)
strcpy(grade,"Second class");
else if(avg<50)
strcpy(grade,"Pass class");
cout<<"---------------------------------------------"<<endl;
cout<<"Roll number                      : "<<rollno<<endl;
cout<<"Name                                   : "<<name<<endl;
cout<<"Marks in three subjects : "<<m1<<setw(8)<<m2<<setw(8)<<m3<<endl;
cout<<"Total marks                       : "<<tot<<endl;
cout<<"Average                              : "<<avg<<endl;
cout<<"Grade                                  : "<<grade<<endl;
}
void main()
{
student s[10];
int n,i;
clrscr();
cout<<"Enter number of students : ";
cin>>n;
cout<<"Enter "<<n<<" students informations\n";
for(i=1;i<=n;i++)
s[i].accept();
for(i=1;i<=n;i++)
s[i].display();
getch();
}







Output :
Enter number of students : 3
Enter 3 students informations
Enter the roll number                        : 400
Enter the name                                    : Deepak
Enter the marks in three subjects : 80 85 90
Enter the roll number                        : 401
Enter the name                                    : Rahul
Enter the marks in three subjects : 59 40 38
Enter the roll number                       : 402
Enter the name                                   : Ramesh
Enter the marks in three subjects : 30 25 10
----------------------------------------------------------
Roll number                      : 400
Name                                   : Deepak
Marks in three subjects : 80      85      90
Total marks                       : 255
Average                              : 85
Grade                                  : Distinction
-----------------------------------------------------------
Roll number                      : 401
Name                                   : Rahul
Marks in three subjects : 59      40      38
Total marks                       : 137
Average                              : 45.666668
Grade                                  : Pass class
-----------------------------------------------------------
Roll number                      : 402
Name                                   : Ramesh
Marks in three subjects : 30      25      10
Total marks                       : 65
Average                              : 21.666666
Grade                                  : Fail

No comments:

Post a Comment