Question

CSC 130 Lab Assignment 8 – Program Menu Create a C source code file named lab8.c...

CSC 130 Lab Assignment 8 – Program Menu Create a C source code file named lab8.c that implements the following features. Implement this program in stages using stepwise refinement to ensure that it will compile and run as you go. This makes it much easier to debug and understand. This program presents the user a menu of operations that it can perform. The choices are listed and a prompt waits for the user to select a choice by entering a number. This kind of menu is a common feature of command-line programs. It can be implemented to execute in the main() function or it can be implemented in a function known as the commandchooser function that returns a numeric value for a choice that can be passed to another function known as the command-dispatcher. 1. Define symbolic constants for FALSE and TRUE 2. Define an int main() function • int done = FALSE; is a flag defined inside int main and used to determine if the user has finished using the program or not. 3. while-loop not done • Loop while the done flag is equal to false /* command chooser */ 4. Implement printf() statements which list menu choices • The first part of the command chooser prints a menu that lists choices for the user. Each choice is a string that begins with the value to be entered on the keyboard to make the choice and ends with a brief description of an operation. • Example: “3 - Operation 3” 5. Next, implement a do-while loop with the result of the scanf() function part of the while condition. • scanf()returns an integer whenever it is called usually this value is not important, but for the command chooser it is essential. • If an improper value was input, scanf() will return a value less than 1. This allows us to create a do-while loop which validates the users input. • See Formatted I/O lecture slides for an example 6. Once implemented, place the printf() statements from step 4 into the do-while loop body. /* command dispatcher */ 7. Implement if else logic where each logical branch corresponds to a menu choice. 8. One choice must set done TRUE. • The command choice to exit the program sets the done flag to TRUE • HINT: This implies one of the menu choices must be to quit the application. If the quit choice was chosen, setting the done flag to TRUE prevents any further action from being taken. 9. All other choices are program operations • All other command choices perform an operation either inline or by calling a function with or without arguments. • For this lab, all command choices should simply printout which operation was selected. No external methods need to be called. 10. Default case prints invalid choice message • The scanf() logic cannot stop all invalid choices, but an else statement of the if else logic can catch the others and print a message. 11. After executing the users chosen command, the while-loop will then continue prompting the user to select an operation or to quit. 12. At the end of the while-loop print “Goodbye” to the console Once completed, please submit lab8.c to Blackboard. An example of this programs expected output is attached below. 1 - Operation 1 2 - Operation 2 3 - Operation 3 4 - Operation 4 5 - Quit 3 //user inputted value Doing operation 3 1 - Operation 1 2 - Operation 2 3 - Operation 3 4 - Operation 4 5 - Quit 1 //user inputted value Doing operation 1 1 - Operation 1 2 - Operation 2 3 - Operation 3 4 - Operation 4 5 - Quit 5 //user inputted value Goodbye

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

Please find the program below:

lab8.c

#include<stdio.h>
#include<conio.h>

const int FALSE = 0;
const int TRUE = 1;


int main() {
   int done = FALSE; // Setting done to false as user is not done entering choice yet
   int ch;
   while(!done) { // Looping until not done
       do {
           // Printing the Menu of choices (command chooser)
           printf("1 - Operation 1\n");
           printf("2 - Operation 2\n");
           printf("3 - Operation 3\n");
           printf("4 - Operation 4\n");
           printf("5 - Quit\n");
           printf("Enter your choice: ");
       } while(scanf("%d", &ch) < 1); // Checking if the input choice is valid
       // Printing the corresponding choive chose by the user (command dispatcher)
       if (ch == 1) {
           printf("Operation 1 is Selected\n");
       } else if (ch == 2) {
           printf("Operation 2 is Selected\n");
       } else if (ch == 3) {
           printf("Operation 3 is Selected\n");
       } else if (ch == 4) {
           printf("Operation 4 is Selected\n");
       } else if (ch == 5) {
           done = TRUE; // Quitting the program
           break;
       } else {
           printf("Invalid choice\n");
       }
   }
   printf("Good Bye...");
   return 1;
}

Sample Output:

