Question

  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 on another task. This repeats until ‘q' or ‘Q' is pressed. You may use “switch-case" or “if-else", but the former looks more legible Even though you may know how to write functions, do not use functions in this program.
Hints
Task 1 - Simple cin, and cout.
Task 2 - Use strcpx (check lecture notes Chpt 1.2.7.1)
Task 3 - Use a loop (while or for)
Task 4 - This is pretty hard. Use a while loop but needs some thinking
Repeating menu: Use gato-label statements, or an appropriate loop 
0 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

#include
#include
using namespace std;

int main()
{
string name;
char choice;


cout<<"Enter name please\n>>";
cin>>name;
cout<<"Hello "<

do
{
cout<<"==========MENU============="< cout<<"Please select one:\n";
cout<<"\'1\' - Add two integers"< cout<<"\'2\' - Add two strings"< cout<<"\'3\' - Compute factorial of an integers(n!)"< cout<<"\'4\' - Reverse a string"< cout<<"\'Q\' - Quit program"< cout<<"==========================="<>";
cin>>choice;

switch(choice)
{
case '1':
{
int n1,n2;
cout<<"Enter two integers\n>>";
cin>>n1>>n2;
cout<<"The sum is "<<(n1+n2)<

}
break;
case '2':
{
string str1,str2,result;
cout<<"Enter two strings\n>>";
cin>>str1>>str2;
result=str1+str2;
cout<<"The result is "< }
break;
case '3':
{
int n,fact=1;
cout<<"Enter positive integer n.\n>>";
cin>>n;
for(int i=2; i<=n; i++)
fact*=i;
cout<

}
break;
case '4':
{
char str[100],temp;
int i=0, j;
cout<<"Enter string to be reversed \n>>";
cin>>str;


j=strlen(str)-1;
while(i {
temp=str[i];
str[i]=str[j];
str[j]=temp;
i++;
j--;
}

cout<<"Reversed string = "<


}
break;
case 'Q':
case 'q':
{

cout<<"Program quitting..."< }
break;
default:
cout<<"Invalid choice!"< }
if(choice=='q'||choice=='Q') break;
}

while(true);

return 0;
}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
  Write codes that will produce the screen as shown Firstly, the program prompts user to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • 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...

  • Write a program that displays this to the user. "Hot Beverage Menu" "A: Coffee $1.00", "B:...

    Write a program that displays this to the user. "Hot Beverage Menu" "A: Coffee $1.00", "B: Tea $ 0.75", "C: Hot Chocolate $1.25", "D: Cappuccino S2.50", "E: Exit Menu" Prompt the user to make a selection. Determine which item the user entered. Use a do-while loop that keeps repeating till the user selects E from the Menu. If the user has selected a valid beverage, prompt the user for how many cups they would like, and print out how much...

  • Write a Java program called Flying.java that, firstly, prompts (asks) the user to enter an input...

    Write a Java program called Flying.java that, firstly, prompts (asks) the user to enter an input file name. This is the name of a text file that can contain any number of records. A record in this file is a single line of text in the following format: Num of passengers^range^name^manufacturer^model where: Num of passengers is the total number of people in the plane. This represents an integer number, but remember that it is still part of the String so...

  • Write a program that prompts the user for an integer that the player (maybe the user,...

    Write a program that prompts the user for an integer that the player (maybe the user, maybe someone else) will try to guess. If the player's guess is higher than the target number, the program should display "too high" If the user's guess is lower than the target number, the program should display "too low" The program should use a loop that repeats until the user correctly guesses the number. Then the program should print how many guesses it took....

  • Write a program that prompts the user to enter a number within the range of 1...

    Write a program that prompts the user to enter a number within the range of 1 to 10 inclusive. The program then generates a random number using the random class: If the users guess is out of range use a validation loop (DO) to repeat the prompt for a valid number, If the users guess matches the random number tell them they win! If the users guess does not match the random number tell them they are wrong. Use a...

  • JAVA Write a program that prompts the user to enter a file name, then opens the...

    JAVA Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it. The input files are assumed to be in CSV format. The input files contain a list of integers on each line separated by commas. The program should read each line, sort the numbers and print the comma separated list of integers on the console. Each sorted list of integers from the same line should be printed together...

  • Q.1. Write a C program that determines whether a line entered by a user is a...

    Q.1. Write a C program that determines whether a line entered by a user is a palindrome or not. You must demonstrate it as an application of stack (you may use linked list implementation demonstrated in the class). Hint! Think of the basic property of a stack i.e. LIFO (list-in-first-out). Q.2. Write a charQueue header file containing all the function headers of following functions: 1- initiateQueue—to initialize a queue 2- enqueue—to add a node at the rear end of the...

  • Write a Python program that prints a name as shown in the image below. The program...

    Write a Python program that prints a name as shown in the image below. The program asks the user to enter a name and how many time the user wants to display the name.. You need two to input two integer values. First, for repeating name in a row. Second, for number of rows. In total, your program will have three inputs. Add three comment lines at start of the program, which shows program purpose, your name and date. Hint:...

  • java program QUESTION 2: 1. Write a do-while loop that asks the user to select a...

    java program QUESTION 2: 1. Write a do-while loop that asks the user to select a task from the following menu to continue: 1. Option 1 2. Option 2 3. Option 3 4. Option 4 5. Exit Read the selection from the keyboard then write the switch statement: For option 1, display the message "Do the option 1" For option 2, display the message "Do the option 2" For option 3, display the message "Do the option 3" For option...

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

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