Question

In: Computer Science

Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names     &

Write a program to prompt the user to display the following menu:

Guess-Number                        Concat-names             Quit

  • If the user selects Guess-number, your program needs to call a user-defined function called int guess-number ( ). Use random number generator to generate a number between 1 – 100. Prompt the user to guess the generated number and print the following messages. Print the guessed number in main ():

Guess a number: 76

96:

Too large

10

Too small

70

Close

Do you want to quit? Q

  • If the user selects Concat-name, prompt the user how many names to concatenate and then enter all the first and las names and store then into a two one-dimensional array. Your program needs to call a user-defined function called void sort-name ( char [] , char[]) to concatenate the first name and the last name and print the names in this function.

How many names: 3

First name                   last name                                Combined

Sue                              Smith                                       Sue Smith

Alan                             Davidson                                 Alan Davidson

David                           Lee                                          David Lee

Do you want to quit? Q

C++

Solutions

Expert Solution

Code:

#include<iostream>
#include<random>
#include<ctime>
#include<iomanip>
using namespace std;
void guess_number()
{
   srand(time(0));
char choice;
do
{
int guess=0;
int num=rand()%(100)+1;/*Generating a random number*/
cout<<"Guess the number:";
while(guess!=num)
{
cin>>guess;/*Reading user input*/
if(guess>num)
{/*if guess is greater than random number*/
cout<<"Too Large"<<endl;
}
else if(guess<num)
{/*if guess is less than random number*/
cout<<"Too Small"<<endl;
}
else
{/*if boath are equal*/
cout<<"Close"<<endl;
}
}
cout<<"Do you want to quit?";
cin>>choice;/*users choice*/
  
}while(choice!='Q');
  
}
void sort_name(char first[],char last[])
{/*Here we print the concatinated name*/
   int i=0;
   while(first[i]!='\0')
   {/*Here we print the first name*/
       cout<<first[i];
       i++;
   }
   i=0;
   cout<<" ";
   while(last[i]!='\0')
   {/*Here we print the last name*/
       cout<<last[i];
       i++;
   }
   cout<<""<<endl;
}
int main()
{
   while(true)
   {
       cout<<"1. Guess_Number"<<endl;
        cout<<"2.Concat-names"<<endl;
        cout<<"3.Quit"<<endl;/*Priting the menu*/
        int choose;
        cout<<"Enter your choice:";
        cin>>choose;/*Reading users choice*/
        switch(choose)
        {
            case 1:/*if 1*/
           guess_number();
           break;
           case 2:/*if 2*/
           char choice;
               do
               {
                   char first[50];
                   char last[50];
                   int n,i;/*Decalring variables*/
                   cout<<"How many names :";
                   cin>>n;/*Reading no of names*/
                   cout<<"First name";
                   cout<<setw(20)<<"Last Name";
                   cout<<setw(20)<<"combined"<<endl;
                   for(i=0;i<n;i++)
                   {/*This loop reads n names*/
                       cin>>first;
                       cin>>last;
                       cout<<setw(43);
                       sort_name(first,last);
                      
                   }
                   cout<<"Do you want to quit?";
           cin>>choice;/*users choice*/
                          
               }while(choice!='Q');  
               break;
              
           case 3:/*if 3*/
               exit(0);
               break;
           default:
               cout<<"invlaid input"<<endl;
       }
      
       
   }

}

Output:

Indentation:


Related Solutions

C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                       ...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names             Quit If the user selects Guess-number, your program needs to call a user-defined function called int guess-number ( ). Use random number generator to generate a number between 1 – 100. Prompt the user to guess the generated number and print the following messages. Print the guessed number in main (): Guess a number: 76 96: Too large 10 Too small 70 Close...
Write a program to prompt the user to display the following menu: Sort             Matrix                   Q
Write a program to prompt the user to display the following menu: Sort             Matrix                   Quit If the user selects ‘S’ or ‘s’, then prompt the user to ask how many numbers you wish to read. Then based on that fill out the elements of one dimensional array with integer numbers. Then sort the numbers and print the original and sorted numbers in ascending order side by side. How many numbers: 6 Original numbers:                     Sorted numbers 34                                                                         2          55                                                      ...
Write a java code snippet to prompt the user for the number of names they’d like...
Write a java code snippet to prompt the user for the number of names they’d like to enter. Create a new array of the size chosen by the user and prompt the user for each of the names. Output the list of names in reverse order.
Write a JAVA program that prompts the user for the number of names they’d like to...
Write a JAVA program that prompts the user for the number of names they’d like to enter. Create a new array of the size chosen by the user and prompt the user for each of the names. Output the list of names in reverse order.
You must prompt the user to enter a menu selection. The menu will have the following...
You must prompt the user to enter a menu selection. The menu will have the following selections (NOTE: all menu selections by the user should not be case sensitive): 1. ‘L’ – Length a. Assume that a file containing a series of names is called names.txt and exists on the computer’s disk. Read that file and display the length of each name in the file to the screen. Each name’s middle character or characters should be displayed on a line...
Write a C program that asks the user to guess a number between 1 and 15(1...
Write a C program that asks the user to guess a number between 1 and 15(1 and 15 are included). The user is given three trials. This is what I have so far. /* Nick Chioma COP 3223 - HW_2 */ #include <iostream> #include <time.h> // needed for time function #include <stdlib.h> // needed for srand, rand functions int main () {       int numbertoguess, num, correct, attempts;       srand(time(NULL)); //this initializes the random seed, making a new...
Write a simple airline ticket reservation program. The program should display a menu with the following...
Write a simple airline ticket reservation program. The program should display a menu with the following options: reserve a ticket, cancel a reservation, check whether a ticket is reserved for a particular person, and display the passengers. The information is maintained on an alphabetized linked list of names. In a simpler version of the program, assume that tickets are reserved for only one flight. In a fuller version, place no limit on the number of flights. Create a linked list...
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
Write a program that accept an integer input from the user and display the least number...
Write a program that accept an integer input from the user and display the least number of combinations of 500s, 100s, 50s, 20s, 10s, 5s, and 1s. Test your solution using this samples] a. Input: 250 Output: 1x200s, 1x50s b. Input: 1127 Output: 5x200s, 1x100s, 1x20s, 1x5s, 2x1s c. Input: 1127 Output: 5x200s, 1x100s, 1x20s, 1x5s, 2x1s d. Input: 19 Output: 1x10s, 1x5s, 4x1s ​[Hints] o Use division to determine the number of occurrence of each element (i.e. 200, 100)...
We need to create basic program that will simply display a menu and allow the user...
We need to create basic program that will simply display a menu and allow the user to select one of the choices. The menu should be displayed such that each option will be numbered, as well as have one capital letter so as to indicate that either the number or the designated letter can be entered to make their choice. Once the choice is made, the sub-menu for that selection should be displayed. Colors with an odd number of letters...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT