Question

In: Computer Science

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                                                           11

2                                                              34

89                                                            55

78                                                            78

11                                                            89

Do you want to quit? Q

  • If the user selects ‘M’ or ‘m, prompt the user to read an elements of two dimensional array of 2 x 2. Then, find the transpose of matric A and then add the transposed matrix to the original matrix and save the results into matrix C. Print the elements of matrices A, A-transposed , and C.

Do you want to quit? Q

If the user enters ‘Q’ or ‘’, your program should terminate the program.

C++ Please

Solutions

Expert Solution

Below is the complete C++ code. If you face any difficulty while understanding the code, Please let me know in the comments.

Code:

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main() {
char ch;
cout << "Menu:\n Sort: s or S\n Matrix: m or M\n Quit: q or Q" << endl;
cin >> ch ;
  
if(ch == 's' || ch == 'S') {
int n;
cout << "How many numbers:";
cin >> n ;
  
int origArr[n];
int sortArr[n];
  
for(int i=0;i<n;i++) {
cin >> origArr[i];
sortArr[i] = origArr[i];
}
  
sort(sortArr, sortArr + n );
  
cout << "Original numbers" << " Sorted numbers" << endl;
for(int i=0;i<n;i++)
cout << origArr[i] << " " << sortArr[i] << endl ;
  
}else if(ch == 'm' || ch == 'M') {
  
int A[2][2];
cout << "Enter the elements of matrix M:\n";

for(int i=0; i<2; i++)
for(int j=0; j<2; j++)
cin >> A[i][j];
  
int A_transposed[2][2];
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
A_transposed[i][j] = A[j][i];
  
int C[2][2];
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
C[i][j] = A[i][j] + A_transposed[i][j];
  
// Print matrix A
cout << "\nMatrix A:\n";
for(int i=0;i<2;i++){
for(int j=0;j<2;j++)
cout << A[i][j] << " ";
cout << "\n";
}
  
// Print matrix A-transposed
cout << "\nA-Transposed matrix:\n";
for(int i=0;i<2;i++){
for(int j=0;j<2;j++)
cout << A_transposed[i][j] << " ";
cout << "\n";
}
  
// Print matrix C
cout << "\nMatrix C:\n";
for(int i=0;i<2;i++){
for(int j=0;j<2;j++)
cout << C[i][j] << " ";
cout << "\n";
}
} else if(ch == 'q' || ch == 'Q') {
char ch;
cout << "Do you want to quit? Q\n" ;
cin >> ch;
  
if(ch == 'Q')
return 0;
}

return 0;
}

Screenshots:

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...
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...
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...
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...
Question #11. Write a script that uses the menu function to prompt the user to select...
Question #11. Write a script that uses the menu function to prompt the user to select the current day of the week. Then use the menu function to prompt the user to select their favorite day of the week. Print a message telling the user how many days it will be until their favorite day. The output must include the current day, the favorite day, and the number of days until the favorite day. Debug your programming by running it...
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 PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
Write a calculator program that prompts the user with the following menu: Add Subtract Multiply Divide...
Write a calculator program that prompts the user with the following menu: Add Subtract Multiply Divide Power Root Modulus Upon receiving the user's selection, prompt the user for two numeric values and print the corresponding solution based on the user's menu selection. Ask the user if they would like to use the calculator again. If yes, display the calculator menu. otherwise exit the program. EXAMPLE PROGRAM EXECUTION: Add Subtract Multiply Divide Power Root Modulus Please enter the number of the...
Write a program that prompts the user for their first and lastname. Display the first...
Write a program that prompts the user for their first and last name. Display the first initial of their first name and their last name to the user.Ask the user to input a phone number.The program checks which part of Colorado a phone number is from using the values below.If the second digit of the phone number is one of the below digits, print the phone number and which part of Colorado it is from. If none of the digits...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT