MENU
Question -

Define a class Candidate in C++ with the following specification :   
Private Mumbers:
A data members Rno (Registration Number) type long
A data member Cname of type string
A data members Agg_marks (Aggregate Marks) of type float
A data members Grade of type char
A member function setGrade() to find the grade as per the aggregate marks obtained by the student. Equivalent aggregate marks range and the respective grade as shown below.

Aggregate Marks                      Grade
> = 80                                          A
Less than 80 and >    =    65     B
Less than 65 and >    =    50     C
Less than 50                               D
Public members:
A constructor to assign default values to data members:
Rno = 0, Cname “N.A”, Age_marks = 0.0
A function Getdata ( ) to allow users to enter values for Rno. Cname, Agg_marks and call function setGrade () to find the grade.
A function dispResult () to allow user to view the content of all the data members.



Answer -

class Candidate 
{ long Rno;
 char Cname [20]; 
float Agg_marks; 
char Grade; 
void setGrade ()
 { if (Agg_marks>= 80)
 Grade = 'A';
 else if (Agg_marks<80 && Agg_ marks>=65)
 Grade = 'B' ;
 else if (Agg_marks<65 && Agg_ marks>=50)
 Grade = 'C'; 
else
 Grade = 'D' ;
 }
 public;
 Candidate ( )
 {
 Rno=0;
 Strcpy (Cname, ''N.A.''); 
Agg_marks=0.0;
 }
 void Getdata ()
 {
 cout<<''Registration No''; 
cin>>Rno; 
cout<<"Name''; 
cin>>Cname;
 cout<
cin>>Agg_marks; 
set Grade ();
 }
 void dispResult ()
 {
 cout<<"Registration No''<
cout<<"Name''<
 cout<<"Aggregate Marks''<
 marks;
 }

Comment(S)

Show all Coment

Leave a Comment

×