please help. where there are // is where code needs to be written please help. D
ID: 3817566 • 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<stdlib.h>
#include<string>
using namespace std;
int main()
{
ifstream infile ("C:/Users/Surya/Desktop/coursedata.txt");//opening input file
ofstream outfile ("C:/Users/Surya/Desktop/out.txt");//opening output file
int count=0;
int total;
string current;
string next;
//reading first course
getline(infile,next);
while(next!="CSIT 999")
{
current=next;
count=0;
total=0;
while(next==current)
{
count++;//incrementing course count...
string n;
getline(infile,n);//reading course number
getline(infile,n);//reading MENTOR name
getline(infile,n);//reading enrollments..
int k,t=0;
char c[1];
//converting string to integer..
for(k=0;n[k]!='';k++)
{
c[0]=n[k];
t=t*10+atoi(c);//converting to int
}
total=total+t;//calculating total enrollments..
getline(infile,next);//reading next couse data
}
//writing to outputfile...
outfile<<current<<" "<<count<<" "<<total<<" ";
}
//closing files..
infile.close();
outfile.close();
return 0;
}
//SAMPLE
//INPUT FILE
CSIT 101
01
DD
24
CSIT 101
03
DD
42
CSIT 101
04
DD
27
CSIT 701
01
DD
4
CSIT 109
01
DD
2
CSIT 999
01
NOBODY
00
//OUTPUT FILE
CSIT 101
3
93
CSIT 701
1
4
CSIT 109
1
2
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.