Question

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 enter a number and then prompts to enter a
symbol. The allowable range of numbers is [7, 17] which will be used as height of the
above shape and any symbol is acceptable.
• Your program should be case insensitive. Uppercase and lowercase inputs will be
considered correct! You must use if-else statements to make appropriate choices in
the menu. Can’t use switch statement here! Logic to draw the shape can be
implemented using any loop statements but you cannot use same loop statement
twice.
• After displaying the shapes, show the menu again automatically. Note: there will be
no other way to stop the program until user enters Q.
Hint: You may want to create separate functions for drawing each shape.
c) Re-do Part b of the last problem using switch-case statement for menu. Note: You must use switch-case statements to make appropriate choices in the menu. Can’t use if-else statement here
0 0
Add a comment Improve this question Transcribed image text
Answer #1
 
/*
   C program to print shapes
*/

#include <stdio.h>
        #include <stdlib.h>

        void printSquare(int hi, char sym)
        {
        int i, j;

        printf("

");

        for(i = 0; i < hi; i++)
        {
        for(j = 0; j < hi; j++)
        {
        if(i == 0 || j ==0 || i == hi - 1 || j == hi -1)
        printf("%c", sym);
        else
        printf(" ");
        }
        printf("
");
        }
        }

        void printDiamond(int hi, char sym)
        {
        int i, j;
        int mid = hi/2;

        printf("

");

        for(i = 0; i < hi; i++)
        {
        for(j = 0; j < hi; j++)
        {
        if(i <= 3 && (mid - i == j) || (mid + i) == j)
        printf("%c", sym);
        else if(i > 3 && (i - mid == j) || (hi - i + mid - 1) == j)
        printf("%c", sym);
        else
        printf(" ");
        }
        printf("
");
        }
        }

        int main()
        {
        int choice;
        int hi;
        char sym;

        do
        {
        printf("Menu
");
        printf("1. Square
");
        printf("2. Diamond
");
        printf("3. Quit
");

        printf("
Enter Choice: ");
        scanf("%d", &choice);

        if(choice == 1)
        {
        printf("Enter Height and Symbol: ");
        scanf("%d %c", &hi, &sym);
        printSquare(hi, sym);
        }
        else if(choice == 2)
        {
        printf("Enter Height and Symbol: ");
        scanf("%d %c", &hi, &sym);
        printDiamond(hi, sym);
        }
        else if(choice == 3)
        {
        exit(0);
        }

        printf("

");

        }  while(1);

        return 0;
        }

/*
   Main Function with switch

   int main()
{
   int choice;    
   int hi;
   char sym;

   do
   {
      printf("Menu
");
      printf("1. Square
");
      printf("2. Diamond
");
      printf("3. Quit
");
   
      printf("
Enter Choice: ");
      scanf("%d", &choice);
   
      swicth(choice)
      {
         case 1:       printf("Enter Height and Symbol: ");
                  scanf("%d %c", &hi, &sym);
                  printSquare(hi, sym);
                  break;
      
         case 2:       printf("Enter Height and Symbol: ");
                  scanf("%d %c", &hi, &sym);
                  printDiamond(hi, sym);
                  break;
         
         case 3:       exit(0);
      
      }
   
      printf("

");

   }  while(1);

   return 0;
}

*/

CAUsersTusharDesktopnwPrint Diamond Square.exe Menu 2. Diamond 3. Quit Enter Choice: 1 Enter Height and Symbol: 9 222929202 MCAUsers TushanDesktoplnew Print Diamond Square.exe Enter Choice: 1 Enter Height and Symbol: 9 222929202 Menu 2. Diamond . Quit Enter Choice: 2 Enter Height and Symbol: 9 Menu 2. 3. Quit Enter Choice: 3 Diamond Process exited after 18.47 seconds with return value e R 1227 AM

Note: For any query, drop a comment.

Add a comment
Know the answer?
Add Answer to:
Write a C program that does the following: • Displays a menu (similar to what you...
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
  • Write a program in Python that will: Here are following requirements to completing Menu shapes: 1....

    Write a program in Python that will: Here are following requirements to completing Menu shapes: 1. Create a "MENU" with 4 - 5 options have the user click the option and thereafter ask the user to enter the amount of stars from 1 - 50. From there your "for loop" will create the shape. Menu options need to be: 1. Filled Triangle 2. filled Square 3. This can be any shape such as a Square, circle, a different angle of...

  • Using C++, Write a program that will provide the user a menu from which the user...

    Using C++, Write a program that will provide the user a menu from which the user may select to calculate the area of one of four geometric shapes: a circle, a rectangle, a triangle, and a trapezoid. You should use the most appropriate SWITCH block for this program. The user will input all data needed to calculate the area. The program should output all data input by the user, the calculated area, and the geometric shape selected. Run this program...

  •   Write codes that will produce the screen as shown Firstly, the program prompts user to...

      Write codes that will produce the screen as shown Firstly, the program prompts user to enter his name. Then it will display Hello <user name>. Next it prints out a menu which contains 5 options (1- add two integers, 2- add two strings, 3- compute factorial, 4- reverse a string, 5- quit program). Code all 5 tasks appropriately. When the task is completed (not including quitting program of course), the menu pops up again and asks user to try...

  • Use Python 3 Create a program that uses Turtle to draw shapes. Show the following menu:...

    Use Python 3 Create a program that uses Turtle to draw shapes. Show the following menu: Enter Circle Enter Rectangle Remove Shape Draw Shapes Exit Circles – User inputs position, radius, and color. The position is the CENTER of the circle Rectangles – User inputs position, height, width, color. The position is the lower left-hand corner Colors – Allow red, yellow, blue, and green only Remove – Show the number of items in the list and let the user enter...

  • Menu-driven programs will display the menu options to the user and then prompt them for a...

    Menu-driven programs will display the menu options to the user and then prompt them for a menu choice. This program will display the following menu in the following format: Calculator Options: Calculate the area of a circle Calculate the area of a rectangle Calculate the area of a triangle Calculate the area of a trapezoid Calculate the area of a sphere Exit Enter your choice (1-6) Once the user enters a choice for the menu, the program should use a...

  • 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...

  • 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...

  • IN JAVA: Write a program that displays a menu as shown in the sample run. You...

    IN JAVA: Write a program that displays a menu as shown in the sample run. You can enter 1, 2, 3, or 4 for choosing an addition, subtraction, multiplication, or division test. After a test is finished, the menu is redisplayed. You may choose another test or enter 5 to exit the system. Each test generates two random single-digit numbers to form a question for addition, subtraction, multiplication, or division. For a subtraction such as number1 – number2, number1 is...

  • Code should be written in C++ 2. [11] You have been hired by Shapes Calculator Menu Maker to create a C++ console a...

    Code should be written in C++ 2. [11] You have been hired by Shapes Calculator Menu Maker to create a C++ console application that prompts the user with a menu and various options. Starting from Lab03, prompt the user for a char value that corresponds to one of the following menu options: a. Sphere=4*pi"radius3 (hint: use a constant value for pi=3.1415) b. Right Circular Cylinder- piradius*height c. Rectangular Parallelepiped length *width height d. Cone-*pi*radius2 height 3 x. Exit menu. Implement...

  • In C++ write a simple menu program that displays a menu for the user in an...

    In C++ write a simple menu program that displays a menu for the user in an object-oriented technique. The menu should keep showing up until the user chooses to quit. Also, there is a sub-menu inside a menu. The user should get at least a line displayed after he or she chooses that particular option meaning if the user presses 1 for the read actors from the file. The output can look like "reading actors from a file" and then...

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