KEMBAR78
C++ program using class | TXT
//C++ program using class
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class Student
{
private:
int rollno;
char name[25];
float marks;
char grade;
public:
void readStudent()
{
cout<<"n Enter Roll no.:";
cin>> rollno;
cout<<"n Enter name :";
gets(name);
cout<<"n Enter marks :" ;
cin>> marks;
}
void dispStudent()
{
calcGrade();
cout<<"n Roll no. : "<<rollno;
cout<<"n Name :"<<name;
cout<<"n Marks :"<<marks;
cout<<"n Grade :";
}
int getRollno()
{
return rollno;
}
float getMarks()
{
return marks;
}
void calcGrade()
{
if (marks>=75)
grade='0';
else if (marks >=60)
grade = 'A';
else if (marks >=50)
grade='B';
else if (marks >=40)
grade ='C';
else
grade= 'F';
}
};
void main()
{Student XIIa[10];
for(int i=0; i<10; ++i)
{
cout<<"n Enter the details of student"<<i+1<<":";
XIIa[i].readStudent();
}
int choice, rno, pos=-1, highmarks=0;
do
{
clrscr();
cout<<"nnn Main menunn";
cout<<"n 1. Specific student";
cout<<"n 2. Topper";
cout<<"n 3. Exit ";
cout<<"n Enter your choice";
cin>> choice;
switch(choice)
{
case 1: cout<<"n Enter roll no. of student whose details you want to see:";
cin>>rno;
for(i=0; i<10; ++i)
{
if (XIIa[i].getRollno()==rno)
{XIIa[i].dispStudent();
break;
}
}
if (i==10)
cout<<"n INVALID ROLLNO.!!!!!!!!";
getch();
break;
case 2: for( i=0; i<10; ++i)
{
if(XIIa[i].getMarks()>highmarks)
{
pos=i;
highmarks=XIIa[i].getMarks();
}
}
XIIa[pos].dispStudent();
getch();
break;
case 3: break;
default: cout<<"n nnnnn WRONG CHOICE!!!!!!!!!!!!!nnnnnnn";
}
} while(choice>=1&& choice <3);
}

C++ program using class

  • 1.
    //C++ program usingclass #include<iostream.h> #include<stdio.h> #include<conio.h> class Student { private: int rollno; char name[25]; float marks; char grade; public: void readStudent() { cout<<"n Enter Roll no.:"; cin>> rollno; cout<<"n Enter name :"; gets(name); cout<<"n Enter marks :" ; cin>> marks; } void dispStudent() { calcGrade(); cout<<"n Roll no. : "<<rollno; cout<<"n Name :"<<name; cout<<"n Marks :"<<marks; cout<<"n Grade :"; } int getRollno() { return rollno; } float getMarks() { return marks; } void calcGrade() { if (marks>=75) grade='0'; else if (marks >=60) grade = 'A'; else if (marks >=50) grade='B'; else if (marks >=40) grade ='C'; else grade= 'F'; } }; void main() {Student XIIa[10]; for(int i=0; i<10; ++i) { cout<<"n Enter the details of student"<<i+1<<":"; XIIa[i].readStudent(); } int choice, rno, pos=-1, highmarks=0; do { clrscr(); cout<<"nnn Main menunn";
  • 2.
    cout<<"n 1. Specificstudent"; cout<<"n 2. Topper"; cout<<"n 3. Exit "; cout<<"n Enter your choice"; cin>> choice; switch(choice) { case 1: cout<<"n Enter roll no. of student whose details you want to see:"; cin>>rno; for(i=0; i<10; ++i) { if (XIIa[i].getRollno()==rno) {XIIa[i].dispStudent(); break; } } if (i==10) cout<<"n INVALID ROLLNO.!!!!!!!!"; getch(); break; case 2: for( i=0; i<10; ++i) { if(XIIa[i].getMarks()>highmarks) { pos=i; highmarks=XIIa[i].getMarks(); } } XIIa[pos].dispStudent(); getch(); break; case 3: break; default: cout<<"n nnnnn WRONG CHOICE!!!!!!!!!!!!!nnnnnnn"; } } while(choice>=1&& choice <3); }