How would a pseudocode solution for this problem look? Using file input. Only pr
ID: 3559993 • Letter: H
Question
How would a pseudocode solution for this problem look? Using file input. Only process those records that have no errors. Filename: grades.dat Description: Each record contains the student ID, name and grades for a student. Field Description Student ID Student Name Homework Grade 1 Homework Grade 2 Homework Grade 3 Homework Grade 4 Homework Grade 5 Homework Grade 6 Test Grade 1 Test Grade 2 Test Grade 3 Test Grade 4 Test Grade 5 Extra Credit 1 Extra Credit 2 Extra Credit 3 Extra Credit 4 Extra Credit 5 Extra Credit 6 Project Grade Final Exam Grade -- Need to create a new file with the student ID and course grade. These two items need to be separated by a comma.
Explanation / Answer
Create a file "grades.dat"
It shoud be like this:
StudentId StudentName HomeworkGrade1 HomeworkGrade2 HomeworkGrade3 HomeworkGrade4 HomeworkGrade5 HomeworkGrade6 TestGrade1 TestGrade2 TesGrade3 TestGrade4 Test Grade5 ExtraCredi1 ExtraCredit2 ExtraCredit3 ExtraCredit4 ExtraCredit5 ExtraCredit6 ProjectGrade FinalExamGrade
so put values space seprated in file.
/* pseudo code */
/*declare variables*/
int studentid;
string studentname;
char ch[19];
/*Open file in read mode using ifstream*/
ifstream ifile;
ifile.open("grades.dat",ios::in);
/*Output file having studentId & CourseGrade*/
ofstream outfile;
outfile.open("newfile.dat",ios::out|ios::app);
/*Now Read the file line by line but check file is openable or not*/
if(ifile.is_open()){
while(ifile >> studentid){
/*store values from file in variables*/
outfile << studentid;
ifile >> studentname>>ch[0] >> ch[1] >> ch[2] >> ch[3] >> ch[4] >> ch[5] >> ch[6] >> ch[7] >> ch[8] >> ch[9] >> ch[10] >> ch[11] >> ch[12] >> ch[13] >> ch[14] >> ch[15] >> ch[16] >> ch[17] >> ch[18] ;
outfile << ",";
outfile << ch[18]; /*Final grade should be course grade as if you haven't mention anything about this*/
}
}
this is pseudo code;
/*Want Running Code then tell me but you have to rate for me this pseudo code*/
/*Implementatio*/
/*grades.dat should be like this*/
1000 pankaj A A A A A A A A A A A A A A A A A A A
1001 paj A A A A A A A A A A A A A A A A A A A
1002 paaj A A A A A A A A A A A A A A A A A A A
*/
/*newfile.txt will*/
1000,A
1001,A
1002,A
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.