please help. where there are // is where code needs to be written please help. D
ID: 3808950 • Letter: P
Question
please help. where there are // is where code needs to be written please help. Don't ask for better pictures this is the best they will get just enlarge them and you should be able to read them. thanks for any and all help
Explanation / Answer
#include <fstream>
#include <string>
#include <iostream>
#include <stdlib.h>
#include <windows.h>
using namespace std;
int main()
{
ifstream input("C:\coursedata.txt");
string next, current, line;
if (!input.is_open()) {
cout << "unable to open input file" << endl;
exit(0);
}
if(!CreateDirectory("C:\Data", NULL) && ERROR_ALREADY_EXISTS != GetLastError())
{
cout << "Unable to create directory C:/Data" << endl;
exit(0);
}
ofstream output("C:\Data\enrollmentdata.txt");
if (!output.is_open()) {
cout << "unable to open output file" << endl;
exit(0);
}
int count=0, total=0;
if(std::getline(input, current)) {
std::getline(input, line); // for section number
count++;
std::getline(input, line); // ignore instructor
std::getline(input, line);
total = atoi(line.c_str());
while (std::getline(input, next))
{
if(next != current) {
output << current << endl;
output << count << endl;
output << total << endl;
// reset count
count = 0;
total = 0;
current = next;
}
std::getline(input, line); // for section number
count++;
std::getline(input, line); // ignore instructor
std::getline(input, line);
total += atoi(line.c_str());
}
cout << "Done" << endl;
} else {
cout << "No records in the file" << endl;
}
}
Sample Input file:
coursedata.txt in c drive:
CSIT 104
01
Decker
26
CSIT 104
02
Decker
24
CSIT 473
01
Nazarenko
19
CSIT 999
01
Nobody
00
Sample output created in c://Data folder
CSIT 104
2
50
CSIT 473
1
19
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.