![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
This code is to add two Matrices.
Updated code: On the next reply. Any help will be appreciated. Thanks.
__________________
Personal Portfolio TecBrain Support Forum Linux VS Windows ... Dont Even Think of it .. Distribution: Slackware if (OS==Linux) return success There are 10 kinds of people, those who can read binary numbers and those who can't. Last edited by TecBrain; Mar 2nd, 2005 at 10:42 AM. Reason: //Add |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
This is my updated code:
Thanks guys, seems better but I think #define maxrow 10 #define maxcol 10 Is causing some problems. #include <cstdlib>
#include <iostream>
#define maxrow 10
#define maxcol 10
class Matrix
{
public:
Matrix();
void ReadMatrix();
void PrintMatrix();
void addsub(char c, const Matrix &A, const Matrix &B);
Private:
int row,col;
//This is my array which both Matrices will be entered
float data[maxrow][maxcol];
};
Matrix A,b;
void Matrix::ReadMatrix()
{
const int N=10; //Max size of rows
const int M=10; // Max size fo col
int n,m;
do
cout << "Enter number of rows, should be less then" << N;
cin >> n;
while (!(n<+N) && (n<0)
do
cout << "Enter number of col, should be less then" << M;
cin >> m;
while (!(m<+M) && (m<0)
cout << "Enter elements of the first Matrix";
for (i=0;i<n;i++)
for(j=0;j<m;j++)
cin >> A.data[i][j];
cout << "Enter elements of the Second Matrix";
for (i=0;i<n;i++)
for(j=0;j<m;j++)
cin >> B.data[i][j];
}Errors: --------------------Configuration: Cpp1 - Win32 Debug-------------------- Compiling... Cpp1.cpp C:\Documents and Settings\Admin\Desktop\1DataStructure Assig1\Cpp1.cpp(17) : error C2062: type 'int' unexpected C:\Documents and Settings\Admin\Desktop\1DataStructure Assig1\Cpp1.cpp(17) : error C2238: unexpected token(s) preceding ';' C:\Documents and Settings\Admin\Desktop\1DataStructure Assig1\Cpp1.cpp(33) : error C2065: 'cout' : undeclared identifier C:\Documents and Settings\Admin\Desktop\1DataStructure Assig1\Cpp1.cpp(33) : error C2297: '<<' : illegal, right operand has type 'char [42]' C:\Documents and Settings\Admin\Desktop\1DataStructure Assig1\Cpp1.cpp(34) : error C2061: syntax error : identifier 'cin' C:\Documents and Settings\Admin\Desktop\1DataStructure Assig1\Cpp1.cpp(38) : error C2143: syntax error : missing ')' before 'do' C:\Documents and Settings\Admin\Desktop\1DataStructure Assig1\Cpp1.cpp(39) : error C2297: '<<' : illegal, right operand has type 'char [41]' C:\Documents and Settings\Admin\Desktop\1DataStructure Assig1\Cpp1.cpp(40) : error C2061: syntax error : identifier 'cin' C:\Documents and Settings\Admin\Desktop\1DataStructure Assig1\Cpp1.cpp(44) : error C2146: syntax error : missing ')' before identifier 'cout' C:\Documents and Settings\Admin\Desktop\1DataStructure Assig1\Cpp1.cpp(44) : error C2297: '<<' : illegal, right operand has type 'char [35]' C:\Documents and Settings\Admin\Desktop\1DataStructure Assig1\Cpp1.cpp(46) : error C2065: 'i' : undeclared identifier C:\Documents and Settings\Admin\Desktop\1DataStructure Assig1\Cpp1.cpp(47) : error C2065: 'j' : undeclared identifier C:\Documents and Settings\Admin\Desktop\1DataStructure Assig1\Cpp1.cpp(48) : error C2065: 'cin' : undeclared identifier C:\Documents and Settings\Admin\Desktop\1DataStructure Assig1\Cpp1.cpp(48) : error C2296: '>>' : illegal, left operand has type 'float' C:\Documents and Settings\Admin\Desktop\1DataStructure Assig1\Cpp1.cpp(48) : error C2297: '>>' : illegal, right operand has type 'float' C:\Documents and Settings\Admin\Desktop\1DataStructure Assig1\Cpp1.cpp(50) : error C2297: '<<' : illegal, right operand has type 'char [36]' C:\Documents and Settings\Admin\Desktop\1DataStructure Assig1\Cpp1.cpp(54) : error C2065: 'B' : undeclared identifier C:\Documents and Settings\Admin\Desktop\1DataStructure Assig1\Cpp1.cpp(54) : error C2228: left of '.data' must have class/struct/union type Error executing cl.exe. Cpp1.exe - 18 error(s), 0 warning(s)
__________________
Personal Portfolio TecBrain Support Forum Linux VS Windows ... Dont Even Think of it .. Distribution: Slackware if (OS==Linux) return success There are 10 kinds of people, those who can read binary numbers and those who can't. |
|
|
|
|
|
#3 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
OK... first off, why do you use two different sets of constants for the maximum number of rows and columns?
Anyway, to fix the errors:
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|