DEFINING A CLASS STUDENT WITH APPROPRIATE VARIABLES AND FUNCTIONS
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
class student
{
int rollno;
char name[20];
float marks;
char grade;
public:
void getdata()
{
cout<<"Enterv the roll no. of student:";
cin>>rollno;
cout<<"Enter name:";
gets(name);
cout<<"Enter marks:";
cin>>marks;
}
void calcgrade()
{
if(marks>=90)
grade='A';
else if(marks>75)
grade='B';
else if(marks<75)
grade='C';
}
void display_data()
{
cout<<"Roll no. is:"<<rollno;
cout<<"Name is:"<<name;
cout<<"Marks is:"<<marks;
cout<<"grade is:"<<grade;
}
};
void main()
{
clrscr(0;
student s;
s.getdata();
s.calcgrade();
s.display_data();
getch();
}
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
class student
{
int rollno;
char name[20];
float marks;
char grade;
public:
void getdata()
{
cout<<"Enterv the roll no. of student:";
cin>>rollno;
cout<<"Enter name:";
gets(name);
cout<<"Enter marks:";
cin>>marks;
}
void calcgrade()
{
if(marks>=90)
grade='A';
else if(marks>75)
grade='B';
else if(marks<75)
grade='C';
}
void display_data()
{
cout<<"Roll no. is:"<<rollno;
cout<<"Name is:"<<name;
cout<<"Marks is:"<<marks;
cout<<"grade is:"<<grade;
}
};
void main()
{
clrscr(0;
student s;
s.getdata();
s.calcgrade();
s.display_data();
getch();
}
Comments
Post a Comment