So I took on a project which is beyond my current level and understanding of C++. Basically I am writing a program to accept user defined matrices, then to perform assorted functions to them such as converting them to RREF, finding the inverse, etc.. I am still at the point where I am reading in the matrix from the user, then just displaying a list of all the matrices entered. The next step I will be implementing is the ability to search and edit an existing matrix by name. Anyway, I have a bunch of errors, and obviously don't know what i'm doing.
1 2 3 4 5 6 7
error C3867: 'Matrix::fullMatrix': function call missing argument list; use '&Matrix::fullMatrix' to create a pointer to member
error C2109: subscript requires array or pointer type
error C2228: left of '.push_back' must have class/struct/union
warning C4018: '<' : signed/unsigned mismatch
error C2228: left of '.size' must have class/struct/union
error C3867: 'Matrix::fullMatrix': function call missing argument list; use '&Matrix::fullMatrix' to create a pointer to member
error C2109: subscript requires array or pointer type
struct Matrix
{
int numOfRows, numOfColumns;
string name;
vector <double> oneRow; // holds one row
vector < vector <double> > fullMatrix(int); // contain all of the rows, accessed by row number
};
void displayMenu();
Matrix addMatrix(vector <Matrix>);
void viewAll(vector <Matrix>);
int main()
{
vector <Matrix> Matrices; // holds all of the matrices
int choice; // choice from menu
Matrix tempMatrix;
do
{
displayMenu();
cin >> choice;
switch (choice)
{
case 1:
Matrices.push_back(addMatrix(Matrices)); // adds full matrix struct to array of matrixes
break;
case 2:
viewAll(Matrices);
break;
case 9:
system("pause");
return 0;
break;
default:
cout << "\nERROR: Invalid Choice!";
break;
}
} while (choice != 9);
system("pause");
return 0;
}
Matrix addMatrix(vector <Matrix>)
{
Matrix newMatrix;
cout << "\n Matrix name: ";
cin >> newMatrix.name;
cout << "\nNumber of rows: ";
cin >> newMatrix.numOfRows;
cout << "\nNumber of columns: ";
cin >> newMatrix.numOfColumns;
for (int i = 0; i < newMatrix.numOfRows; i++)
{
for (int j = 0; j<newMatrix.numOfColumns; j++)
{
int tempVal = 0;
cout << "Enter the number for Matrix 1";
cin >> tempVal;
newMatrix.oneRow.push_back(tempVal);
}
newMatrix.fullMatrix[i].push_back(newMatrix.oneRow); // adds one row vector to all rows vector
}
return newMatrix;
}
View all
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
void viewAll(vector <Matrix> Matrices)
{
Matrix newMatrix;
for (int s = 0; s < Matrices.size(); s++)
{
cout << "\n\nName: " << Matrices[s].name;
for (int n = 0; n < Matrices[s].fullMatrix.size(); n++)
{
cout << Matrices[s].fullMatrix[s]; // this will not work, need a for loop for extracting rows from fullMatrix
cout << endl;
}
}
}
Again, sorry for the really bad code. I'm getting confused with having structures inside vectors which are inside another vector. I would appreciate it if someone wouldn't mind giving me ideas on how to fix this. Sorry for coming here with so many errors.
you're declaring a function called Matrix::fullMatrix that takes an int as an argument, and returns a vector of vectors. Nowhere in your posted code do you actually define the body of the function.
Here:
newMatrix.fullMatrix[i].push_back(newMatrix.oneRow);
(and elsewhere) you're attempting to use fullMatrix as a data member of Matrix.
If you want it to be a data member, why do you have the (int) in the declaration?