Define a class named Student, create following members in it: Data Members: student_name, rollno, class (BCA/MCA), semester, sub1_marks,sub2_marks, sub3_marks, total marks, average, percentage.
Member Functions:
To enter the information of a student.
To calculate his/her total, average, percentage.
To display the result.
Write a program to test your class.
Coding:
Member Functions:
To enter the information of a student.
To calculate his/her total, average, percentage.
To display the result.
Write a program to test your class.
Coding:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class
student
{
int
roll,total_marks,sub1_marks,sub2_marks,sub3_marks;
char stu_name[20],clss[3],sem[10];
float avg,percentage;
public:
void getdata();
void calculation();
void display();
};
void
student::getdata()
{
cout<<"\nEnter Student
Name:"<<" ";
gets(stu_name);
cout<<"\nEnter Student Roll
No.:"<<" ";
cin>>roll;
cout<<"\nEnter
class:"<<" ";
gets(clss);
cout<<"\nEnter
semester:"<<" ";
gets(sem);
cout<<"\nEnter subject
marks:"<<" ";
cin>>sub1_marks>>sub2_marks>>sub3_marks;
}
void
student::calculation()
{
total_marks=sub1_marks+sub2_marks+sub3_marks;
avg=total_marks/3;
percentage=total_marks*100/300;
}
void
student::display()
{
cout<<"\nThe Result is:\n";
cout<<"\nTotal
Marks="<<total_marks;
cout<<"\nAverage
Marks="<<avg;
cout<<"\nPercentage
Marks="<<percentage;
}
void
main()
{
clrscr();
student stu;
stu.getdata();
stu.calculation();
stu.display();
getch();
}
Output:
No comments:
Write comments