I'm having trouble with having the user input data into the arrays and I am having issues printing and searching them. Here's the problem.
(Arrays, Searching and Sorting) Write a complete program that receives a series of student records from the keyboard and stores them in three parallel arrays named studentID and courseNumber and grade. All arrays are to be 100 elements. The studentID array is to be of type int and the courseNumber and grade arrays are to be of type string.
The program should prompt for the number of records to be entered and then receive user input on how many records are to be entered. That value should be used in an input loop to receive the series of records and store them in the parallel arrays.
Add a function to printout all records stored in the array. Only print records that were input from the keyboard. Much of the arrays will be unused. Add another function to search the arrays using a specific student ID and display the student’s ID, course number, and grade wherever found, OR the message “<student ID> doesn’t exist in array”
Add code in main to print all records and prompt a user to enter a student ID and search for it in the arrays. Test both possible outcomes.
Sample trace:
Enter the number of records to be input: 6
Enter record 1 (student ID, Course number and grade): 12 COSC175 A
Enter record 2 (student ID, Course number and grade): 15 COSC175 B
Enter record 3 (student ID, Course number and grade): 22 COSC175 C
Enter record 4 (student ID, Course number and grade): 12 ENG317 A
Enter record 5 (student ID, Course number and grade): 15 ENG317 A
Enter record 6 (student ID, Course number and grade): 12 PSYC101 A
Enter a student ID for a record search: 12
12 COSC175 A
12 ENG317 A
12 PSYC101 A
Note: If a search had been made for 17, the message “17 doesn’t exist in array” would have been displayed.
here is what I have so far:
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
int main() {
int numOfRecords = 1;
int recordNum = 1;
int i = 0;
int studentID[100];
string courseNum[100];
string grade[100];
cout << "Enter number of records to be input: " << endl;
cin >> numOfRecords;
do {
cout << "Enter record " << recordNum++ << endl;
cin >> studentID[i] >> courseNum[i] >> grade[i];
}
while (recordNum <= numOfRecords);
OP: take a look at the solution I suggested here - http://www.cplusplus.com/forum/general/204859/
the problem is very similar to yours so you can also, if you wish:
1. set up struct Student with data-members ID, course# and grade
2. use the Student ctor to populate the various fields
3. overload the << operator to print Student objects
4. save the Student objects in an array of Student objects (or use std::vector<Student> if you're allowed)
5. your search function should prompt for the search ID and then loop the array/vector to see if any of the Student objects in the container has this ID
Good luck!