Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Step 0: The program is written to let you see a common bug created by many C++ novice programmers. Fix the bug so that it

Step 0: The program is written to let you see a common bug created by many C++ novice programmers. Fix the bug so that it can compile.

Step 1: In the while loop of the program instantiate a student struct object. (The input file named StudentRecords.txt is also uploaded.)

In each iteration the system should read 5 pieces of data, which are student ID, name, course, credit and score. Save the data in the Student object. Use cout to display the values of the object. Carefully examine the output and you can see that there is an extra line of output at the bottom. (That is, the last two lines are the same, or almost the same.) What cause the problem to occur? Use the debugger to trace the program and figure out what causes the bug.)

Step 2: Let us assume the maximum amount of the students is 99. Since there are many students, we should use another data structure (either array or vector) to store the student records, so that we can manipulate the data. What data structure could be a nice choice to use so that all data can be properly stored?

Step 3: After storing the data in the data structures, use the following table to calculate the GPA of each student.

Range Grade ======== ===== 90 -- 100 ---> 4.0 80 -- 89 ---> 3.0 70 -- 79 ---> 2.0 60 -- 69 ---> 1.0 0 -- 59 ---> 0.0

We should take the credit of the course into account. For example, the following equation is how we calculate Amy's GPA.

(3.0 * 4 + 4.0 * 4 + 4.0 *3)/(4 + 4 + 3) = 3.64

Step 4: Course listing and GPA for a student should consist of three parts:

(1) ID and name, (2) A listing of all courses, and (3) The calculated GPA

For example, Amy's report should look like this:

12546 Amy

=========

CS1 4 81 3.0

CS2 4 90 4.0

CS3 3 90 4.0

======================

GPA 3.64

The last column is the converted grades calculated from the scores.

Step 5: The output should display reports for all students.

So in this code, we will have 2 structs, 1 vector and 1 array.

#include #include

using namespace std;

struct Student { int ID; string Name; string Course; int Credit; int Score; }

int main() { fstream inputFile; string fileName = "StudentRecords.txt"; string token;

inputFile.open(fileName.c_str(), ios::in); if (inputFile.is_open()) { while(!inputFile.eof()) { inputFile >> token; cout << token << endl; } inputFile.close(); } else cout << "File cannot be opened.";

return 0; }

StudentRecords.txt file

12546 Amy CS1 4 81 13455 Bill CS1 4 76 14328 Jim CS1 4 64 14388 Henry CS3 3 80 15667 Peter CS3 3 45 12546 Amy CS2 4 90 13455 Bill CS2 4 85 14328 Jim CS2 4 71

12546 Amy CS3 3 90 13455 Bill CS3 3 75 14328 Jim CS3 3 69

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

Students also viewed these Databases questions