Sei sulla pagina 1di 4

Page No.

Ex no: CLASS AND OBJECT DESIGN IN C++ Date:

AIM : To write a C++ program to find the total marks, average and grade of a student.

ALGORITHM: 1. Start the program. 2. Declare the class as student. 3. Function defined in public. 4. Call the member function for variables. 5. Enter the student name and the six marks. 6. Find the total mark, average and grade. 7. Display the name, total mark, average and grade. 8. Stop the program.

VIVEKANANDHA EDUCATIONAL INSTITUTIONS

Page No.

PROGRAM: #include<iostream.h> #include<conio.h> class student { char name[10],grade; int m[6],total; float avg; public: void accept(); void display(); }; void student::accept() { int i; total=0; cout<<"Enter student name:"; cin>>name; cout<<"Enter 6 marks:"; for(i=0;i<6;i++) { cin>>m[i]; total=total+m[i]; } avg=total/i; } void student::display() { int j; cout<<"\nStudent name:"<<name;

VIVEKANANDHA EDUCATIONAL INSTITUTIONS

Page No.

cout<<"\nMarks:\n"; for(j=0;j<6;j++) cout<<m[j]<<"\t"; cout<<"\nTotal marks:"<<total; cout<<"\nAverage marks:"<<avg; if(avg>75) grade='d'; else if(avg<=75&&avg>60) grade='a'; else if(avg<=60&&avg>50) grade='b'; else if(avg<=50&&avg>40) grade='c'; else grade='f'; cout<<"\nGrade="<<grade; } main() { clrscr(); student s; s.accept(); s.display(); getch(); return 0; }

VIVEKANANDHA EDUCATIONAL INSTITUTIONS

Page No.

RESULT:

Thus the C++ program to find the total marks, average and grade of a student has been executed and verified successfully.

VIVEKANANDHA EDUCATIONAL INSTITUTIONS

Potrebbero piacerti anche