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 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...
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...
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 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)...
Write a C program that prompt the user to enter 10 numbers andstores the numbers...
Write a C program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT