Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 1st, 2005, 6:16 PM   #1
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 4 TecBrain is on a distinguished road
Cool 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.
__________________
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
TecBrain is offline   Reply With Quote
Old Mar 2nd, 2005, 10:41 AM   #2
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 4 TecBrain is on a distinguished road
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.
TecBrain is offline   Reply With Quote
Old Mar 2nd, 2005, 4:46 PM   #3
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:31 PM.

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