-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7_4.cpp
More file actions
57 lines (43 loc) · 1.39 KB
/
7_4.cpp
File metadata and controls
57 lines (43 loc) · 1.39 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
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstring>
using namespace std;
// Structure to store student data
struct Student {
char name[50];
float marks;
char grade;
};
// User-defined manipulator for setting a fixed width (like setw)
ostream& alignColumn(ostream& os) {
return os << setw(15) << left;
}
// Function to generate the formatted student report
void generateReport(const char* filename) {
ifstream file(filename);
if (!file.is_open()) {
cerr << "Error: Could not open file \"" << filename << "\" for reading.\n";
return;
}
Student student;
cout << "\n======= Student Performance Report =======\n";
cout << alignColumn << "Name"
<< alignColumn << "Marks"
<< alignColumn << "Grade" << endl;
cout << string(45, '-') << endl;
// Read and display data from the file line by line
while (file >> student.name >> student.marks >> student.grade) {
cout << alignColumn << student.name
<< alignColumn << fixed << setprecision(2) << student.marks
<< alignColumn << student.grade << endl;
}
file.close();
}
int main() {
const char* filename = "students.txt";
cout << "=== Student Report Generator ===\n";
generateReport(filename);
cout<<endl<<"24CE052_Pushti kansara"<<endl;
return 0;
}