Add a comment
Know the answer?
Add Answer to:
CSC 130 Lab Assignment 8 – Program Menu Create a C source code file named lab8.c...
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
  • C++ programming For this assignment, write a program that will act as a geometry calculator. The...

    C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...

  • Design program so that it correctly meets the program specifications given below.   Specifications: Create a menu-driven...

    Design program so that it correctly meets the program specifications given below.   Specifications: Create a menu-driven program that finds and displays areas of 3 different objects. The menu should have the following 4 choices: 1 -- square 2 -- circle 3 -- right triangle 4 -- quit If the user selects choice 1, the program should find the area of a square. If the user selects choice 2, the program should find the area of a circle. If the user...

  • Create a menu-driven program (using the switch) that finds and displays areas of 3 different objects....

    Create a menu-driven program (using the switch) that finds and displays areas of 3 different objects. The menu should have the following 4 choices: 1 -- rectangle 2 -- circle 3 -- triangle 4 -- quit If the user selects choice 1, the program should find the area of a rectangle. rectangle area = length * width If the user selects choice 2, the program should find the area of a circle. circle area = PI * radius * radius...

  • Write a Program that has a menu with a  layout below, that asks the user if they...

    Write a Program that has a menu with a  layout below, that asks the user if they want to: 1. Converts from feet and inches to meter and centimeters 2. Converts from meter and centimeters to feet and inches 3. Quit the program The program should continue as long as the user asks it to. The program will use a switch statement for the menu option selection. Either a do loo or a do-while loop can be used for the overall...

  • This is done in c programming and i have the code for the programs that it wants at the bottom i ...

    This is done in c programming and i have the code for the programs that it wants at the bottom i jut dont know how to call the functions Program 2:Tip,Tax,Total int main(void) {    // Constant and Variable Declarations    double costTotal= 0;    double taxTotal = 0;    double totalBill = 0;    double tipPercent = 0;    // *** Your program goes here ***    printf("Enter amount of the bill: $");    scanf("%lf", &costTotal);    printf("\n");    // *** processing ***    taxTotal = 0.07 * costTotal;    totalBill...

  • In basic c develop the code below: (a) You will write a program that will do...

    In basic c develop the code below: (a) You will write a program that will do the following: prompt the user enter characters from the keyboard, you will read the characters until reading the letter ‘X’ You will compute statistics concerning the type of characters entered. In this lab we will use a while loop. We will read characters from stdin until we read the character ‘X’. Example input mJ0*5/]+x1@3qcxX The ‘X’ should not be included when computing the statistics...

  • Write a C program that does the following: • Displays a menu (similar to what you...

    Write a C program that does the following: • Displays a menu (similar to what you see in a Bank ATM machine) that prompts the user to enter a single character S or D or Q and then prints a shape of Square, Diamond (with selected height and selected symbol), or Quits if user entered Q. Apart from these 2 other shapes, add a new shape of your choice for any related character. • Program then prompts the user to...

  • C++ Program with 2 functions 1. Hamming Functions Tester Write a function that displays a menu...

    C++ Program with 2 functions 1. Hamming Functions Tester Write a function that displays a menu to test the functions from 2 - 4. You must call the functions from 2 - 4 and cannot reimplement their functionality in this function. The menu is displayed as follows: 1) Enter a 4-bit message to encode into a 7-bit Hamming message. 2) Enter a 7-bit Hamming message to transmit through a noisy channel. 3) Enter a 7-bit Hamming message to receive and...

  • In the Source Folder (src) of this project create a new C source file called "gcd.c"....

    In the Source Folder (src) of this project create a new C source file called "gcd.c". Once again, copy the contents of the "main.c" file above into the "gcd.c" source file. Modify this program to NOT ask the user to input the second Positive Integer, if the user has entered a program terminating value for the "first" input Postitive Integer. #include <stdlib.h> #include <stdio.h> int main(int argc, char *argv[]) { //============================== setbuf(stdout, NULL); // turns standard output buffering off int...

  • Create a new Python program in IDLE, and save it as lab8.py.(Again, I recommend saving lab...

    Create a new Python program in IDLE, and save it as lab8.py.(Again, I recommend saving lab progranms Your Python program will do the following: Create an empty list . Use a for loop to ask the user for 10 numbers. Add each number to your list using the append metha . Use another for loop to print the list in reverse order, one per line . Use a while loop to count how many positive numbers are in the list...

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