GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 22-Jun-2007, 16:06
fahad fahad is offline
New Member
 
Join Date: Mar 2007
Posts: 9
fahad has a little shameless behaviour in the past
Question

Write a program which overloads a binary Minus (-) operator


Write a program which overloads a binary Minus (-) operator,
The program will contain a class Matrix, This class will contain a private data member Array[][] which store int values. The class will further contain a Default constructor, get() function which takes values for array from the user and also contain a Display function witch display the array on the screen,
In main function create three objects Mat1, Mat2, Mat3 of this class, first call get() and Display() functions with Mat1 and Mat2 objects then implement the statement Mat3 = Mat1 - Mat2; and call Display() function with Mat3.
Note: The matrix should be 2x2.


Please help me to correct following code:

Code:
#include<iostream.h> TMatrix = class(TObject) <Operator -> overload; TMatrix.<Operator ->; Self.array[ ][ ] = This.array[ ][ ] int main; int Mat1, Mat2, Mat3: TMatrix; { Mat1 := TMatrix.Create(); Mat2 := TMatrix.Create(); Mat3 := TMatrix.Create(); Mat1.get(); Mat1.Display(); Mat2.get(); Mat2.Display(); Mat3 = Mat1 - Mat2; Mat3.Display(); }
Last edited by LuciWiz : 23-Jun-2007 at 14:25. Reason: Added [code] tags
  #2  
Old 22-Jun-2007, 16:16
Kimmo Kimmo is offline
Regular Member
 
Join Date: Mar 2007
Location: Finland
Posts: 450
Kimmo is a jewel in the roughKimmo is a jewel in the roughKimmo is a jewel in the rough

Re: Write a program which overloads a binary Minus (-) operator


Is this really C++ code?
  #3  
Old 22-Jun-2007, 16:35
fahad fahad is offline
New Member
 
Join Date: Mar 2007
Posts: 9
fahad has a little shameless behaviour in the past

Re: Write a program which overloads a binary Minus (-) operator


Quote:
Originally Posted by Kimmo
Is this really C++ code?
This is just hint of c++ code
  #4  
Old 22-Jun-2007, 18:01
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 6,153
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Write a program which overloads a binary Minus (-) operator


Quote:
Originally Posted by fahad
Please help me to correct following code:

There is not a single line of anything in your post that is correct. (Well, #include<iostream.h> is not technically incorrect, but the use of <iostream.h> is not recommended.) Nothing else is valid; not even close. Period.

The way it works is: you seriously try to make something that satisfies the assignment. If you have problems, then show us what you seriously tried and ask specific questions.

Start at the beginning:

1. Make a Matrix class according to your assignment.

2. Write a program with a main() function that creates object of your class and test the display function. (You will have to have some way of getting things into your matrix. Maybe a constructor that takes arrays or vectors of ints. Whatever.)

Then, after you can create and display objects of the class:

3. Look at examples of overloaded operators. Look in your book. Look in class notes. Look for examples on the web. Look somewhere. You can't just make up your own rules for creating something and call it C++. (Well, you can, but I'm guessing it won't work the way that you wish it would.)

If you have problems anywhere along the way, then show us what code you actually compiled (or tried to compile). If there were any messages that you don't understand, then post the messages also.

Regards,

Dave
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 07:44
BOOKEEPING program, HELP!! yabud C Programming Language 10 17-Nov-2006 03:48
Need help writing a program that reads from a file and converts it to binary. edd_y_123 C Programming Language 3 18-Dec-2005 10:21
C++ PhoneBook marita C++ Forum 46 12-Jun-2005 12:10
Anyone can write a program code for this??? chriskan76 C Programming Language 1 19-Oct-2004 20:25

Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 07:24.


vBulletin, Copyright © 2000 - 2014, Jelsoft Enterprises Ltd.