Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   Matrices and Defining my Array Question (http://www.programmingforums.org/showthread.php?t=2532)

TecBrain Mar 1st, 2005 6:16 PM

Matrices and Defining my Array Question
 
This code is to add two Matrices.

Updated code: On the next reply.

Any help will be appreciated.

Thanks.

TecBrain Mar 2nd, 2005 10:41 AM

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)

Ooble Mar 2nd, 2005 4:46 PM

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:

  1. You need using namespace std; after the #includes (2).
  2. private is lowercase (16).
  3. I believe you want a capital B (22).
  4. Your do-while loops should be structured like this:
    :

    do {
     
    ...
     
    ...
     
     } while (blah);

    You haven't closed the brackets after while or used braces.
Enjoy.


All times are GMT -5. The time now is 6:15 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC