Write a program to read from two input files (StudentFile1.txt and StudentFile2.
ID: 3633375 • Letter: W
Question
Write a program to read from two input files (StudentFile1.txt and StudentFile2.txt under lab10-2) to process students’ reports. One file (StudentFile2.txt) is about the current semester and contains individual student ID, the course code, letter grade, and credit hours for five courses. The other file(StudentFile1.txt) is about the record till last semester and contains student ID, name, address, telephone number, Gender code M/F, current standing (1 for Freshman/ 2 for Sophomore/ 3 for Junior/ 4 or 5 for Senior), total credit hours completed, cumulative GPA and major. There are 15 records in each file. The program should then compute, using the current semester data, and update the total credit hour, the cumulative grade point average for each student and output the updated information to a new file (call it StudentOutput.txt) in the following format:Johnson, James L
Waupun, Wisconsin
Tel: 7345229
XYZ University Student Report Card
01/15/2008
Student ID: 10103
Student Major: ENGR
Current Semester:
ENGL176 4 C
EDUC268 4 B
EDUC330 3 B
PE281 3 C
ENGR317 4 D
-------------------------------------------
Cumulative:
Credit Hours: 33
GPA is: 2.61
---------------------------------------------------------------------------------------------------------
First file (StudentFile1.txt) contains the following:
10103 Johnson, James L
Waupun, Wisconsin
7345229
M 1 15 3.15
ENGR
10104 Andrews, Peter J
Grand-Rapids, Michigan
9493301
M 2 42 2.78
CPSC
10110 Peters, Andrew J
Lynden, Washington
3239550
M 5 63 2.05
ART
10113 VandenVander, Vanessa V
Fremont, Michigan
5509237
F 4 110 3.74
HIST
10126 Aristotle, Alice A
Chino, California
3330861
F 3 78 3.10
PHIL
10144 Lucky, Lucy L
Grandville, Michigan
7745424
F 5 66 2.29
HIST
10179 Euler, Lennie L
Three_Rivers, Michigan
6290017
M 1 15 3.83
MATH
10191 Nakamura, Toky O
Chicago, Illinois
4249665
F 1 12 1.95
SOCI
10226 Freud, Fred E
Lynden, Washington
8340115
M 1 15 1.85
PSYC
10272 Speareshake, William W
Grand_Rapids, Michigan
2410744
M 5 102 2.95
ENGL
10274 Tchaikovsky, Wolfgang A
Byron-Center, Michigan
8845115
M 3 79 2.75
MUSC
10284 Orange, Dutch V
Graafschaap, Michigan
3141660
M 2 42 2.98
ENGR
10297 Caesar, Julie S
Denver, Colorado
4470338
F 4 117 3.25
HIST
10298 Psycho, Prunella E
De_Motte, Indiana
5384609
F 4 120 2.99
PSYC
10301 Bull, Sitting U
Gallup, New_Mexico
6632997
M 1 14 2.95
EDUC
---------------------------------------------------------------------------------------------------------
The second file (StudentFile2.txt) contains the following:
10103 ENGL176 C 4 EDUC268 B 4 EDUC330 B 3 PE281 C 3 ENGR317 D 4
10104 CPSC271 D 4 ESCI208 D 3 PHIL340 B 2 CPSC146 D 4 ENGL432 D 4
10110 ART520 D 3 ESCI259 F 1 ENGL151 D 4 MUSC257 B 4 PSYC486 C 4
10113 HIST498 F 3 PE317 C 4 MUSC139 B 3 PHIL165 D 3 GEOG222 C 3
10126 PHIL367 C 4 EDUC420 C 3 EDUC473 C 3 EDUC224 D 3 GERM257 F 4
10144 HIST559 C 3 MATH357 D 3 CPSC323 C 2 PE246 D 4 MUSC379 D 4
10179 MATH169 C 4 CHEM163 C 4 MUSC436 A 3 MATH366 D 2 BIOL213 A 4
10191 SOCI177 F 4 POLS106 A 4 EDUC495 A 3 ENGR418 B 2 ENGR355 A 4
10226 PSYC116 B 3 GERM323 B 4 ART350 A 4 HIST269 B 4 EDUC214 C 3
10272 ENGL558 A 4 EDUC169 D 3 PSYC483 B 4 ENGR335 B 2 BIOL228 B 4
10274 MUSC351 B 4 PSYC209 C 4 ENGR400 F 1 ESCI392 A 4 SOCI394 B 3
10284 ENGR292 D 4 PSYC172 C 4 EDUC140 B 4 MATH274 F 4 MUSC101 D 4
10297 HIST464 F 1 HIST205 F 1 ENGR444 F 1 MATH269 F 1 EDUC163 F 1
10298 PSYC452 B 3 MATH170 C 4 EDUC344 C 2 GREE138 C 2 SPEE303 A 3
10301 EDUC197 A 4 PE372 B 3 ENGR218 D 4 MATH309 C 4 ESCI405 C 4
------------------------------------------------------------------------------------------------------
Please include run result (output file)
Explanation / Answer
1.
#include <iostream>
2.
#include <fstream>
3.
#include <string>
4.
using namespace std;
5.
int main()
6.
{
7.
ifstream in;
8.
9.
char Data = char();
10.
char Ender = char();
11.
string First = string();
12.
string Last = string();
13.
int Grade = int();
14.
string Test = string();
15.
16.
17.
in.open("C:\Input.txt");
18.
19.
if(!in)
20.
{
21.
cout << "Error: Input File Cannot Be Oppened" << endl;
22.
23.
}
24.
in >> Data;
25.
while (!in.eof())
26.
{
27.
in >> First >> Last >> Grade;
28.
while ( Ender != '-' )
29.
{
30.
cout << First << Last << Grade;
31.
32.
}
33.
34.
}
35.
in.close();
36.
cout << "End-of-file reached.." << endl;
37.
38.
39.
cin >> Test;
40.
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.