1.

Define a class Student with the following specification: private members:roll_nointegername20 charactersclass8 charactersmarks[5]integerpercentagefloatCalculate() function that calculates overall percentage of marks and returns the percentage of marks.public members:Readmarks() a function that reads marks and invokes the calculate functio Displaymarks() a function that prints the marks.

Answer»

#include <iostream.h>

#include<stdio.h>

#include<conio.h>

class Student

{

int roll_no;

char name[20];

char Class[8];

int marks[5]; 

flloat percentage;

float Calculate()

{ percentage = (marks[0]+marks[1]+marks[2]+marks[3]+marks[4])/5; return percentage;

}

public: void Readmarks();

void Displaymarks();

};

void Student::Readmarks() {

cout<<endl<<"Enter roll number: ";

cout<>roll_no;

cout<<endl<<"Enter name:";

gets(name);

cout<<"Enter marks in ";

for(int i=0;i<5;i++)

{

cout<<end1<<"Subject "<<i+1<<":";

cout<>marks[i]; 

 };

Calculate(); 

void Student::Displaymarks() {

cout<<"......Student Marksheet........";

cout<<end1<<"Roll number:"<<roll_no<<end1;

cout<<" Name:"<<name<<end1;

cout<<" Marks in subject-1:"<< marks[0]<<end1

;

cout<<" Marks in subject-2:"<< marks[1]<<end1;

cout<<" Marks in subject-3:"<<marks[2]<<end1;

cout<<" Marks in subject-4:"<<marks[3]<<end1;

cout<<" Marks in subject-5:"<< marks[4]<<end1;

cout<<" Percentage:"<<percentage<<end1l;

 int main()

Student obj;

obj.Readmarks();

obj.Displaymarks();

getch(); return 0; 

}



Discussion

No Comment Found

Related InterviewSolutions