-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program_29.CPP
96 lines (86 loc) · 1.54 KB
/
Program_29.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* Program to calculate grade of students based on marks */
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
#include<stdlib.h>
int i;
class student
{
int rollno;
char name[30],grade;
float marks[10],total;
public:
void getdata();
void calculate();
void showdata();
}stud;
void student :: calculate()
{
float total=0;
for(i=0;i<5;i++)
{
total+=marks[i];
}
if(total>400)
grade='A';
else if(300<total<400)
grade='B';
else if(200<total<300)
grade='C';
else if(150<total<200)
grade='D';
else if(100<total<150)
grade='E';
else if(total<100)
grade='F';
}
void student::showdata()
{
calculate();
cout<<"\nname:"<<name<<"\nstudent rollno:"<<rollno<<"\ngrade:"<<grade;
}
void student::getdata()
{
cout<<"\nenter name of student:";
gets(name);
cout<<"\nenter rollno of student:";
cin>>rollno;
for(i=0;i<5;i++)
{
cout<<"enter marks (out of 100) in subject"<<i+1<<":";
cin>>marks[i];
}
calculate();
}
void create()
{int n,i=0;
ofstream fout;
fout.open("student.dat",ios::out|ios::binary);
cout<<"\nEnter how many students?:";
cin>>n;
do
{ stud.getdata(); i++;
fout.write((char*)&stud,sizeof(stud));
} while(i<n);
fout.close();
}
void readfile()
{
ifstream fin;
fin.open("student.dat",ios::in|ios::binary);
fin.read((char*)&stud,sizeof(stud));
while(fin)
{
stud.showdata();
fin.read((char*)&stud,sizeof(stud));
}
fin.close();
}
void main()
{
clrscr();
create();
readfile();
getch();
}