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. 5 1904 mo************* *@gmail.com wrote:
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.
You've got very precise instructions, it almost tells you how to write
the program line by line.
Which bit don't you understand?
class
private data member
binary - operator
default constructor
function
etc. etc.
The way to get help on a homework question is to post the code you have
written so far. That way we can tell what you understand and what you
don't. Even more importantly it shows that you are prepared to make and
effort and don't just expect to be given the answer.
Post your code and you will get help with it.
john
On Jun 20, 3:11 pm, mohammaditrad.. .@gmail.com wrote:
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.
Better to approach some tutorial sites which has loads of examples.
Regards,
Sarath
On Jun 20, 3:11 am, mohammaditrad.. .@gmail.com wrote:
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.
pay me and I'll write the program for you
On Jun 20, 11:18 am, John Harrison <john_androni.. .@hotmail.com>
wrote:
mohammaditrad.. .@gmail.com wrote:
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.
You've got very precise instructions, it almost tells you how to write
the program line by line.
Which bit don't you understand?
class
private data member
binary - operator
default constructor
function
etc. etc.
The way to get help on a homework question is to post the code you have
written so far. That way we can tell what you understand and what you
don't. Even more importantly it shows that you are prepared to make and
effort and don't just expect to be given the answer.
Post your code and you will get help with it.
john
dear sir i wirte this code but give error can u correct it please help
me
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
class Matrix
{
private :
int numRows, numCols ;
int elements [30] [30] ;
public :
Matrix(){
cout<<"paratmer ized constructor";
}
Matrix( int rows , int cols ) ;
void getMatrix ( ) ;
void displayMatrix ( ) ;
Matrix :: Matrix operator+();
};
Matrix :: Matrix ( int rows = 0 , int cols = 0)
{
numCols = cols ;
numRows = rows ;
for ( int i = 0 ; i < numRows ; i ++ )
{
for ( int j = 0 ; j < numCols ; j ++ )
{
elements [ i ] [ j ] = 0 ;
}
}
}
void Matrix :: getMatrix ( )
{
for ( int i = 0 ; i < numRows ; i ++ )
{
for ( int j = 0 ; j < numCols ; j ++ )
{
cin >elements [ i ] [ j ] ;
//cout<<"Enter the 1st Matrix";
}
}
//cout<<"Enter the 2nd Matrix"<<endl;
}
void Matrix :: displayMatrix ( )
{
for ( int i = 0 ; i < numRows ; i ++ )
{
cout << "| " ;
for ( int j = 0 ; j < numCols ; j ++ )
{
cout << elements [ i ] [ j ] << " " ;
}
cout << "|" << endl ;
}
cout<<'\n';
cout<<'\n';
}
Matrix :: Matrix operator + (Matrix add)
{
Matrix temp;
temp.numCols=nu mCols + add.numCols;
temp.numRows=nu mRows + add.numRows;
return temp;
}
void main ( )
{
Matrix matrix1(2, 2),matrix2(2,2) ;
matrix1.getMatr ix ( ) ;
matrix2.getMatr ix();
//Matrix = matrix1 + matrix2 ;
matrix1.display Matrix ( ) ;
matrix2.display Matrix ( ) ;
//
system ( "PAUSE" ) ;
getch();
}
On Jun 22, 6:57 pm, mohammaditrad.. .@gmail.com wrote:
On Jun 20, 11:18 am, John Harrison <john_androni.. .@hotmail.com>
wrote:
mohammaditrad.. .@gmail.com wrote:
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.
You've got very precise instructions, it almost tells you how to write
the program line by line.
Which bit don't you understand?
class
private data member
binary - operator
default constructor
function
etc. etc.
The way to get help on a homework question is to post the code you have
written so far. That way we can tell what you understand and what you
don't. Even more importantly it shows that you are prepared to make and
effort and don't just expect to be given the answer.
Post your code and you will get help with it.
john
dear sir i wirte this code but give error can u correct it please help
me
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
class Matrix
{
private :
int numRows, numCols ;
int elements [30] [30] ;
public :
Matrix(){
cout<<"paratmer ized constructor";}
Matrix( int rows , int cols ) ;
void getMatrix ( ) ;
void displayMatrix ( ) ;
Matrix :: Matrix operator+();
};
Matrix :: Matrix ( int rows = 0 , int cols = 0)
{
numCols = cols ;
numRows = rows ;
for ( int i = 0 ; i < numRows ; i ++ )
{
for ( int j = 0 ; j < numCols ; j ++ )
{
elements [ i ] [ j ] = 0 ;}
}
}
void Matrix :: getMatrix ( )
{
for ( int i = 0 ; i < numRows ; i ++ )
{
for ( int j = 0 ; j < numCols ; j ++ )
{
cin >elements [ i ] [ j ] ;
//cout<<"Enter the 1st Matrix";
}
}
//cout<<"Enter the 2nd Matrix"<<endl;}
void Matrix :: displayMatrix ( )
{
for ( int i = 0 ; i < numRows ; i ++ )
{
cout << "| " ;
for ( int j = 0 ; j < numCols ; j ++ )
{
cout << elements [ i ] [ j ] << " " ;}
cout << "|" << endl ;
}
cout<<'\n';
cout<<'\n';
}
Matrix :: Matrix operator + (Matrix add)
{
Matrix temp;
temp.numCols=nu mCols + add.numCols;
temp.numRows=nu mRows + add.numRows;
return temp;
}
void main ( )
{
Matrix matrix1(2, 2),matrix2(2,2) ;
matrix1.getMatr ix ( ) ;
matrix2.getMatr ix();
//Matrix = matrix1 + matrix2 ;
matrix1.display Matrix ( ) ;
matrix2.display Matrix ( ) ;
//
system ( "PAUSE" ) ;
getch();
}
What's the error? PS. main should return int, not void.
(use "return(0)" at the end of main()). In addition,
your Addition operator does NOT add the matrices. You
are adding the _sizes_ of the matrices together, you
need to add the _elements_ together! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: da Vinci |
last post by:
Hello again.
I have a question regaring pass-by-reference and multiple functions.
This is an assignment that I have to use pass-by-reference for
everything.
First off, I made the following program to figure out what was wrong
in my main program. This program works fine. It compiles AND the
values are correct in the output.
|
by: tyler_durden |
last post by:
thanks a lot for all your help..I'm really appreciated...
with all the help I've been getting in forums I've been able to continue
my program and it's almost done, but I'm having a big problem that I
believe if it's solved, the remaining stuff is easy...
my full program until now is here:
http://www.geocities.com/tom4_h4wk/progmail.zip
the problem is the segmentation fault when main trys to run
leficheiro.c.... the *.c2 files are the...
|
by: David Van D |
last post by:
Hi there,
A few weeks until I begin my journey towards a degree in Computer
Science at Canterbury University in New Zealand,
Anyway the course tutors are going to be teaching us JAVA wth bluej and
I was wondering if anyone here would be able to give me some tips for
young players such as myself, for learning the language.
Is this the best Newsgroup for support with JAVA?
|
by: promiscuoustx |
last post by:
I am trying to get my program to compile, but it will not complete. At line 79 it states, cannot convert 'float()()' to 'float' in assignment. Here is my code.
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cctype>
#include <stdlib.h>
#include <sstream>
using namespace std;
|
by: raa abdullah |
last post by:
Overview
A conflict-serializbility\recoverability checker, SCR, is a program that takes in a schedule and outputs 2 decisions: Conflict serialzable or Not confilict serializable AND Recoverable or Not recoverable. The following is a detailed description of the program.
Input
The input to SCR should be a schedule of operations. It should be in a text file (.txt) where each line is in the following format:
Operation TransactionNum
...
| |
by: Bsnpr8 |
last post by:
I need help guys, i have to many stuff to do, because i am in my last 2 weeks of the university, my last assignment is to do a spell checker in C++, i have an idea but nothing is coming out. I really need help, could someone do, anything to help me i don't have much time, here are the instructions:
Instructions:
In this project, you are asked to develop your own spell-checker utility. We make suggestions to help get you started. You should...
|
by: fatboySudsy |
last post by:
Hi,
I have constructed a client program that has given me some error codes that i just cannot see. I was wondering if a different set of eyes with much more experience than me could help me out. Here are the error codes and underneath i have listed the program. Thanks in advance for looking.
client.c: In function `main':
client.c:118: error: syntax error before '-' token
client.c: At top level:
client.c:132: error: conflicting types...
|
by: weidongtom |
last post by:
Hi,
I tried to implement the Universal Machine as described in
http://www.boundvariable.org/task.shtml, and I managed to get one
implemented (After looking at what other's have done.) But when I use
to run a UM program, I kept on getting error messages. I have used
someone else's implementation and it runs fine. I have compared my
code with other's and I still can't figure it out what's wrong with
mine. So please help me out, after 3...
|
by: mohammaditraders |
last post by:
Question # 1 Write a program which consists of a class
named Student, the class should consists of three data members Name,
Ob_marks, Total_marks and two member functions Cal_percentage() which
calculate the percentage of the student by the formula (Ob_marks *
100 )/Total_marks and Display() which show all information of the
student. The class should also contain the default constructor which
initializes all the data member of...
|
by: fido19 |
last post by:
Once upon a time, there lived a chimpanzee called Luycha Bandor (aka Playboy Chimp).
Luycha was unhappily married to Bunty Mona, a short but cute little lady chimp. Luycha
was tall and handsome – he was feeling uncomfortable taking Bunty to public places
along with him. People would stare at them all the while. At one point, Luycha could not
stand it anymore and he decided to do some justice to his name. He started looking for a
new hope in...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |