Question

Write a modularized, menu-driven program to read a file with unknown number of records.

==============C++ or java================

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; 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’) or a blank space (up to you)

  • No error checking of the data required; all records are unique

  • Store records in an array of objects

  • Create a menu which allows to

    • example

    • print records unsorted

    • sort by any field using array-based selection sort

    • sort by any field using array-based insertion sort

    • sort by any field using array-based quick sort

    • sort by any field using array-based bubble sort

    • quit the program and print a table of number of comparisons and the number of items movements for each sort performed

    Sort Field Number of Comparisons Number of Items Movements    

    quick GPA 25 100

    • Before each sort, reload the array from the input function

    • After each sort, print the sorted array, number of comparisons, and the number of items movements

    • Write one function for each type of sort, that can sort by any field. Do not copy and paste body of sort code five times into the same function. The same body of the code should be able to handle sorting by any field based on the use choice. Start with bubble sort because it is the easiest to modify. To ensure that you write the sort code correctly, submit your bubble sort code here, as a Text Entry, before submitting the entire lab. This way I can let you if you have implemented the sort function correctly.

    • A user should be able to run many as many times as user wants

    • NO goto, continue, while(true), break (except for switch) or similar. It will result in grade of zero. No additional attempts would be allowed

    • Use const ( array size) and enums (menu choices, sort choice) were appropriate

    • The length of a file is unknown; make sure your programs handles empty files and files that have more records than an array can fit.

    • Follow established best practices and create cohesive functions. For example, a sort function should only sort. It should not ask a user what field to sort by and should not print.

    • Clearly label the output

    • Well document your code (comments)

    • Include your test data and our input file

    • Test your program thoroughly; at least 100 records.

    Record must be in the following order: Firs Name, Last Name, GPA, ID, email

    example: Mary Jones 3.9 887196478 [email protected]

    0 0
    Add a comment Improve this question Transcribed image text
    Answer #1

    #include
    #include
    #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 << "\n\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 << "\n\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 << "\n\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 << "\n\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 << "\nYou entered a wrong option. Please enter the initial in the Menu \n\n";
               break;
           }
       }
       inFile.close();
       system("pause");
       return 0;
    }

    Add a comment
    Know the answer?
    Add Answer to:
    Write a modularized, menu-driven program to read a file with unknown number of records.
    Your Answer:

    Post as a guest

    Your Name:

    What's your source?

    Earn Coins

    Coins can be redeemed for fabulous gifts.

    Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
    Similar Homework Help Questions
    • In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, t...

      In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, then present a menu to the user, and at the end print a final report shown below. You may(should) use the structures you developed for the previous assignment to make it easier to complete this assignment, but it is not required. Required Menu Operations are: Read Students’ data from a file to update the list (refer to sample...

    • Write a menu based program implementing the following functions: (0) Write a function called displayMenu that...

      Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...

    • The name of the C++ file must be search.cpp Write a program that will read data...

      The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...

    • In C only Please! This lab is to write a program that will sort an array...

      In C only Please! This lab is to write a program that will sort an array of structs. Use the functions.h header file with your program. Create a source file named functions.c with the following: A sorting function named sortArray. It takes an array of MyStruct's and the length of that array. It returns nothing. You can use any of the sorting algorithms, you would like though it is recommended that you use bubble sort, insertion sort, or selection sort...

    • Visual C# Homework 2 You are to write a program which will create a class called...

      Visual C# Homework 2 You are to write a program which will create a class called Student Each student has a name age height and weight. These variables should be declared as private. Create the correct constructors and functions. In the main, you will create 5 students. Input the data for the 5 students from a file which already has information in it. Name the file “Information.txt”. After setting up all the data, it is time to sort based on...

    • Write a JAVA Program: Compare the performance of bubble sort and selection sort over several arrays....

      Write a JAVA Program: Compare the performance of bubble sort and selection sort over several arrays. - Write two methods that sort arrays of doubles. One method should use selection sort, and the other should use bubble sort. - In each of the sort methods, add code that counts the total number of comparisons and total number of swaps performed while sorting the entire array (be careful; don't count each pass through the array separately) - Each time an array...

    • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

      Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

    • • Add a menu bar to the program with a File menu. • In the File...

      • Add a menu bar to the program with a File menu. • In the File menu, add a submenu (JMenuItem) called About. • When the user clicks on the About menu item, display a JOptionPane message dialog that contains your name, your course, the section number, and ID. Add comments to the top of each source code file that includes your name, course number, section number, and ID. 2. In Chapter 5, you created a lottery game application. Create...

    • In C++, write a complete program that receives a series of student records from the keyboard...

      In C++, 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...

    • Write a java program to sort arrays using 3 different methods: Bubble Sort, Selection Sort and...

      Write a java program to sort arrays using 3 different methods: Bubble Sort, Selection Sort and Insertion Sort. The numbers to be sorted will be obtained using a library function which generates pseudo-random numbers. TO Do 1. Fill an array with 140 real numbers between 0.00 and 945.00. Generate the numbers using the subroutine that generates random numbers. Make a spare copy of the array; you will need it later. 2. Call a subroutine to print the contents of the...

    ADVERTISEMENT
    Free Homework Help App
    Download From Google Play
    Scan Your Homework
    to Get Instant Free Answers
    Need Online Homework Help?
    Ask a Question
    Get Answers For Free
    Most questions answered within 3 hours.
    ADVERTISEMENT
    ADVERTISEMENT
    ADVERTISEMENT