473,320 Members | 2,071 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,320 software developers and data experts.

oop by robert lafore, exercise 10, chap 7... help?

It's the actual problem.

A matrix is a two-dimensional array. Create a class matrix that provides the same safety feature as the array class in Exercise 7; that is, it checks to be sure no array index is out of bounds. Make the member data in the matrix class a 10-by-10 array. A constructor should allow the programmer to specify the actual dimensions of the matrix (provided they’re less than 10 by 10). The member functions that access data in the matrix will now need two index numbers: one for each dimension of the array. Here’s what a fragment of a main() program that operates on such a class might look like:

Expand|Select|Wrap|Line Numbers
  1. matrix m1(3, 4); // define a matrix object
  2. int temp = 12345; // define an int value
  3. m1.putel(7, 4, temp); // insert value of temp into matrix at 7,4
  4. temp = m1.getel(7, 4); // obtain value from matrix at 7,4 
Now, help me with the idea. How can i initialize a member data (10 by 10 array) and then reinitialize the array to the given dimensions of matrix?
Apr 11 '15 #1

✓ answered by shockxd

Hi, Thank you for your time.

That article is good but it will take some time for me to digest. I will do it your way, "read and understand the article and solve the problem" if you say "It's the only way to do this problem. This problem needs those topics (in the article) to be covered by me".

Robert in his chapter 7 teaches basics about arrays like.
- Array Fundamentals (declaration, initialization, passing to functions etc.)
- Array as Class Member Data
- Array of Objects

That's it.

How can he give a problem like that which requires more understanding of arrays than he already gave. So, i think maybe problem belongs to wrong chapter??? or Is there a simpler way to re-initialize/re-assign the dimensions of a 10 by 10 array???

Please Comment on this.

I will go for the article and hopefully in 3/4 days i will be able to do it, just i wanna be sure.
Thank you again.

3 2421
weaknessforcats
9,208 Expert Mod 8TB
Read this:

http://bytes.com/topic/c/insights/77...rrays-revealed

THen post again with any further questions.
Apr 11 '15 #2
Hi, Thank you for your time.

That article is good but it will take some time for me to digest. I will do it your way, "read and understand the article and solve the problem" if you say "It's the only way to do this problem. This problem needs those topics (in the article) to be covered by me".

Robert in his chapter 7 teaches basics about arrays like.
- Array Fundamentals (declaration, initialization, passing to functions etc.)
- Array as Class Member Data
- Array of Objects

That's it.

How can he give a problem like that which requires more understanding of arrays than he already gave. So, i think maybe problem belongs to wrong chapter??? or Is there a simpler way to re-initialize/re-assign the dimensions of a 10 by 10 array???

Please Comment on this.

I will go for the article and hopefully in 3/4 days i will be able to do it, just i wanna be sure.
Thank you again.
Apr 11 '15 #3
weaknessforcats
9,208 Expert Mod 8TB
A 10 by 10 array is 100 elements contiguous in memory.

You can initialize these elements using a loop that cycles from 0 99.

Or you can get fancy and say, no, these 100 elements are really 10 arrays of 10 elements each. Now you use two loops where the outer loop cycles 0 to 9 and the inner loop cycles from 0 to 9. These are exactly the same elements in the above example. That is a 10 x 10.

Or you can say, no, these 100 elements are really an array of 5 elements where each element is an array of 2 elements where each of those element is an array of 10 elements. Now you need three loops. The outer loop cycles from 0 to 4, the middle loop cycles 0 to 1 and the inner loop cycles from 0 to 9. That is a 5 x 2 x 10. Still the same 100 elements from the first example.

It's not these arrays are structured differently rather it's your VIEW that is different. Re-read the last example in that article.

Note that when you allocate an array all you allocate is an area of memory. There are no rows or columns or anything else. You map that memory to be what you want. Run a loop from 0 to 99 on that memory and you will see your 10 x10 matrix initialized perfectly.

Things must work this way to preserve "pointer arithmetic" so that the compiler can calculate the addresses you want to use. You will find that when the compiler can't do that you will get compile errors until you preserve pointer arithmetic.
Apr 12 '15 #4

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

Similar topics

4
by: Sugapablo | last post by:
I have a dynamic form that that creates input variables named different things based on what it reads from the database. So, for example, it may create three fields, named ex12, ex23, and ex45...
9
by: JP SIngh | last post by:
Hi All I am trying to write a recursive function to list the managers and his employees in a tree like sctructure Manager 1 Emp1 Emp1.1 Emp 1.2 Emp 2
3
by: CoolPint | last post by:
Can anyone explain how I can make the following function accept an default arguement for the last parameter, which should be an optional functor? template <typename T, typename FUNCTOR> void...
0
by: John Roberts | last post by:
I bought Robert Lafore's *3rd* edition of "Object-Oriented Programming in C++" a couple of years ago (bought it new). The program files are no longer available from the publisher. Anyone have...
2
by: Repi3 | last post by:
im searching the solution to the execices. pls need help
5
by: Felix Collins | last post by:
Hi All, does anyone know any cleaver tricks to sort a list of outline numbers. An outline number is a number of the form... 1.2.3 they should be sorted in the following way... 1 1.1 1.2
9
by: Kurt Nesworthy | last post by:
Hi guys, Got a Visual Basic test to do by wedensday, but i dont have the faintest idea on how to do it. "A company has two schemes for paying monthly shift pay to its employees. Management are...
1
by: ZAHID KHAN | last post by:
Please Send Me Solved Programs Of Exercise 2,3,and 4 From Book Object Oriented Programming In C++ By Robert Lafore
3
by: majestic | last post by:
Hello, Is it possible that someone can help me with the following program? There are 500 light bulbs (numbered 1 to 500) arranged in a row. Initially they are all OFF. Starting with bulb 2, all...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.