Question
Lab #8a HOORAY CS 1A 25 pts Submit the following in Canvas: Lab #8a: HOORAY 1 Output (your console output cut-and-pasted into a text file
Lab #8a HOORAY CS 1A
25 pts |
Submit the following in Canvas:
Lab #8a: HOORAY
1 Output (your console output cut-and-pasted into a text file called ScreenIO.txt created in Eclipse)
2 Source Code (your main.cpp, functions.cpp, functions.h, printHeader.cpp, printHeader.h source files)
MAKE SURE your program conforms to the style detailed in course topic 2
Write a program that reads in a list of up to 25 first names from an input file nameData.txt and allows the user to display the name data, sort it in ascending or descending order, count the number of occurrences of a given name, or exit the program. The input file consists of a single name per line with each line terminated with an end of line (i.e. using Enter key to end the line). Your program should present the user with a menu that provides the options show below in INPUT/OUTPUT.
You must use the following enum for the menu selection:
enum MenuPick {READ_DATA, DISPLAY,
SORT_ASC, SORT_DEC, COUNT, EXIT
};
You must write a function with header
MenuPick getMenuPick()
// Read names from file // Display names // Sort names ascending // Sort names descending // Count name
// Exit program
to display the menu, validate the menu pick, and return the enumerator associated with the selected menu item. Your main function must then use the returned enumerator to perform the appropriate operation.
You must write a single bubble sort function with header
void bubbleSort(string strAr[], const int SIZE, const bool ascending) to perform the sorting and you must use a string method to perform the array element swap within your bubbleSort function (hint: http://www.cplusplus.com/reference/string/string/swap/) . Use the bubbleSort program from the lecture notes as a guide for implementing your bubble sort function.
You must write a counting function with header
int count(const string strAr[], const string key,const int SIZE)
Page 1 of 5
Lab #8a HOORAY CS 1A to count the occurrences of a given name.
Both the sort and counting functions should be in a separate source file functions.cpp with a separate header file functions.h.
Test your program thoroughly, including using an input file with no names and one with greater than 25 names. You must demonstrate your program to the instructor in the lab to get any credit for this lab. The output below is for the sample input file included with the lab on Canvas. The instructor may provide you with a different input file on a flash drive to demonstrate your program.
Screen INPUT/OUTPUT - should be formatted as follows (Class heading should be also displayed)
Please select from one of the following options: 1. Read names from file 2. Display names 3. Sort names ascending
4. Sort names descending 5. Count name 6. Exit program Selection:2
No names to display!
Please select from one of the following options: 1. Read names from file 2. Display names 3. Sort names ascending
4. Sort names descending 5. Count name 6. Exit program Selection:1
10 names read from file e: ameData.txt
Please select from one of the following options: 1. Read names from file 2. Display names 3. Sort names ascending
4. Sort names descending 5. Count name 6. Exit program Selection:2
1: Joe 2: Sally 3: Joe 4: Sue 5: Sally 6: Adam 7: Joe 8: Adam 9: Adam
10: Joe
Please select from one of the following options: 1. Read names from file 2. Display names
Page 2 of 5
Lab #8a
HOORAY
CS 1A
3. Sort names ascending 4. Sort names descending 5. Count name 6. Exit program Selection:3
Sorting in ascending order...
Please select from one of the following options: 1. Read names from file 2. Display names 3. Sort names ascending
4. Sort names descending 5. Count name 6. Exit program Selection:2
1: Adam 2: Adam 3: Adam 4: Joe 5: Joe 6: Joe 7: Joe 8: Sally 9: Sally
10: Sue
Please select from one of the following options: 1. Read names from file 2. Display names 3. Sort names ascending
4. Sort names descending 5. Count name 6. Exit program Selection:4
Sorting in descending order...
Please select from one of the following options: 1. Read names from file 2. Display names 3. Sort names ascending
4. Sort names descending 5. Count name 6. Exit program Selection:2
1: Sue 2: Sally 3: Sally 4: Joe 5: Joe 6: Joe 7: Joe 8: Adam 9: Adam
10: Adam
Please select from one of the following options: 1. Read names from file
Page 3 of 5
Lab #8a
HOORAY
CS 1A
2. Display names 3. Sort names ascending 4. Sort names descending 5. Count name 6. Exit program Selection:1
10 names read from file e: ameData.txt
Please select from one of the following options: 1. Read names from file 2. Display names 3. Sort names ascending
4. Sort names descending 5. Count name 6. Exit program Selection:2
1: Joe 2: Sally 3: Joe 4: Sue 5: Sally 6: Adam 7: Joe 8: Adam 9: Adam
10: Joe
Please select from one of the following options: 1. Read names from file 2. Display names 3. Sort names ascending
4. Sort names descending 5. Count name 6. Exit program Selection:5
Enter a name to count: Joe Name Joe occurs 4 times
Please select from one of the following options: 1. Read names from file 2. Display names 3. Sort names ascending
4. Sort names descending 5. Count name 6. Exit program Selection:5
Enter a name to count: Sue Name Sue occurs 1 time
Please select from one of the following options: 1. Read names from file 2. Display names 3. Sort names ascending
4. Sort names descending 5. Count name 6. Exit program Selection:7
Page 4 of 5
Lab #8a HOORAY CS 1A
Please enter a number between 1 and 6!
Please select from one of the following options: 1. Read names from file 2. Display names 3. Sort names ascending
4. Sort names descending 5. Count name 6. Exit program Selection:exit
Please enter an integer value!
Please select from one of the following options: 1. Read names from file 2. Display names 3. Sort names ascending
4. Sort names descending 5. Count name 6. Exit program Selection:6
Thank you for using my name program.
Page 5 of 5
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