473,385 Members | 1,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how can we add two matrices in the example given below?

Expand|Select|Wrap|Line Numbers
  1. class Matrix1
  2. {
  3.  
  4. Protected:
  5. int ** data;
  6. int row,col;
  7. Public:
  8.  
  9. };
  10. Class Matrix2 : Public Matrix
  11. {
  12. Public:
  13. Matrix2()
  14. {
  15.  
  16. }
  17. Matrix2 (int a, int b):Matrix1(a,b)
  18. {
  19.  
  20. }
  21. void resize()
  22. {
  23.  
  24. //?????
  25.  
  26. }
  27.  
  28. };
  29. // can we do this in our driver/main file(function) i.e.
  30. Matrix2 m1(3,4);
  31. Matrix2 m2(3,4);
  32. Matrix m=m1+m2;
  33. // is this legal ? if yes, then how will it work ?
Aug 29 '13 #1
2 1201
weaknessforcats
9,208 Expert Mod 8TB
Write the necessary operator+ and operator=.
Aug 29 '13 #2
Nepomuk
3,112 Expert 2GB
First of all, you have to define what "adding two matrices" means mathematically. What are the requirements? (Probably same number of rows and columns?) What is the expected result?
Also, from a technical standpoint: How do you want to deal with invalid input? Just ignore it and return garbage? Return some kind of error? Try to add what you can, even though it's probably nonsense?

Once you've decided on those things, you'll have to write the functions weaknessforcats described (or alternative functions I guess; you could name a function add if you prefer). To do so, I'd expect you need nested for loops, though the details depend on your decisions I mention above.
Aug 30 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: pathisunil | last post by:
Dear All I have an xmldocument which is as formed below. It is a bit of loopy in nature. can anyone kindly let me know how can i write a xslt which would take a parameter which is an...
6
by: chiara | last post by:
Hi everybody! I am just at the beginning as a programmer, so maybe this is a stupid question...Anyway,I need to write a function in C to generate generate all possible strings of given length...
0
pgmrkim
by: pgmrkim | last post by:
Thanks for the great code example. I've been trying to do a similar client-side script for a few days now.
1
by: Usman Jamil | last post by:
Hi I'm having problem resolving DNS records of a domain using C#. What I want to do is an exact replica of this command nslookup.exe -type=MX i.e I need to resolve the MX record of a...
1
by: Nithya Kalyani | last post by:
Hi Expert, I m a student, can any one help me in finding the answer of below one. The C programs given below contain errors, rectify them as needed. a) void main() { char linebuf; char...
2
by: rasmidas | last post by:
I have a text file. I need to search for two strings and replace the string for values from another line. I am attaching the text file. The requirement is like below: For every :61: line it...
3
by: aeroranger | last post by:
Hi all, My file has characters and numbers in the format given below: # 1 2 3 4 5
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.