Question

In: Computer Science

PLEASE SOLVE THIS QUESTION WITHOUT CHANGING THE SOURCE CODE POSTED BELOW. (ONLY ADDING) #include <iostream> using...

PLEASE SOLVE THIS QUESTION WITHOUT CHANGING THE SOURCE CODE POSTED BELOW. (ONLY ADDING)

#include <iostream>

using namespace std;

const int arrSize = 3;

// QUESTION ii. COMPLETE A displayMatrix(...) FUNCTION HERE

// QUESTION iii. COMPLETE A transposedMatrix(...) FUNCTION HERE

// QUESTION iv. COMPLETE A calculateTotal(...) FUNCTION HERE

int main(){

// variable declaration

int mat[arrSize][arrSize], transMat[arrSize][arrSize] = {0}, total = 0;

// QUESTION i. Prompt user to enter 9 integer numbers and fill in into the matrix

cout << "\nThe original matrix is : \n";

displayMatrix(mat, arrSize); // function called to display matrix

// function called to transpose matrix

transposedMatrix(mat, transMat, arrSize);

cout << "\nThe transposed matrix is : \n";

displayMatrix(transMat, arrSize); // function called to display matrix

calculateTotal(mat, arrSize, total); // function called to calculate total

cout << "\nThe total of the matrix is " << total << endl;

return 0;

}

Solutions

Expert Solution

Full Code--

#include <iostream>
using namespace std;
const int arrSize = 3;
// QUESTION ii. COMPLETE A displayMatrix(...) FUNCTION HERE
void displayMatrix(int mat[][arrSize],int size)
{
   for(int i=0;i<size;i++)
   {
       for(int j=0;j<size;j++)
       {
           cout<<mat[i][j]<<" ";
       }
       cout<<endl;
   }
   cout<<endl;
}
// QUESTION iii. COMPLETE A transposedMatrix(...) FUNCTION HERE
void transposedMatrix(int mat[][arrSize],int transMat[][arrSize], int size)
{
   for(int i=0;i<size;i++)
   {
       for(int j=0;j<size;j++)
       {
           transMat[j][i]=mat[i][j];
       }
   }
}
// QUESTION iv. COMPLETE A calculateTotal(...) FUNCTION HERE
void calculateTotal(int mat[][arrSize],int size,int &total)
{
   for(int i=0;i<size;i++)
   {
       for(int j=0;j<size;j++)
       {
           total+=mat[i][j];
       }
   }
}
int main()
{
   // variable declaration
   int mat[arrSize][arrSize], transMat[arrSize][arrSize] = {0}, total = 0;
   // QUESTION i. Prompt user to enter 9 integer numbers and fill in into the matrix
   cout<<"Enter the values of the matrix\n";
   for(int i=0;i<arrSize;i++)
   {
       for(int j=0;j<arrSize;j++)
       {
           cin>>mat[i][j];
       }
   }
   cout << "\nThe original matrix is : \n";
   displayMatrix(mat, arrSize); // function called to display matrix
   // function called to transpose matrix
   transposedMatrix(mat, transMat, arrSize);
   cout << "\nThe transposed matrix is : \n";
   displayMatrix(transMat, arrSize); // function called to display matrix
   calculateTotal(mat, arrSize, total); // function called to calculate total
   cout << "\nThe total of the matrix is " << total << endl;
   return 0;
}

Question wise screenshot--

Question i)

Question ii)

Question iii)

Question iv)

Output Screenshot--

Note--

Please upvote if you like the effort.


Related Solutions

C++ CODE ONLY Using the following code. #include <iostream> #include <string> #include <climits> #include <algorithm> using...
C++ CODE ONLY Using the following code. #include <iostream> #include <string> #include <climits> #include <algorithm> using namespace std; // M x N matrix #define M 5 #define N 5 // Naive recursive function to find the minimum cost to reach // cell (m, n) from cell (0, 0) int findMinCost(int cost[M][N], int m, int n) {    // base case    if (n == 0 || m == 0)        return INT_MAX;    // if we're at first cell...
I need to understand how I would edit this code without changing anything, only adding. I...
I need to understand how I would edit this code without changing anything, only adding. I am not looking for the exact answer, just information on how I would use the given code to complete some of the todo statements. Thank you! // include this header file so we can use `printf()` #include <stdio.h> // every C program must implement the `main()` function int main(int argc, char *argv[]) {    //TODO: check for enough arguments       // save the...
A C++ question: I want to indent the code of this C++ program: #include<iostream> #include<cstring> using...
A C++ question: I want to indent the code of this C++ program: #include<iostream> #include<cstring> using namespace std; int lastIndexOf(char *s, char target) { int n=strlen(s); for(int i=n-1;i>=0;i--) { if(s[i]==target) { return i; } } return -1; } void reverse(char *s) { int n=strlen(s); int i=0,j=n-1; while(i<=j) { char temp=s[i]; s[i]=s[j]; s[j]=temp; i++; j--; } return; } int replace(char *s, char target, char replacementChar) { int len=strlen(s); int total=0; for(int i=0;i<len;i++) { if(s[i]==target) { s[i]=replacementChar; total+=1; } } return total;...
C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using...
C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using namespace std; const int CWIDTH = 26; int main() {    int choice;    double convertFoC, converCtoF;    double starting, endvalue, incrementvalue;    const int CWIDTH = 13;    do {       cin >> choice;    switch (choice)    {        cin >> starting;    if (starting == 28){       cout << "Invalid range. Try again.";    }    while (!(cin >> starting)){       string  garbage;       cin.clear();       getline(cin, garbage);       cout << "Invalid data Type, must be a number....
--- TURN this Code into Java Language --- #include <iostream> #include <string> using namespace std; //...
--- TURN this Code into Java Language --- #include <iostream> #include <string> using namespace std; // constants const int FINAL_POSITION = 43; const int INITIAL_POSITION = -1; const int NUM_PLAYERS = 2; const string BLUE = "BLUE"; const string GREEN = "GREEN"; const string ORANGE = "ORANGE"; const string PURPLE = "PURPLE"; const string RED = "RED"; const string YELLOW = "YELLOW"; const string COLORS [] = {BLUE, GREEN, ORANGE, PURPLE, RED, YELLOW}; const int NUM_COLORS = 6; // names...
using only loops, no functions and no arrays. with the heading: #include <iostream> using namespace std;...
using only loops, no functions and no arrays. with the heading: #include <iostream> using namespace std; "Write a program that asks the user to enter an odd positive integer. The program reads a value (n) entered by the user and prints an n x n grid displaying a large letter X. The left half should be made up of pluses (+) and the right half should be made with the character "x" and the very center should be an asteric...
Using only loops, no functions and no arrays. with the heading: #include <iostream> using namespace std;...
Using only loops, no functions and no arrays. with the heading: #include <iostream> using namespace std; "Write a program that asks the user to enter an integer between 1 and 20. If the user enters an illegal number, the program repeatedly asks the user to enter the correct one. If the user has not entered a correct number after 10 attempts, the program chooses the number 10 as the user's number. The program prints the cube of the user's number.
Please write variables and program plan(pseudocode) of this C++ programming code: #include <iostream> using namespace std;...
Please write variables and program plan(pseudocode) of this C++ programming code: #include <iostream> using namespace std; void leapYear(int x); int main() { int x; cout << "Enter a year: "; cin >> x; leapYear (x);   return 0; } void leapYear(int x ) {    if (x % 400 == 0)    {    cout << "This is a leap Year";}    else if    ((x % 4 == 0) && (x % 100 != 0))    {    cout <<...
Hi, i need flowchart for this code (C++) please, THANX #include <iostream> #include <thread> #include <unistd.h>...
Hi, i need flowchart for this code (C++) please, THANX #include <iostream> #include <thread> #include <unistd.h> #include <semaphore.h> #include <pthread.h> using namespace std; #define NRO 6 // Número de coches //Puente declarado con matriz y valor entero void Puente(string array, int value); // Variable global int Norte = 1; int Sur = 1; sem_t mutex1; //Coche al norte void* NorteC(void* arg){ sem_wait(&mutex1); string array = "En el lado Norte "; // Norte cout<<array<<"del puente, el coche #"<<Norte<<" puede cruzar el...
C++ finish the AVL Tree code: #include "AVLNode.h" #include "AVLTree.h" #include <iostream> #include <string> using namespace...
C++ finish the AVL Tree code: #include "AVLNode.h" #include "AVLTree.h" #include <iostream> #include <string> using namespace std; AVLTree::AVLTree() { root = NULL; } AVLTree::~AVLTree() { delete root; root = NULL; } // insert finds a position for x in the tree and places it there, rebalancing // as necessary. void AVLTree::insert(const string& x) { // YOUR IMPLEMENTATION GOES HERE } // remove finds x's position in the tree and removes it, rebalancing as // necessary. void AVLTree::remove(const string& x) {...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT