12

C++ Program to maintain Student Result by using CLASS with PUBLIC & PRIVATE...

 4 years ago
source link: https://sqlwithmanoj.com/2010/01/07/c-program-to-maintain-student-result-by-using-class-with-public-private-access-specifiers-q7/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Home > Cpp > C++ Program to maintain Student Result by using CLASS with PUBLIC & PRIVATE Access Specifiers – Q7

C++ Program to maintain Student Result by using CLASS with PUBLIC & PRIVATE Access Specifiers – Q7

Q7. Program Matrix manipulation (menu based):

Make a structure Student with following fields:
– Name
– Roll No.
– Result (Structure)
– – Total Marks Obtained
– – Max_Marks
– – Percentage

Read the list of students (At least 3) in a class.
Now compare the results of all the students and Rank top 3 students in the whole class.

… from College notes (BCA/MCA assignments):

#include <iostream.h>
#include <conio.h>
class CStud{
private:
char name[20], course[10];
char grade;
public:
int  marks;
void getinfo();
void compute();
void display();
};
void CStud :: getinfo(){
cout<<"\n Enter Name: ";
cin>>name;
cout<<"\n Enter Course: ";
cin>>course;
cout<<"\n Enter Marks Obtained (out of 500): ";
cin>> marks;
}
void CStud :: compute(){
int per;
per = marks/5;
if(per >= 80)
grade = 'A';
else if( (per < 80) && (per >= 60) )
grade = 'B';
else if( (per < 60) && (per >= 40) )
grade = 'C';
else
grade = 'D';
}
void CStud :: display(){
cout<<"\n Name: "<<name;
cout<<"\t Course: "<<course;
cout<<"\t Marks: "<<marks;
cout<<"\t Grade: "<<grade;
}
void main(){
int n = 0;
char ch;
CStud Ostu[10];             // Creating Object.
clrscr();
while(ch != 'n'){                   // Getting Information.
gotoxy(25, 1);
cout<<"-: STUDENT INFORMATION :- \n";
cout<<"\n Student No.: "<<n+1<<endl;
Ostu[n].getinfo();
Ostu[n].compute();              // Calculate Grade.
cout<<"\n Next Student (y/n): ";
cin>>ch;
n++;
clrscr();
}
// Sorting.
CStud Otemp;
for(int i=0; i<n; i++){
for(int j=i; j<n; j++){
if(Ostu[i].marks < Ostu[j].marks){
Otemp = Ostu[i];
Ostu[i] = Ostu[j];
Ostu[j] = Otemp;
}
}
}
clrscr();
gotoxy(25, 1);
cout<<"-: STUDENT'S REPORT :- ";      // Display Results.
for(i=0; i<n; i++){
cout<<"\n\n Student No.: "<<i+1;
Ostu[i].display();
}
cout<<"\n\n Press Any Key to Exit ...";
getch();
}

Output:

-: STUDENT INFORMATION :-

Student No.: 1

Enter Name: Manoj

Enter Course: MCA

Enter Marks Obtained (out of 500): 350

Next Student (y/n): y

-: STUDENT INFORMATION :-

Student No.: 2

Enter Name: Bhanu

Enter Course: MBA

Enter Marks Obtained (out of 500): 400

Next Student (y/n): n

-: STUDENT’S REPORT :-

Student No.: 1
Name: Bhanu Course: MBA Marks: 400 Grade: A

Student No.: 2
Name: Manoj Course: MCA Marks: 350 Grade: B

Press Any Key to Exit …


Related

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK