Question
I'm trying to solve this question, but when I run it in my code, it doesn't show any output. can you show how do I
I'm trying to solve this question, but when I run it in my code, it doesn't show any output. can you show how do I did wrong and fixed code?
below is the question and my code.
Write a modularized, menu-driven program to read a file with unknown number of records.
- Create a class Records to store the following data: first and last name, GPA , an Id number, and an email
- Input file has unknown number of records, but no more than 100; one record per line in the following order: first and last names, GPA , an Id number, and email
- All fields in the input file are separated by a tab (\t)
- No error checking of the data required
- Create a menu which allows to
- print records unsorted
- search for a record by ID
- quit the program
- we will be adding sort options in part II
- A user should be able to run many as many times as user wants
- NO goto, continue, break (except for switch)
- Clearly label the output
- Well document your code (comments)
- Include your test data
My code:
#include
using namespace std; class Records { public: string FirstName, LastName, Email, ID; double GPA; void UnsortedPrint(Records StudentRc[],int x) const; void IDsearchRecord(Records StudentRc[],int x) const; };
void Records::UnsortedPrint(Records StudentRc[],int x) const { cout << " \t\tFirstName\tLastName\tGPA\tID\t\tEmail" << endl; for (int i = 0; i < x; i++) { cout << "\t\t" << StudentRc[i].FirstName << "\t" << StudentRc[i].LastName << "\t" << StudentRc[i].GPA << "\t" << StudentRc[i].ID << "\t\t" << StudentRc[i].Email << endl; } }
void Records::IDsearchRecord(Records StudentRc[],int x) const { string Num; bool found = false; cout << " \tEnter studnet ID : "; cin >> Num; for (int i = 0; i < x; i++) { if (StudentRc[i].ID == Num) { cout << "\tRecord Number\t\tFirstName\tLastName\tGPA\tID\t\tEmail" << endl; cout << "\t\t" << StudentRc[i].FirstName << "\t" << StudentRc[i].LastName << "\t" << StudentRc[i].GPA << "\t" << StudentRc[i].ID << "\t\t" << StudentRc[i].Email << endl; found = true; } } if (!found) cout << " \t" << Num << " is not found in the data." << endl; } int main() { Records Studnet; Records StudentRc[100]; fstream inFile; char Option = 'x'; int x = 0; inFile.open("C:\\Users\\JONGMIN\\Desktop\\540 C++\\inFile.txt");
while (!inFile.eof()) { inFile >> StudentRc[x].FirstName >> StudentRc[x].LastName; inFile >> StudentRc[x].GPA >> StudentRc[x].ID >> StudentRc[x].Email; ++x; } while (true) //Fixeit { cout << " \tA. Print records that is unsorted " << endl; cout << "\tB. Search student records by student ID " << endl; cout << "\tC. Quit the program" << endl; cout << "\tOption : "; cin >> Option; switch (Option) { case 'A': case 'a': Studnet.UnsortedPrint(StudentRc,x); break; case 'B': case 'b': Studnet.IDsearchRecord(StudentRc,x); break; case 'C': case 'c': exit(1); break; default: cout << " You entered a wrong option. Please enter the initial in the Menu "; break; } } inFile.close(); system("pause"); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started