/* Copyright © 2007 Ankur Banerjee. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. http://www.fsf.org/licensing/licenses/lgpl.html /
/ Classes – Program to manage student data /
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
class student
{
int admno;
char sname[20];
float mark[5], total;
float calculate();
public:
void takedata();
void showdata();
} stud;
float avg;
void student :: takedata()
{
cout<<endl<<“Enter admission number : “;
cin>>admno;
cout<<“Enter student name : “;
gets(sname);
cout<<“Enter marks in five subjects”<<endl;
for (int i = 0; i < 5; i++)
{
cout<<“Enter marks for subject “<<i + 1<<” : “;
cin>>mark[i];
}
avg = calculate();
showdata();
}
void student :: showdata()
{
cout<<endl<<“Details for student are”<<endl
<<“Student admission number : “<<admno<<endl
<<“Student name : “<<sname<<endl
<<“Student marks in five subjects”;
for (int i = 0; i < 5; i++)
cout<<endl<<“Marks of student in subject “<<i + 1
<<” : “<<mark[i];
cout<<endl<<“Total marks of student : “<<total<<endl
<<“Average marks of student : “<<avg<<endl;
}
float student :: calculate()
{
total = 0;
for (int i = 0; i < 5; i++)
total+= mark[i];
return (total / 5);
}
void main()
{
clrscr();
cout<<“Enter details for student”;
stud.takedata();
getch();
}
/ Output */
Enter details for student
Enter admission number : 42
Enter student name : Arthur Dent
Enter marks in five subjects
Enter marks for subject 1 : 58
Enter marks for subject 2 : 98
Enter marks for subject 3 : 67
Enter marks for subject 4 : 53
Enter marks for subject 5 : 42
Details for student are
Student admission number : 42
Student name : Arthur Dent
Student marks in five subjects
Marks of student in subject 1 : 58
Marks of student in subject 2 : 98
Marks of student in subject 3 : 67
Marks of student in subject 4 : 53
Marks of student in subject 5 : 42
Total marks of student : 318
Average marks of student : 63.6