Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a menu-driven program called p2.c that allows the user to enter and display data about a single American politician: Program Operation The program
Write a menu-driven program called p2.c that allows the user to enter and display data about a single American politician: Program Operation The program should keep track of the following quantities for a single politician: Prefix: a string of at most three characters and can be null. First Name: a single string with a maximum of 32 characters. Middle Initial: a single character and can be null. Last Name: a single string with a maximum of 32 characters. Suffix: a string of at most three characters and can be null. Age: an integer from 18 to 99 years inclusive. Sex: a single character, 'M' or 'F'. Office Held: a string of at most 32 characters. (Can include spaces). Years Served: a two-digit integer from 0 to 99. Political Party: should be stored and displayed as a three-letter string as given below: Constitution: CON Democratic: DEM Green: GRE, Libertarian: LIB Republican: REP State: two-character abbreviation for home state (e.g., AL, SC) to be chosen from a list displayed. Twitter Account: a string with a maximum of fifteen characters. (Ampersand is not entered but is shown when displayed, e.g. "@CheathamMoore") Phone Number: a ten-digit number input and displayed as (666) 555-4444. Donations Received: a floating-point number from 0.0 to 1.0x105, inclusive, displayed in USD. Total Wealth: a floating-point number from 0.0 to 1.0x101000, inclusive, displayed in USD. Note: Initially, all quantities are to be initialized as an "unknown value" and should be denoted as such when displayed. It's up to the programmer to decide what values to store to represent unknown values. Menu The program should have eight input options in the menu which perform the following tasks: Enter Name Display all Data Enter Years, Party, Office, and State Clear all Data Enter Age and Sex Quit Enter Contacts Enter Contributions and Wealth The specific format of the menu and its display is not specified, but it must be straight- forward and readable. Input The program should allow the user to select only one of the above options at a time. An error message should be displayed if an invalid option is chosen. For the options requiring data input, the program should prompt for the appropriate data when the option is selected. All inputs should be checked for validity, and if the data input is invalid, an appropriate error message should be given allowing the user to try again. Upon completing any option (except "Quit"), the program should redisplay the menu. Use the following line to compile your program Output The program should only display data if that option is selected. When it is selected, the program should print all data indicating which-if any-data is unknown. gum -Wall -g p2.c -o p2 [-1m]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Heres a basic example of a menudriven program in C that follows the specifications you provided Note that this is a simple consolebased program and you may want to add more error handling and refineme...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