Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ Please. This homework assignment gives you the opportunity to practice file 1/0, sorting/searching, parallel arrays, functions with array arguments and reference variables. HW1

In C++ Please.image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

This homework assignment gives you the opportunity to practice file 1/0, sorting/searching, parallel arrays, functions with array arguments and reference variables. HW1 (Graded out of 100) Write a program that manages students'records. Each student's record consists of a netID, a major and a GPA, maintained in parallel arrays. The program will read students' data from a file and loop on displaying the following menu of choices: 1. List the top n students 2. Search for a student. 3. Exit the program. If the user chooses 1 , the user will be prompted for the value of n, and the netID, major and GPA of the top n students will be listed, starting with the student with highest GPA and going down. If the user chooses 2 , user will be prompted to enter the student's netID. If the netID is found in the netID array, the array index, major and GPA of the student are displayed. If the student is not found, a "Student not found" message is displayed. If the user chooses 3, the program prints "Exiting'n" and terminates. 1. Additional Requirements - Make sure you comply with all the requirements to avoid losing points a) Arrays definition Define these arrays in the main function (for consistency, please use the same names to make the grading easier): const int NUM_ELMTS - 18; // netID, major and GFA are parallel arrays int ne-ID[NUM aMTS]; // Original netID array string major[NUM_ELATS]; // Original major array double GPR[NUM_ELMTS.; // original GPA array a) Arrays definition Define these arrays in the main function (for consistency, please use the same names to make the grading easier): b) Arrays initialization The arrays will be initialized by reading from a fle, and the program prompts the user for the file name. c) File The file is a text file containing student records. A student record consists of a student's netiD, followed by that student's major, followed by that student's GPA. An example of student record is as follows (for simplicity, assume the student's netID is an int): In the above record, the netID is 1001 , major is CS, and GPA is 3.8. You may assume the data is properly formatted and therefore there is no need for input validation when reading from the file. The number of records in the file is unknown but you may assume it is at most NUM_ELMTS. d) Search for a student When the user selects choice 2 , your program will perform both a linear search and a binary search, and display the result from both. You may use the C++ code provided in the lectures, with the necessary adaptations. The linear search is performed on the original array, netID[NUM_ELMTS]. The binary search can only be performed on a sorted array, but netID is not sorted. Normally when an array is sorted, the values in the array are modified. Since we want to preserve the values of the netID array (in order to do linear search on the original array), we make a copy of netID called sortedNetIDbyID, and sort the copy by netID. The binary search will be performed on sortedNetIDbyID. To be able to display the major and GPA of the student found, we will maintain sortedMajorbylD and sortedGPAbylD, which are the arrays parallel to sortedNetIDbyID. That is, sortedMajorbyID[i] and sortedGPAbyID[i] are respectively the major and the GPA of the student whose netID is sortedNetIDbyID[i]. You can use one of the sorting algorithms (bubble sort or selection sort) taught in class. However, to maintain the parallelism of the arrays, whenever you swap elements of sortedNetIDbyID, you should also swap the elements at the same indices of sortedMajorbylD and sortedGPAbyID. Your code should also keep track of how many iterations the search went through and the main function should display the number of iterations, for both linear search and binary search. e) List the top n students To list the top students, your program will sort the GPA array by GPA. To preserve the original GPA array, sort a copy of GPA called sortedGPAbyGPA. To be able to display the netID and major, you should also maintain arrays parallel to sortedGPAbyGPA called sortedMajorbyGPA and sorted Net IDbyGPA. Like before, you can use one of the sorting algorithms taught in class, but need to maintain the parallelism. Whenever you swap elements of sortedGPAbyGPA, you should also swap the elements at the same indices of sortedMajorbyGPA and sortedNetIDbyGPA. e) List the top n students To list the top students, your program will sort the GPA array by GPA. To preserve the original GPA array, sort a copy of GPA called sortedGPAbyGPA. To be able to display the netID and major, you should also maintain arrays parallel to sortedGPAbyGPA called sortedMajorbyGPA and sortedNetIDbyGPA. Like before, you can use one of the sorting algorithms taught in class, but need to maintain the parallelism. Whenever you swap elements of sortedGPAbyGPA, you should also swap the elements at the same indices of sortedMajorbyGPA and sortedNet IDbyGPA. You may assume the user always types a positive integer. If the user types a value of n greater than the number of students, the program should list al the students sorted by GPA, starting with the highest. f) Outline of main g) Display arrays GPAs should be displayed with a decimal point followed by 2 digits. i) Search functions Implement the following functions. You must use the same function name, parameter list and retum type to pass the unit tests. Implement the following functions. You must use the same function name, parameter list and retum type to pass the unit tests. j) Style Make sure you follow the style requirements in the "Homework Notes" to avoid losing points. 2. Grading criteria - Source code inspection (grader) "Style: 10 points (refer to the "Homework Notes" for the style requirements) - Code compilation and execution (7ylabs) Output-2 Output-3 Meni of choices 1 - List top n students 2 - Search on a netiD 3 - Quit 2 Enter netID: 1111 Result of linear search: Student not found It took10 iterations Res:11t of birary search: Student not found It took iteratiors Meril of choices 1 - List top n students 2 - Search or a netid 3 - guit 3 Exiting

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

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students also viewed these Databases questions

Question

Does it avoid using personal pronouns (such as I and me)?

Answered: 1 week ago

Question

Does it clearly identify what you have done and accomplished?

Answered: 1 week ago