Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ help Need to output a matrix but it only outputs A single column that isn't correct (I am running this on a Linux server).

c++ help

Need to output a matrix but it only outputs A single column that isn't correct (I am running this on a Linux server). User should be able to enter contents of matrix manually or from a WAM file by >./progname < WAM which is what I used. User doesn't specify array size but was told that it wouldn't be any more than 10 and it is a square matrix.

My code:

#include #include #include using namespace std; #define MAX 1000 #define M 10 int main() { int i = 0; int j = 0; int matrix [MAX][MAX]; char x[MAX]; cout << "Enter the WAM: " << endl; cin.getline(x, MAX, ' '); stringstream ssin(x); while (ssin.good() && j < M) { ssin >> matrix[0][j]; ++j; } i = j;

for (int c = 1; c < i; c++) { cin.getline(x, MAX, ' '); stringstream ssin(x); j = 0; while (ssin.good() && j < M) { ssin >> matrix[c][j]; ++j; } }

cout << "The WAM entered is: " << endl; for (int c = 0; c < i; c++) { for (int d = 0; d < j; d++) { cout << matrix[c][d] << " "; } cout << endl; } return 0; }

WAM file content

0 0 355 0 695 0 0 0

0 0 74 0 0 348 0 0

355 74 0 262 0 269 0 0

0 0 262 0 0 242 0 0

695 0 0 0 0 151 0 0

0 348 269 242 151 0 83 306

0 0 0 0 0 83 0 230

0 0 0 0 0 306 230 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago