Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PROGRAM REQUIREMENTS You are tasked to develop C++ program for 2D array calculat

ID: 3626934 • Letter: P

Question

PROGRAM REQUIREMENTS
You are tasked to develop C++ program for 2D array calculations using given Matrix A and Matrix B below . At the beginning of the program ( as soon as the user launches the program) user will be prompted by Greeting message And the main menu options.
=========================
Welcome
=========================
How can I help up you today?
1) Add Matrix A and B
2) Transpose of A
3) Reset a section of Matrix A
4) Noting. Exit

REQUIREMENTS
1) There must be a warning message if the user enters a choice (option) which is NOT given in the menu items ( i.e. 6).User must be prompted by “ Invalid Entry !” and the menu items must be showed again to give the user an opportunity to make correct selection.
2) The greeting message is going to appear just once at the beginning of the program
3) Develop a VOID FUNCTION for the Main menu
4) On the screen, the distance between the columns of each matrix should be 6 character length.

If the user selects option 1: Program will display the following message on the screen.
=====================================================
Addition of Matrix A and B
=====================================================
Then show the new matrix C where C=A+B on the screen ( Add matrix A and Matrix B)
Then show the main menu for the user to make selection.
If the user selects option 2: Program will display the following message on the screen.
=====================================================
Transpose of A
=====================================================
Then show the new (AT=transpose of A) matrix on the screen
Then show the main menu for the user to make selection.
If the user selects option 3: Program will display the following message on the screen.
=====================================================
Resetting a section of Matrix A
=====================================================
Have user to select a section of the given matrix ( User to enter Row and Column)
Reset the values of the selected section ( replace the current values with zero). See two examples below.
Show the matrix after the reset ( same A matrix but selected section is full of zeros)
Then show the main menu for the user to make selection.
If the user selects option 4: Program will display the following message on the screen.
=====================================================
EXITING FROM THE PROGRAM
=====================================================
Then exit from the program. Program will not stop unless option 4 is selected.
If the user selects invalid option : User must be prompted by “ Invalid Entry !” message
=====================================================
INVALID ENTRY
=====================================================
And, then the main menu items must be displayed again to give the user an opportunity to make correct selection.
Matrix A Matrix B
42 25 16 10 0 3 12 7 1 32
31 10 28 4 -3 22 4 30 4 -5
6 14 39 6 5 15 9 27 22 3
16 -4 2 12 11 4 8 -10 9 67
11 9 26 32 32 8 16 13 15 4
EXAMPLES FOR OPTION 3
Enter Row =2
Enter Column =3
New Matrix with resented sections
42 25 16 10 0
31 10 28 4 -3
6 14 39 0 0
16 -4 2 0 0
11 9 26 0 0
Enter Row =3
Enter Column =1
New Matrix with resented sections
42 25 16 10 0
31 10 28 4 -3
6 14 39 6 5
16 0 0 0 0
11 0 0 0 0

Explanation / Answer

/*
Hello. Here is an example that meets your criteria. I have included some comments at the beginning of some code blocks to briefly describe behavior. If you have any questions, do not hesitate to ask. This program has been tested and works on MSVC++ and GCC. Please excuse the formatting as Cramsters answer auto formatting destroys what I copy and paste.

Don't forget to rate please.

-B
*/

//Preprocessor directives for input/output and output formatting
#include
#include
using namespace std;

//typedef to make life easier while pasing a 2-D array to functions
typedef int d5x5[5][5];

//Menu function
void menu(){
cout << "How can I help up you today?" << endl;
cout << "1) Add Matrix A and B" << endl;
cout << "2) Transpose of A" << endl;
cout << "3) Reset a section of Matrix A" << endl;
cout << "4) Noting. Exit" << endl;
cout << "Enter in your choice: ";
}

//Add the Matrices
void add(d5x5 &a, d5x5 &b){
cout << "=====================================================" << endl;
cout << "Addition of Matrix A and B" << endl;
cout << "=====================================================" << endl;
int matrixC[5][5];
for(int i = 0; i < 5; i++){
for(int j = 0; j < 5; j++){
matrixC[i][j] = a[i][j] + b[i][j];
cout << setw(6) << matrixC[i][j] << setw(6);
}
cout << endl;
}
}

//Transpose matrix A
void aT(d5x5 &a){
cout << "=====================================================" << endl;
cout << "Transpose of A" << endl;
cout << "=====================================================" << endl;
for(int i = 0; i < 5; i++){
for(int j = 0; j < 5; j++){
cout << setw(6) << a[j][i] << setw(6);
}
cout << endl;
}
}

//Set a certain area of matrix A to 0
void set(d5x5 &a){
int col, row;
cout << "Enter in Column: ";
cin >> col;
cout << "Enter in Column: ";
cin >> row;
cout << endl;
for(int i = row; i < 5; i++){
for(int j = col; j < 5; j++){
a[i][j] = 0;
}
}
for(i = 0; i < 5; i++){
for(int j = 0; j < 5; j++){
cout << setw(6) << a[j][i] << setw(6);
}
cout << endl;
}
}

int main(){
//output the welcome message once
cout << "=========================" << endl;
cout << "Welcome" << endl;
cout << "=========================" << endl;

//Variables
int choice = 0;

int matrixA[5][5] = {
42, 25, 16, 10, 0,
31, 10, 28, 4, -3,
6, 14, 39, 6, 5,
16, -4, 2, 12, 11,
11, 9, 26, 32, 32
};

int matrixB[5][5] = {
{3, 12, 7, 1, 32},
{22, 4, 30, 4, -5},
{15, 9, 27, 22, 3},
{4, 8, -10, 9, 67},
{8, 16, 13, 15, 4}
};

// Loop to control the flow of the program
while (choice != 4){
menu();
cin >> choice;
switch(choice){
case 1:
add(matrixA, matrixB);
break;
case 2:
aT(matrixA);
break;
case 3:
set(matrixA);
break;
case 4:
cout << "=====================================================" << endl;
cout << "EXITING FROM THE PROGRAM" << endl;
cout << "=====================================================" << endl;
break;
default:
cout << "=====================================================" << endl;
cout << "INVALID ENTRY" << endl;
cout << "=====================================================" << endl;
}
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote