Menu
support@authoritypapers.com
+1(805) 568 7317

write a menu driven c application to do the activities shown in the associated examp 5155556

Write a menu-driven C++ application to do the activities shown in the associated example output. All of the activities involve reading the provided file, names.txt, which gives babies' names in the U.S. and their popularity rankings for 11 decades beginning in 1900. In this file a popularity of 0 indicates a ranking that was 1000 or more. Each of the 4429 lines in this file starts with a baby's first name and is followed by eleven (11) integers representing the popularity ranks for that name for the 11 decades from 1900 through 2005. There should be four (4) menu items the user may choose: Print histogram for a name: The histogram line should be longer the more popular that name is. So, a rank of 1 gets the most stars (100) and a rank of 999 gets only one star. Names whose ranks are zero (0) should show no stars since the zero implies a popularity of 1000 or more. You should aim to get 100 stars for rank 1 and 1 star for rank 999. This can be done by accessing a name's rank for a specific decade and plugging it into the expression: (1000 – rank) / 10 + 1. If the entered name is not found in the list of names, then an error is printed and the menu is redisplayed for another user selection. See the example output. Compare two names in a decade: The user should be prompted to enter each of the two names and the decade value (1 through 11). Handling of errors (a name is not found or an invalid entry for decade) is shown in the example output. Print top ten names for a decade: List the top 10 names for a given decade in order of decreasing popularity (or increasing rank: first 1, then 2, then 3, etc.). The user should be prompted for the decade in which to search. NOTE: This will display 20 names since for each popularity rank there are two name. See the example output. Quit (write anomalies): This menu choice causes the application to terminate. However, before terminating, the application must print all anomalies found in names.txt to an output file named anomalies.txt. The file's format is defined to have two names for every decade/rank pair. For example, if examining decade 7 (1960-1969) and the rank, 9, this would yield the names, Michelle and Thomas. Any pair of a decade and a rank should correspond to two names as in the previous example. However, there are anomalies in the file such that some decade/rank pairs have only one name and a few of these pairs have no name at all. Writing the anomalies to an output file means that your program will search the array of names looking for these anomalies and print a list of these problems with the file's format to the output file. As it turns out, there are 1,065 anomalies: in most cases, only one name with a particular rank in a decade or in a few cases, no names in a decade with a particular rank. Your code to do this will need to check each name in each decade for each rank in order to find all 1065 anomalies. The format of the two different kinds of anomalies you will write to the file named, anolamies.txt, follows: 23 – One name(Wilma) for 1900-1909, rank 139. 676 – No names for 1940-1949, rank 779. – Note: Write out one anomaly per line and number each anomaly written. In the two examples above, the first one was the 23rd anomaly found and the second was the 676th anomaly found. You may find them in a different order, but you numbers should go from 1 to 1065. – Also note, the first type of anomaly that the one name found is given in the description of that anomaly, NOTE: Examine the example output with the goal of making your output look like the example output. When the user is asked to enter an integer, assume that the user will not enter characters that are not a number. However, if the number entered is out of range, those errors should be validated. Once again, the example output shows the handling of such errors, including names entered by the user that are not found in the list. Ignore the case of user input; for example, “jOHn”, “John”, “JOHN”, and “john” should all be the same name as far as the program is concerned. Design: Use the following struct to store the data contained on one line of the file, names.txt: const int NAME_LEN = 21; const int NUM_RANKS = 11; . . . struct Name { char name[NAME_LEN]; int rank[NUM_RANKS]; }; The function, loadNames, should be called to read the entire names.txt file and store the data from each line into a struct of type Name. The main function should pass an array of Name structs to loadNames so that it can simply read a line's data into the struct at the first element of this array, then read the second line's data into the second element, etc. This should be done for all 4429 lines of the names.txt file. OnceloadNames has completed and returned to main, the file, names.txt, must never be read again during this execution of the application. Be sure to use named constants for all numbers like 21, 11, 4429, etc. Once the array of Name structs is populated by the loadNames function, then the function, main, can present the menu and get a selected menu choice from the user. Here is an example of the main program loop: Name list[SIZE]; bool done = false; loadNames( list ); // main app loop do { switch( getMenuSelection() ) { case HISTOGRAM: displayHistogram( list ); break; case COMPARE: compareNames( list ); break; case TOPTEN: displayTopTenNames( list ); break; case EXIT: done = true; break; } // end main app loop } while( !done ); This example uses the constants: const char HISTOGRAM = 'a'; const char COMPARE = 'b'; const char TOPTEN = 'c'; const char EXIT = 'd'; You should setup your main function in a similar fashion. Make sure you do NOT use recursion — this is when a function either invokes itself or invokes another function that invokes the first one. Use loops to cycle back to the menu presentation after executing the user's choice. In the example above, the array of Name structs is created in main, populated by loadNames, and the passed to each major function in the list of menu choices. Once an individual task is complete, control returns to main where the application continues to offer the menu once again only if the user has not selected the terminate option. You should notice that the Name struct uses a C-String to store the name found on a line of the text file. You must use this struct and the c-string field, name, exactly as defined above. Using a c-strings requires library functions like, strcpy, strcmp, etc. (see textbook). If you want to use other strings in the application, you are welcome to use the data type, string, for these — but not for the Name stuct's name field. The string type is found in many examples in the textbook. Your grade on this project will depend heavily on your implementation of a modular design. This implies that you use smaller functions to accomplish larger tasks. This means writing functions to do tasks that are repeated, such as searching for a name, changing a name's case, organizing a line of a histogram, etc. This also means creating functions to hold meaningful subdivisions of the work. Examples of these are the functions called for each of the menu cases in the switch statement above. As you organize the structure of your solution, remember: NO recursion allowed, every function should have ONLY one return statement, break is only used in a switch statement (NOT to terminate loops), and continue and exit are never used in this course Again, the file, names.txt, must read the file once only. This would be done by the loadNames function called by main before the main program loop ever begins. Use named constants wisely. Some examples were given above. You will want others. Read through the requirements (above) and the example output and list any questions you have along the way. Re-read both documents to answer questions; email me questions you cannot answer for yourself. Divide the problem into parts using the menu items: part a (print a histogram), part b (compare two names), etc. Do one part at a time. Write utility (helper) functions to keep from having redundant code. Beginning and Completing this Project Use stepwise refinement as your method of design and implementation. What this means is that you carve out a small part of the project, proceed to design it and then implement it. When this part is implemented, you should be able to compile it and run it. After testing the completed part, choose another chunk to design and add its implementation to what you already have. Now compile and test what you have completed so far. When you have gone back to design and implement all parts of the problem, you will be ready to do the final testing of the entire application. For this project, here are the parts I would isolate and the order in which I would design, implement and test: Read file into an array of Name structs Create the array in main, pass it to the loadNames function and let that function populate the contents of each Name struct in the array using the data from successive lines of the text file, names.txt Test this, by printing out random names and their popularity rankings For example, if main named the array, list, then upon returning from the loadNames function, do something like: cout

"Order a similar paper and get 15% discount on your first order with us
Use the following coupon
"GET15"

Order Now