Question: Goal: Learn how to design a data structure by using struct, array and vector so that raw data can be properly loaded and manipulated. :

Goal: Learn how to design a data structure by using struct, array and vector so that raw data can be properly loaded and manipulated.

: Read the raw data in StudentRecords.txt, place the data in a proper data structure and display student GPAs. Each student is allowed to take any number of courses. But for simplicity we can assume that there are only a fixed number, i.e. 99, of students in this class.

Steps to complete the work:

Step 0: The program at the bottom is written by a novice programmer. It is a good start. But its data structure design is not of the best and it is incomplete in many ways. Read it and test it to know what have been done.

Step 1: Read the 2 structs to know how courses are stored in the data structure. Change the array in Student to a vector and modify the code so that it can compile. Since we allow a student to any number of courses, the course array has to be changed to vector.

Step 2: Modify the code in the while loop so that all data are loaded properly, which is for preparing the display of the reports.

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.

#include

#include

using namespace std;

const int maxCourseAmt = 99;

struct Course

{

string Course = "";

int Credit = 0;

int Score = 0;

int Grade = 0;

};

struct Student

{

int ID = 0;

string Name = "";

Course arrCourse[maxCourseAmt];

};

int isInArray(Student arr[], int target)

{

int i = 0;

while (arr[i].ID != 0)

{

if (arr[i].ID == target)

return i;

i++;

}

return -1;

}

int main()

{

fstream inputFile;

string fileName = "StudentRecords.txt";

string token;

Student arrStu[9];

inputFile.open(fileName, ios::in);

if (inputFile.is_open())

{

int index = 0;

int ID;

string Name;

string CourseName;

int Credit;

int Score;

while(!inputFile.eof())

{

inputFile >> ID >> Name >> CourseName >> Credit >> Score;

int ii = isInArray(arrStu, ID);

if (ii == -1) // The student record does not exist

{

arrStu[index].ID = ID;

arrStu[index].Name = Name;

arrStu[index].arrCourse[0].Course = CourseName;

arrStu[index].arrCourse[0].Credit = Credit;

arrStu[index].arrCourse[0].Score = Score;

index++;

}

else /// The student exists

{

/// Add course and score to the existing student record

}

}

inputFile.close();

}

else

cout << "File cannot be opened.";

int target = 15667;

int ii = isInArray(arrStu, target);

if (ii == -1)

cout << target << " does not exist." << endl;

else

cout << "The record is found. The index is " << ii << endl;

target = 99999;

ii = isInArray(arrStu, target);

if (ii == -1)

cout << target << " does not exist." << endl;

else

cout << "The record is found. The index is " << ii << endl;

return 0;

}

here is the content of the text files:

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!