-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10.cpp
More file actions
72 lines (53 loc) · 1.28 KB
/
10.cpp
File metadata and controls
72 lines (53 loc) · 1.28 KB
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
/*
@Author: Amritanshu Sikdar
Session: 2018-'19
Repository: https://github.com/amritanshusikdar/CS30PracticalQuestion
*/
// To accept student data and print it
#include<constream.h>
#include<stdio.h>
#include<fstream.h>
#include<iomanip.h>
struct student
{
char name[20];
char house[11];
int amount;
};
// User define function declaration
void line();
void main()
{
clrscr();
student student;
fstream file("STUDENT.TXT", ios::in | ios::out);
for(int i=0; i<5; i++)
{
cout << "Enter Details:- " << endl;
cout << "Name: ";
gets(student.name);
cout << "House: ";
gets(student.house);
cout << "Amount Collected: ";
cin >> student.amount;
file.write((char*) &student, sizeof(student));
}
line();
cout << "Name\t House\t\tAmount Collected" << endl;
line();
file.seekg(0, ios::beg); // Moving the file pointer to the begining of the file
while(file.read((char*) &student, sizeof(student)))
{
cout << student.name << "\t" << setw(9) << student.house << "\t" << student.amount << endl;
}
line();
file.close();
getch();
}
// User define function
void line()
{
for(int i=0; i<60; i++)
cout << '-';
cout << endl;
}