Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

can someone please write this program in C, thanks. Your code must contain at least one of all of the following control types: nested for

can someone please write this program in C, thanks. image text in transcribed
image text in transcribed
image text in transcribed
Your code must contain at least one of all of the following control types: nested for loops a while() or a do-while) loop a switch statement an if-else statement five functions in addition to the main function) Consider which control structures will work best for various aspects of the assignment. (Hint: What control type can be used with a menu driven program? How many statements should a case for a switch statement contain? Where would nested loops be appropriate for this program?) The first thing your program will do is print a menu of choices for the user. You may choose your own version of the wording or order of choices presented, but each choice given in the menu must match the following: Valid User Input Choices hoort N'or Menu Cholce Enter Change Character Enter Change Number Print Plus (+) Figure Print X Figure Quit Program oor A prompt is presented to the user to enter a choice from the menu. If the user enters a choice that is not a valid input, a message stating the choice is invalid is displayed and the menu is displayed again. Your program must have at least five functions (not including main() including: A function that prints the menu of choices for the user, prompts the user to enter a choice and retrieves that choice. The return value of this function must be voll. It will have one pass-by-reference parameter of type char. On the function's return, this parameter will contain the user's entry, which is then used to determine the next action performed by the program. This function should allow the user to enter any value. In other words, it will not check for proper input. It will store the user input in the pass- by-reference variable and return, even if the input is not a valid menu choice. A function that prompts the user to enter a single character. The return value of the function must be of type char and will return the character value entered by the user This return value will be stored in a local variable, C (or whatever variable name you choose), in main(). The initial default value of this character will be " (blank or space character) A function that prompts the user to enter a odd number between 3 and 15 (inclusive). If the user enters an even number or a value outside this range, the user is prompted to re-enter a value until a proper value is entered. The return value of the function must be of type it and will return the value entered by the user. This return value will be stored in a local variable, N (or whatever variable name you choosel, in main(). The initial default value of this integer will be 0. Two "Print Figure" functions. Each function will take the current integer value N and character value C as input parameters. The return values of these functions will be vold. The functions will print figures of N lines and columns using the input character C. The Plus function will print the figure as a plus (+) sign. The X function will print the figure as a X. For example, if the integer value N-5, and the character value and the x function is called the following figure will be printed: If the Plus function is to called then the following figure is printed: Note that if the user attempts to print the figure before entering any values for Cor N (or whatever variable name you choose your program will still call the functions to print the figure. However, if N- (the default value), the function will print a figure with no lines or columns (ie nothing). IFC (the default), the function will print a figure with N lines or columns, but since C is the blank character, no figure will be seen. Suggested Steps to Complete the Assignment: You are not required to complete the following steps to write your program or even pay attention to them. However, following the steps will likely help you complete the lab faster and with fewer debugging issues. If you do use the suggested steps, you should test your program thoroughly to ensure each step works correctly before moving on to the next step 1. Create a directory named "Lab3 cusemame dabsection and make it your current working directory 2. Copy your Makefile from Lab2 into this directory and modify it to work with the Lab3 executable (see below). 3. Write a void function, called from main, that prints the menu. Testit tonsure it works properly. 4. Add appropriate variables to the main function (one for N. Cand the mohu choice). Make sure the variables are initialized appropriately 5. Modify the menu function, adding a pass-by-reference parameter and adding code to prompt the user for input and storing the input character in the pass-by-reference parameter (allow any character input) 6. In the main function, add a print statement after the call to the menu function to verify that the user input in the menu function is being returned correctly to the main function. Debug your code until the print statement prints the correct input. You can the comment out the print statement (You may leave it in the code for later debugging.) 7. Enclose the print menu function within a loop that will exit the program only when the Quit program choice is entered. Test the logic of your code to ensure that the loop only exits on proper input 8. Create four "stub functions for the four other non-Quit) choices. Put a print statement such as "This is function EnterCard" or some other informative statement in the body of the function. For functions that return a value, return a specific character X' or mimber This will be changed when the function is filled in. 9. Within the loop in maino), create the logic to call each function based on input from the menu choice and handle incorrect input choices Consider what type of control structure fits best with this task (a chain of if-then-else statements? A switch) statement Test this logie by observing the output of the stub function statements

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions