Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added PromptForMatrix #33

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ bool PromptForRetry(){ //Asks user if they'd like to retry in case of failed inp
int PromptForInteger(string prompt){
string userInput;
bool allNumbers = true;
cout << endl << prompt;
cout << prompt;
cin >> userInput;

for(int i = 0; i < userInput.length(); i++){ //Checks for any non integer characters in userInput
Expand All @@ -100,12 +100,45 @@ int PromptForInteger(string prompt){
return PromptForInteger("Invalid input, please enter a number: ");
}

vector<int> PromptForMatrixRow(int numRow, int numColumns){ //Returns a matrix row
vector<int> row;
for(int i = 1; i <= numColumns; i++){
string prompt = "Enter the number for column " + to_string(i) + " in row " + to_string(numRow) + ": ";
row.push_back(PromptForInteger(prompt));
}
return row;
}

vector<vector<int>> AssembleMatrix(int numRows, int numColumns){ //Returns completed matrix
vector<vector<int>> matrix;
for(int i = 1; i <= numRows; i++)
matrix.push_back(PromptForMatrixRow(i, numColumns));
return matrix;
}

vector<vector<int>> PromptForMatrix(){ //Returns matrix after assembling it with user
int numRows, numColumns;
cout << "Hello\nThis program will calculate the reduced row echelon form of a given matrix\nLet's begin by getting your matrix dimensions\n";
numRows = PromptForInteger("Enter the number of rows: ");
numColumns = PromptForInteger("Great! Now enter the number of columns: ");
cout << "\nYou have chosen to use a " << numRows << "x" << numColumns << " matrix\nYou will now be prompted to insert the matrix values, pay attention to the row and column numbers";
return AssembleMatrix(numRows, numColumns);
}

int main(){
// This is a test of the DisplayRREF function:

/* This is a test of the DisplayRREF function:
vector< vector<int> > h = {{1,2,3}, {4,5,6}, {7,8,9}};
DisplayRREF(h);
// This is the end of the test.
This is the end of the test */

vector<vector<int>> test = PromptForMatrix();
for(int i = 0; i < test.size(); i++){
for(int j = 0; j < test.at(i).size(); j ++)
cout << test.at(i).at(j) << " ";
cout << endl;
}

return 0;
}

Expand Down
Binary file modified main.exe
Binary file not shown.