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 …


Advertisement
Categories: Cpp Tags: ,
  1. raja
    December 18, 2018 at 7:29 pm

    Can you give a program code.
    That is
    ” declaring student marks (public exam manner)”

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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

%d bloggers like this: