Question

In: Computer Science

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

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++ please

Solutions

Expert Solution

Please find the program below.

#include <iostream>
#include <stdlib.h> /* srand, rand */
#include <time.h>

using namespace std;
void sort_name ( string firstname[] , string lastname[],int count){
cout<<"First name"<<"\t\t"<<"Last name"<<"\t\t"<<"Combined name"<<endl;
cout<<"------------------------------------------------------------"<<endl;
for (int i=0;i<count;i++){
cout<<firstname[i]<<"\t\t\t"<<lastname[i]<<"\t\t\t"<<firstname[i]<<" "<<lastname[i]<<endl;
}
}

int main()
{   
int number=0;
cout<<"1. Guess-Number"<<endl ;
cout<<"2. Concat-names"<<endl;
cout<<"3. Quit"<<endl;
cin>>number;
switch (number)
{
case 1:
{
int random_number=0,guess_number;
char ans;
/* initialize random seed: */
srand (time(NULL));

/* generate secret number between 1 and 10: */
random_number = rand() % 100 + 1;
while(1){
cout<<"Guess the number "<<endl;
cin>>guess_number;
if(guess_number<random_number){
cout<<"Too small"<<endl;
}
else if (guess_number>random_number){
cout<<"Too large"<<endl;
}
else{
cout<<"Close"<<endl;
break;
}
}
cout<<"Do you want to quit? Press Q to quit ..."<<endl;
cin>>ans;
if(ans=='Q'){
exit(0);
break;}
}
case 2:{
while(1){
int name;
char ans;
cout<<"How many names ?" <<endl;
cin>>name;
string firstname[name];
string lastname[name];
for (int i=0;i<name;i++){
cin>>firstname[i];
cin>>lastname[i];
}
sort_name (firstname,lastname,name);
cout<<"Do you want to quit? Press Q to quit ..."<<endl;
cin>>ans;
if(ans=='Q'){
exit(0);
break;
}
}
}
case 3:{ exit(0); }
}
return 0;
}

OUTPUT :


Related Solutions

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...
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 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 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...
IN C This assignment is to write a program that will prompt the user to enter...
IN C This assignment is to write a program that will prompt the user to enter a character, e.g., a percent sign (%), and then the number of percent signs (%) they want on a line. Your program should first read a character from the keyboard, excluding whitespaces; and then print a message indicating that the number must be in the range 1 to 79 (including both ends) if the user enters a number outside of that range. Your program...
In Java: Write a program that generates a random number and asks the user to guess...
In Java: Write a program that generates a random number and asks the user to guess the number and keeps track of how many guesses it took If the user input is negative or zero then the loop must stop reading further inputs and display how many guesses they used If they guess the correct number display a message telling them they got it and exit the program If they guess the wrong number (but still a legal guess) you...
17. Write a program that generates a random number and asks the user to guess what...
17. Write a program that generates a random number and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the program should display “Too low, try again.” The program should use a loop that repeats until the user correctly guesses the random number. 18. Enhance the program that you wrote for Programming...
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream>, switch and if-else statements only and do not use string storing for the conversion in words. Thank you.** **Our class is still discussing on the basics of programming. Please focus only on the basics. Thank you.** Example outputs: Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four...
Write a java program that will first display the following menu: Choose one of the following...
Write a java program that will first display the following menu: Choose one of the following 1- To add 2 double integers 2- To add 2 integer numbers 3- To add 3 double numbers 4- To add 3 integer numbers After reading user’s choice, use a switch case statement to call the corresponding method Void add 1 (double n1, double n2) Void add2() Double add3 (double n1, double n2, double n3) Double add4 ()
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT