473,386 Members | 1,721 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,386 software developers and data experts.

need help plz

Bigj0410
i've been trying to figure out these questions and i can't seem to understand them...can anyone help?

1)Write a full program in C++ that creates the two-dimensional randomArray
array with 10 rows and 10 columns, and fills it with random numbers
respectively: the first row with random number in range [1, 100), the second
row with random number in range [100, 200), …, the 10th row with random
number in range [900, 1000), The program then displays the array elements
on-screen 10 in each row.

2) Create two arrays with 10 elements averageRows and averageColums.
Calculate the average value for each row of randomArray and assign them
respectively to elements of averageRows array. (The average of the first row
of randomArray to the first element of averageRows, … the average of the
last row of randomArray to the last element of averageRows). Fill in the
same way the averageColums array but this time with average values of
columns of randomArray. Calculate the average of the diagonal of array
averageRows (e00, e11, …, e99) and the average of elements of the second
diagonal of averageRows (e90, e81, …, e09). Display all the results on screen.


thx in advance ;)
Feb 20 '07 #1
36 1839
sicarie
4,677 Expert Mod 4TB
i've been trying to figure out these questions and i can't seem to understand them...can anyone help?

1)Write a full program in C++ that creates the two-dimensional randomArray
array with 10 rows and 10 columns, and fills it with random numbers
respectively: the first row with random number in range [1, 100), the second
row with random number in range [100, 200), …, the 10th row with random
number in range [900, 1000), The program then displays the array elements
on-screen 10 in each row.

2) Create two arrays with 10 elements averageRows and averageColums.
Calculate the average value for each row of randomArray and assign them
respectively to elements of averageRows array. (The average of the first row
of randomArray to the first element of averageRows, … the average of the
last row of randomArray to the last element of averageRows). Fill in the
same way the averageColums array but this time with average values of
columns of randomArray. Calculate the average of the diagonal of array
averageRows (e00, e11, …, e99) and the average of elements of the second
diagonal of averageRows (e90, e81, …, e09). Display all the results on screen.


thx in advance ;)
What don't you understand? Is it the data creation, the manipulation...?
Feb 20 '07 #2
both of them...its so frustrating...btw...i'm a rookie to programming
Feb 20 '07 #3
sicarie
4,677 Expert Mod 4TB
both of them...its so frustrating...btw...i'm a rookie to programming
Ok, so you need help with the algorithm - let's take them one at a time.

Can you tell me the steps you would take to solve the first one, without a computer?
Feb 20 '07 #4
basically..make 10 rows with random numbers in them starting in the 1-100 range on the first row....100,200 on da second and so on til the 10th row....i really suck at this
Feb 20 '07 #5
sicarie
4,677 Expert Mod 4TB
basically..make 10 rows with random numbers in them starting in the 1-100 range on the first row....100,200 on da second and so on til the 10th row....i really suck at this
Nah, you're just starting out. Nobody's amazing when they start out - but we can get you there ;)

So - to refine your algorithm a bit:

create array[10][10]
for each i in array[1][i]
input random number between 1 and 100
for each i in array[2][i]
input random number between 100 and 200
for each i in array[3][i]
input random number between 200 and 300
for each i in array[4][i]
input random number between 300 and 400
and so on until 10

does that look right?

If so, how familiar are you with the rand() function?
Feb 20 '07 #6
yea it looks right...and yea i'm a bit familiar wit ran()..etc :)
Feb 20 '07 #7
sicarie
4,677 Expert Mod 4TB
yea it looks right...and yea i'm a bit familiar wit ran()..etc :)
Ok, so are you starting to see how (from the algorithm) this is going to come together?

I'm sure you can create the headers and main declaration - then you just need to follow your algorithm.
Feb 20 '07 #8
Ok, so are you starting to see how (from the algorithm) this is going to come together?

I'm sure you can create the headers and main declaration - then you just need to follow your algorithm.


yea i'm starting to see it :)
Feb 20 '07 #9
sicarie
4,677 Expert Mod 4TB
yea i'm starting to see it :)
Ok, so you have your basic structure, and your arrays declared, right?

Then you just need to figure out how to get the random number in between 1 and 100.

I think this link will give you a good idea of how to do that - but definitely post if you get confused.

(Anyone else have a good link to show this?)
Feb 20 '07 #10
Ok, so you have your basic structure, and your arrays declared, right?

Then you just need to figure out how to get the random number in between 1 and 100.

I think this link will give you a good idea of how to do that - but definitely post if you get confused.

(Anyone else have a good link to show this?)

yea i'm startting to understand this..a bit...i'm a slow learner too
Feb 20 '07 #11
sicarie
4,677 Expert Mod 4TB
yea i'm startting to understand this..a bit...i'm a slow learner too
Hey, as long as you're learning. I just made a jackass of myself in another thread. It's all about keeping with it and learning something from it.
Feb 20 '07 #12
sicarie
4,677 Expert Mod 4TB
Posted from users PM:
so far this is wut i got...
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int rand[10];
  7. int i;
  8. for ( i = 1; i < 10; i++)
  9. cin >> random[i]=1;
  10.  
is this right so far?
You're getting the idea, but there are a few comment's I'd like to make.

1) naming variables. Once you get into larger programs, it's good practice to name variables with descriptive names. You did this, but you are also going to be using the rand() function to get the random numbers. This is going to make these two confusing. I would try 'columns' or 'matrix' or something a bit more unique, but still descriptive of what it is.

2) you declare rand and then try to access random. The method of access is correct (you use i as the index correctly), but the variable name isn't correct - this will cause an error.

3) you have the user entering in the values for the array. You will want to declare rand and assign it to a number (that will get overwritten ever time you call another random number), and then set that equal to the array.

4) This might be unintentional, but it's good that you started small - only did one part of the double-for loop, 2-d array first, and then when you understand it, it'll be very simple to make it bigger.

5) You declared 'int main()' and so should end with a 'return 0; }' (The '}' should be on the next line, I just don't know how to format it off the top of my head, without using the [ code] tags)
Feb 20 '07 #13
Posted from users PM:

You're getting the idea, but there are a few comment's I'd like to make.

1) naming variables. Once you get into larger programs, it's good practice to name variables with descriptive names. You did this, but you are also going to be using the rand() function to get the random numbers. This is going to make these two confusing. I would try 'columns' or 'matrix' or something a bit more unique, but still descriptive of what it is.

2) you declare rand and then try to access random. The method of access is correct (you use i as the index correctly), but the variable name isn't correct - this will cause an error.

3) you have the user entering in the values for the array. You will want to declare rand and assign it to a number (that will get overwritten ever time you call another random number), and then set that equal to the array.

4) This might be unintentional, but it's good that you started small - only did one part of the double-for loop, 2-d array first, and then when you understand it, it'll be very simple to make it bigger.

5) You declared 'int main()' and so should end with a 'return 0; }' (The '}' should be on the next line, I just don't know how to format it off the top of my head, without using the [ code] tags)

but still just trying to write it is frustrating.....wut i do is write it on paper then type it out....i keep getting messed up...how would u write it? if i don't mind asking
Feb 20 '07 #14
sicarie
4,677 Expert Mod 4TB
but still just trying to write it is frustrating.....wut i do is write it on paper then type it out....i keep getting messed up...how would u write it? if i don't mind asking
Well, I'd start out with the shell:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.  
  7.     return 0;
  8. }
  9.  
and then I would put my algorithm inside


Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     //  create matrix[10][10]
  7.     // for each i in matrix [1][i]
  8.         // get random number between 1 and 100
  9.         // matrix[1][i] = random number
  10.     // for each i in matrix [2][i]
  11.         // get random number betwee 100 and 200
  12.         // matrix[2][i] = rand
  13.     /// and on to matrix [10][i]
  14.     return 0;
  15. }
  16.  
Then I would go through and start breaking that algorithm down - into statements that could be in a single line, and then try to turn it into code


Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     //  create matrix[10][10]
  7.     int matrix[10][10];
  8.     int tmp_rand;
  9.     // for each i in matrix [1][i]
  10.     for (int i = 0; i < 10; i++) {
  11.         // get random number between 1 and 100
  12.         /* I'm not going to give this away, but I'm pretty sure you could figure it out */
  13.         // matrix[1][i] = random number
  14.     // for each i in matrix [2][i]
  15.         // get random number betwee 100 and 200
  16.         // matrix[2][i] = rand
  17.     /// and on to matrix [10][i]
  18.     }
  19.     return 0;
  20. }
  21.  
and so on. This way it starts out as a working template (even though it doesn't do anything, it will compile), and builds up from there - and my code will be commented!

Does that make sense? Help at all?
Feb 20 '07 #15
Well, I'd start out with the shell:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.  
  7.     return 0;
  8. }
  9.  
and then I would put my algorithm inside


Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     //  create matrix[10][10]
  7.     // for each i in matrix [1][i]
  8.         // get random number between 1 and 100
  9.         // matrix[1][i] = random number
  10.     // for each i in matrix [2][i]
  11.         // get random number betwee 100 and 200
  12.         // matrix[2][i] = rand
  13.     /// and on to matrix [10][i]
  14.     return 0;
  15. }
  16.  
Then I would go through and start breaking that algorithm down - into statements that could be in a single line, and then try to turn it into code


Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     //  create matrix[10][10]
  7.     int matrix[10][10];
  8.     int tmp_rand;
  9.     // for each i in matrix [1][i]
  10.     for (int i = 0; i < 10; i++) {
  11.         // get random number between 1 and 100
  12.         /* I'm not going to give this away, but I'm pretty sure you could figure it out */
  13.         // matrix[1][i] = random number
  14.     // for each i in matrix [2][i]
  15.         // get random number betwee 100 and 200
  16.         // matrix[2][i] = rand
  17.     /// and on to matrix [10][i]
  18.     }
  19.     return 0;
  20. }
  21.  
and so on. This way it starts out as a working template (even though it doesn't do anything, it will compile), and builds up from there - and my code will be commented!

Does that make sense? Help at all?


yea it does make a bit sense...it does help...thx dawg (thumbs up)....but i'll still ask for help though :)
Feb 20 '07 #16
sicarie
4,677 Expert Mod 4TB
yea it does make a bit sense...it does help...thx dawg (thumbs up)....but i'll still ask for help though :)
Absolutely - we're more than happy to help.

And, just in case you didn't see (if you didn't you shouldn't worry about it - I'm sure it will come to you when you start programming), there is another optimization you can make in the algorithm.
Feb 20 '07 #17
Absolutely - we're more than happy to help.

And, just in case you didn't see (if you didn't you shouldn't worry about it - I'm sure it will come to you when you start programming), there is another optimization you can make in the algorithm.
really? like what?
Feb 20 '07 #18
sicarie
4,677 Expert Mod 4TB
really? like what?
Well, at least in my algorithm (as yours only deals with half first). Just think of ways to keep yourself from having to write more code.
Feb 20 '07 #19
Well, at least in my algorithm (as yours only deals with half first). Just think of ways to keep yourself from having to write more code.

ok that sounds good...btw...i'm starting to understand the program u wrote...thx again ;)
Feb 20 '07 #20
sicarie
4,677 Expert Mod 4TB
ok that sounds good...btw...i'm starting to understand the program u wrote...thx again ;)
Good, that was the point. And by the way - I didn't write it - you are going to. You did come up with the algorithm and most of the code. You know what you're doing, you just don't think you do yet.

Definitely post again if you get stuck!
Feb 20 '07 #21
ok ...i was going over this plus reading other things on arrays and etc which then i got confused and this is wut i came up with so far
btw...if u don't mind i used your variables

#include <iostream>
using namespace std;

int main()
{
int matrix[10][10]
int tmp_rand;
for (int i = 0; i < 10; i++);
{ matrix[1][i] = (1 < i < 100);
Feb 20 '07 #22
sicarie
4,677 Expert Mod 4TB
ok ...i was going over this plus reading other things on arrays and etc which then i got confused and this is wut i came up with so far
btw...if u don't mind i used your variables

#include <iostream>
using namespace std;

int main()
{
int matrix[10][10]
int tmp_rand;
for (int i = 0; i < 10; i++);
{ matrix[1][i] = (1 < i < 100);
I dont' mind at all. Um, ok, I think you're trying to do too much at once. Let's break that up into two steps:

1) get random number between 1 and 100
2) assign number to matrix[][]

How would you do the first?
Feb 20 '07 #23
I dont' mind at all. Um, ok, I think you're trying to do too much at once. Let's break that up into two steps:

1) get random number between 1 and 100
2) assign number to matrix[][]

How would you do the first?
the first part i remember from math that if a number is between two numbers ...i assume thats wut u do in c++ so i put it there (shrugs my shoulders)
but the matrix thing its coming to me now
Feb 20 '07 #24
sicarie
4,677 Expert Mod 4TB
the first part i remember from math that if a number is between two numbers ...i assume thats wut u do in c++ so i put it there (shrugs my shoulders)
but the matrix thing its coming to me now
Good!

Well, here I'm also assuming you can get a random number in the first place - let's start there, how would you do that?
Feb 20 '07 #25
Good!

Well, here I'm also assuming you can get a random number in the first place - let's start there, how would you do that?

ihave no clue ...at first i thought i knew it but i don't sorry :(..i really suck at this
Feb 20 '07 #26
sicarie
4,677 Expert Mod 4TB
ihave no clue ...at first i thought i knew it but i don't sorry :(..i really suck at this
Ah! Ok, sorry, that was my fault, I was trying to push you to do something you didn't know. It's ok, check this link for rand() . That should start to clear up a lot more.
Feb 20 '07 #27
Ah! Ok, sorry, that was my fault, I was trying to push you to do something you didn't know. It's ok, check this link for rand() . That should start to clear up a lot more.
ok its begining to look ok...so how would i input this in the program?
Feb 20 '07 #28
sicarie
4,677 Expert Mod 4TB
ok its begining to look ok...so how would i input this in the program?
Well, that's what I'm asking you - there are examples in the article. Just worry about putting in one. How would you assign a random number from rand() to tmp_rand?
Feb 20 '07 #29
Well, that's what I'm asking you - there are examples in the article. Just worry about putting in one. How would you assign a random number from rand() to tmp_rand?
?? (shrugs my shoulders)
Feb 20 '07 #30
sicarie
4,677 Expert Mod 4TB
?? (shrugs my shoulders)
14th line in their example.
Feb 20 '07 #31
14th line in their example.
14th line?
Feb 20 '07 #32
sicarie
4,677 Expert Mod 4TB
14th line?
In the example code of the link I posted.
Feb 20 '07 #33
sicarie
4,677 Expert Mod 4TB
In the example code of the link I posted.
You would assign it the way you assign anything. As long as the library (stdlib) is included, you can just assign a random number to any other number (say tmp_rand).
Feb 20 '07 #34
In the example code of the link I posted.
u mean "rand() % 10 + 1;"?
Feb 20 '07 #35
sicarie
4,677 Expert Mod 4TB
u mean "rand() % 10 + 1;"?
Well, I was talking more how they assign it.

variable = rand() % 10 + 1;

gives variable (I dont' remember what they used) a random value.

The mod (%) 10 is what you're going to be interested in next - this returns a number between 0 and 10. So you just have to change that to give you one between 1 and 100.
Feb 20 '07 #36
Well, I was talking more how they assign it.

variable = rand() % 10 + 1;

gives variable (I dont' remember what they used) a random value.

The mod (%) 10 is what you're going to be interested in next - this returns a number between 0 and 10. So you just have to change that to give you one between 1 and 100.
oooo ok....i see
Feb 20 '07 #37

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

Similar topics

0
by: Sofia | last post by:
My name is Sofia and I have for many years been running a personals site, together with my partner, on a non-profit basis. The site is currently not running due to us emigrating, but during its...
6
by: Robert Maas, see http://tinyurl.com/uh3t | last post by:
System login message says PHP is available, so I tried this: http://www.rawbw.com/~rem/HelloPlus/h.php It doesn't work at all. Browser just shows the source. What am I doing wrong?
0
by: Gregory Nans | last post by:
hello, i need some help to 'tree-ify' a string... for example i have strings such as : s = """A(here 's , B(A ) silly test) C(to show D(what kind) of stuff i need))""" and i need to...
7
by: Mike Kamermans | last post by:
I hope someone can help me, because what I'm going through at the moment trying to edit XML documents is enough to make me want to never edit XML again. I'm looking for an XML editor that has a...
8
by: JustSomeGuy | last post by:
I need to write an new class derived from the list class. This class stores data in the list to the disk if an object that is added to the list is over 1K in size. What methods of the std stl...
3
by: Bob.Henkel | last post by:
I write this to tell you why we won't use postgresql even though we wish we could at a large company. Don't get me wrong I love postgresql in many ways and for many reasons , but fact is fact. If...
2
by: Michael R. Pierotti | last post by:
Dim reg As New Regex("^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$") Dim m As Match = reg.Match(txtIPAddress.Text) If m.Success Then 'No need to do anything here Else MessageBox.Show("You need to enter a...
8
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only...
11
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any...
0
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
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:
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...

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.