-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileHandling.cpp
More file actions
34 lines (33 loc) · 850 Bytes
/
fileHandling.cpp
File metadata and controls
34 lines (33 loc) · 850 Bytes
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
#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
using namespace std;
int main(){
ifstream file("input.txt");
string a, name, toan, ly, hoa;
float total, average;
while(!file.eof()){
getline(file, a);
stringstream ss(a);
getline(ss, name, ',');
getline(ss, toan, ',');
if(toan == ""){
toan = "0";
}
getline(ss, ly, ',');
if(ly == ""){
ly = "0";
}
getline(ss, hoa, ',');
if(hoa == ""){
hoa = "0";
}
total = stof(toan) + stof(ly) + stof(hoa);
average = total / 3;
cout << "Name: " << name << endl;
cout << "Total: " << total << endl;
cout << "Average: " << average << endl;
cout << endl;
}
}