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

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

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

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

  • Write a program which: - prompts the user for 2 numerical inputs - stores their two...

    Write a program which: - prompts the user for 2 numerical inputs - stores their two inputs in variables as floats - Use a while in loop to ask a user for a valid operation: (if the user's input operation isn't one of those listed above, instead print a message telling them so, and continue asking for the valid operation) - prompts the user for an arithmetic operation ( + - * / %) - stores the user's input as...

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

  • java programe Write a program that prompts the user to enter in an integer number representing...

    java programe Write a program that prompts the user to enter in an integer number representing the number of elements in an integer array. Create the array and prompt the user to enter in values for each element using a for loop. When the array is full, display the following: The values in the array on a single line. The array with all of the elements reversed. The values from the array that have even numbered values. The values from...

  • Answer in python please and use loop Question 2: Write a program that prompts the user...

    Answer in python please and use loop Question 2: Write a program that prompts the user to enter a sentence string. The program will either print True if the sentence contains every letter of the alphabet. If the sentence does not contain each letter, print which letters are missing. The results should not depend on capitalization. Hint: a loop may be very handy in the solution.

  • 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 program that separately prompts the user for a first name and last name and...

    Write a program that separately prompts the user for a first name and last name and outputs a string containing the following information, in order: a. First letter of the user's name. b. First five letters of the user's last name. c. A random two-digit integer You must construct the desired string ensuring all characters are lowercase; output the identification string accordingly. Assume the last name contains at least 5 characters. You must use the Random (java.util.Random) class to generate...

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