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: 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: 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...
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...
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...
Write a program names EncryptDecrypt.java that has the following menu choices: Print menu and allow user...
Write a program names EncryptDecrypt.java that has the following menu choices: Print menu and allow user to choose options. The program must have a file dialogue box for text file. Output should be based on user choices. Read in a file Print the file to the console Encrypt the file and write it to the console Write out the encrypted file to a text file Clear the data in memory Read in an encrypted file Decrypt the file Write out...
write a program to perform the following in C Your program should prompt the user to...
write a program to perform the following in C Your program should prompt the user to enter ten words, one at a time, which are to be stored in an array of strings. After all of the words have been entered, the list is to be reordered as necessary to place the words into alphabetical order, regardless of case. Once the list is in alphabetical order, the list should be output to the console in order. The program should execute...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT