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

USING C++ ONLY. Please study the code posted below. the goal is to rewrite the code...
USING C++ ONLY. Please study the code posted below. the goal is to rewrite the code implementing a template class using a linked list instead of an array. Note: The functionality should remain the same. /** * Queue implementation using linked list C style implementation ( no OOP). */ #include <cstdio> #include <cstdlib> #include <climits> #include <iostream> #define CAPACITY 100 // Queue max capacity using namespace std; /** Queue structure definition */ struct QueueType { int data; struct QueueType *...
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...
Develop and pseudocode for the code below: #include <algorithm> #include <iostream> #include <time.h> #include "CSVparser.hpp" using...
Develop and pseudocode for the code below: #include <algorithm> #include <iostream> #include <time.h> #include "CSVparser.hpp" using namespace std; //============================================================================ // Global definitions visible to all methods and classes //============================================================================ // forward declarations double strToDouble(string str, char ch); // define a structure to hold bid information struct Bid { string bidId; // unique identifier string title; string fund; double amount; Bid() { amount = 0.0; } }; //============================================================================ // Static methods used for testing //============================================================================ /** * Display the bid information...
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....
Please explain this C++ below on how to get the following outputs (see code) #include <iostream>...
Please explain this C++ below on how to get the following outputs (see code) #include <iostream> using namespace std; // Tests for algorithm correctness // ------------------------------- // 1 gives output "1 3   7 15 31 63 127 255 511 1023 2047" // 2 gives output "2 5 11 23 47 95 191 383 767 1535 3071" // 3 gives output "3 7 15 31 63 127 255 511 1023 2047 4095" // 5 gives output "5 11 23 47 95...
--- 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...
```please convert this code to make only using for loop not while loop #include #include #define...
```please convert this code to make only using for loop not while loop #include #include #define MAX_SIZE 500 int main() { char str[MAX_SIZE]; char tosearch[MAX_SIZE]; char part1[100]; char part2[100]; int cursor = 0, i, cnt1 = 0, cnt2 = 0, cnt = 0; int j = 0; int a = 0; int b = 0; int total = 0; printf("Enter any string: "); gets(str); printf("Enter word to search occurrences: "); gets(tosearch); for (i = 0; i < strlen(tosearch); i++) {...
```please convert this code to make only using for loop not while loop #include #include #define...
```please convert this code to make only using for loop not while loop #include #include #define MAX_SIZE 500 int main() { char str[MAX_SIZE]; char tosearch[MAX_SIZE]; char part1[100]; char part2[100]; int cursor = 0, i, cnt1 = 0, cnt2 = 0, cnt = 0; int j = 0; int a = 0; int b = 0; int total = 0; printf("Enter any string: "); gets(str); printf("Enter word to search occurrences: "); gets(tosearch); for (i = 0; i < strlen(tosearch); i++) {...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT