Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Am having problems with this code, it keeps on shutting down my IDE everytime I build it, I suspect I messed up the arrays or

Am having problems with this code, it keeps on shutting down my IDE everytime I build it, I suspect I messed up the arrays or loops. Any help is appreciated. Thank you

Write a C++ program that reads from a text file containing student records and puts the data into these parallel arrays. A student record consists of a students name, followed by that students major, followed by that students GPA.

> The program puts the students names in an array called nameArray.

> The program puts the students majors in an array called majorArray.

> The program puts the students GPA in an array called gpaArray

The arrays are populated in the order the data is read from the file. For example, the first name read from the file is assigned to the first element of the nameArray, the second name read is assigned to the second element of the nameArray, and so on. The other arrays are populated in the same fashion.

Use the studentData2.txt file to test your code, but your code must work for any file which contains student records, where the record contents are arbitrary names, arbitrary majors and arbitrary GPAs. The number of records is arbitrary, but you can assume it does not exceed 100. For simplicity, assume the student name contains no whitespace. The content of "studentData2.txt is as follows:

Kai CS 3.8

Alice ME 3.9

Seppo CE 3.2

Ken BME 3.0

Anna EE 3.8

Make sure when you read from the file, you store the items in the arrays in the proper order.

The program then uses a loop to display the students names, another loop to display the students majors, and another loop to display the students GPAs. All the data is displayed in the order they are in the arrays. Then the program displays a menu of choices. As long as the user does not choose to quit, the program loops over the menu display

1) Search for the lowest GPA (the program then displays the GPA, name and major)

2) Search for the highest GPA (the program then displays the GPA, name and major)

3) Search on a students name (the program displays the name, GPA and major if found, or Not found)

4) Quit

Additional requirements Make sure you meet all the requirements to avoid losing points

1. To complete the assignment, you are required to use only what has been taught in class. If you have prior programming experience, refrain from using more advanced C++ constructs, so all the homework programs can be graded on a consistent basis.

2. Make sure you follow the requirements in the Homework Notes Function Headers.

3. You are required to implement your program with the following functions that are called in the main () function:

> getUserChoice: displays the menu, prompts the user to enter the choice, performs input validation, displays the menu again if the input is invalid. Returns the users choice if it is valid. For the input validation, if your menu displays a choice of integers (for example, 1 for Search for the lowest GPA, 2 for Search for the highest GPA, etc.), assume the user will always type an integer, which may or may not be a choice in the menu. If your menu displays a choice of chars (for example, a for Search for the lowest GPA, b for Search for the highest GPA, etc.) assume the user will always type a char, which may or may not be a choice in the menu.

> searchLowestGPA: takes as arguments the gpaArray and its size, and returns the index of the lowest GPA. For example, if gpaArray[2] is the lowest element of the gpaArray, the function returns 2.

> searchHighestGPA: takes as argument the gpaArray and its size, and returns the index of the highest GPA.

> searchName: takes as arguments a name, the nameArray and its size, and returns the index of the nameArray element that matches the name argument. Returns -1 if no match.

> display: takes as argument an index and the nameArray, majorArray and gpaArray, and displays the elements of nameArray, majorArray and gpaArray at the index.

> Your main() function implements the following pseudocode

Open file

Read from the file and populate the arrays

Display the nameArray

Display the majorArray

Display the gpaArray

While user does not quit

call getUserChoice

depending on the users choice, call the appropriate function, and display the result

Output

image text in transcribed

Names array name Array C01 Kai name Array[11 Alice name Array[2] Seppo name Array[3] Ken name Array Anna Major array CS major Array[0] majorArray[1] ME major Array[2] CE maiorArray BME major Array[4] EE GPA array gpaArray C01 3.8 gpaArray [1] 3.9 gpaArray C21 3.2 gpaArray[3] 3 gpaArray[4] 3.8 Enter your choice Search for the lowest GPA Search for the highest GPA 3 Search on a student's name Quit Name is Ken major is BME GPA 3 Enter your choice 1 Search for the lowest GPA Search for the highest GPA 3 Search on a student s name Quit Name is Alice major is ME, GPA 3.9 Enter your choice 3 Search on a student's name Quit Input name sep Name not found Enter your choice 3 Search on a student's name Quit Input name: Seppo Name is Seppo major is CE, GPA 3.2 Enter your choice Or 3 Search on a student's name Quit Invalid choice reenter Invalid choice reenter Process returned 0 (0x0) execution time 1.378 s Press any key to continue

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

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

1st Edition

1597496251, 978-1597496254

More Books

Students also viewed these Databases questions