Question
Programming in C++ ** NO 2D-ARRAY **, We can use vectors, or linked list I need help with a program that can read the user
Programming in C++ ** NO 2D-ARRAY **, We can use vectors, or linked list
I need help with a program that can read the user input, and determine if it is a "N x N" matrix
if we use:
int main( ){ string str; getline(cin, str); cout << str; } | we are able to capture the first row, and I need to figure out how many columns are in that first row, so I can then finish looping the remaining of the user input, while getline is not empty |
Example of user input:
User Input | Explanation |
1 -2 3 | "1" space "-2" space "3" enter |
-2 3 -2 | "-2" space "3" space "-2" enter |
3 -1 2 | "3" space "-1" space "2" enter |
Note: The user was never asked or prompted anything, like "press 1 to continue 2 to exit". the program realized the user was done when there were no more entries, because getline was empty.
The idea is to identify how many rows are expected from the number of columns of the first row, in this example the first row is: 1 -2 3 indicates 3 columns, so we should expect a 3x3 matrix. if anything else is entered, then an ERROR should pop up
** CANNOT USE A 2D-ARRAY **
We can use vectors, or linked list
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started