Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Last C++ help thread - Reading txt into arrays and plotting.
New Posts  All Forums:Forum Nav:

Last C++ help thread - Reading txt into arrays and plotting. - Page 2

post #11 of 13
Thread Starter 
Quote:
Originally Posted by The Bartender Paradox View Post
As you haven't posted the function body no one can say if it uses the three parameters, but that function declaration does accept 3 parameters that could be used in the fashion you listed.

Actually it looks a little different, it looks like you want to try and do it with a 1D array whereas those requirements look more like it wants a 2D array. For yours it looks like you iterate a single time over the whole 1D array, inserting a newline every time you get to a multiple of nPoints/nRows. The requirements look like they want something like this:
Code:
void plot( double data[][], int nColumns, int nRows );
Where nColums is the x axis and nRows is the y axis, and you print the array like I've listed in a previous post.

I basically got that from the requirements of the assignment. Lemme quote it for a sec, that'll prolly resolve some issues.

Quote:
Overall Assignment
For this assignment, you are to write a program that reads in the table of data generated in the previous assignment, and produces some simple plots using one- and two-dimensional arrays.
Three functions will be required - One each to determine the maximum and minimum values of the arrays, and one to produce the actual plots. A sample data file is provided in case you did not get assignment 4 working.

Necessary Functions:
The following functions will need to be written for this assignment:

* double maxArray( double data[ ], int nPoints );
This function returns the maximum value of the array "data". nPoints indicates how many data points are in the array. The function should return 0.0 if nPoints is less than 1.

* double minArray( double data[ ], int nPoints );
This function returns the minimum value of the array "data". nPoints indicates how many data points are in the array. The function should return 0.0 if nPoints is less than 1.

* void plot( double data[ ], int nPoints, int nRows );
This is the function that generates the actual plot,
Do u understand how they want 1D and 2D arrays implemented? I can't figure it out. I keep going back to the txt file I had linked earlier as that is HW4 output. I'll link it again.
post #12 of 13
Quote:
Originally Posted by MeeMoo220 View Post
I basically got that from the requirements of the assignment. Lemme quote it for a sec, that'll prolly resolve some issues.



Do u understand how they want 1D and 2D arrays implemented? I can't figure it out. I keep going back to the txt file I had linked earlier as that is HW4 output. I'll link it again.
This might not help but Here is my try.

maxArray uses nPoint as a guide to go through some loop maybe something like

if nPoint < 1
return 0.0
else
for(i = 0; i<nPoint; i++)
then compare the values to see which is the largest
return the largest

minArray is the opposite.(only in the for, you just check for smallest instead of largest)

for plot, I believe that you will be returning a 2d array.
example

data[] holds all the data you read from the text file.
nPoint is how many entries there are
nRow tell you how to break down the 2d array.

example, if data[] had 10 entries example

data[0] = 1.1
data[1] = 1.2
data[2] = 1.3
data[3] = 1.4
data[4] = 1.5
data[5] = 1.6
data[6] = 1.7
data[7] = 1.8
data[8] = 1.9
data[9] = 2.0

and nPoint = 10
and nRows =2
and then when you use plot you enter
plot(dataArr, nPoints, nRows)
// here you have to divide 10 /2
code
// now you need to take the result and make a 2d array
// you should do
double dblArray[nPoints/nRows][nRows];
// this will give you your 2d array

// now you just need to make a loop that will populate the array
// there are many ways, a for loop would be best
// something like
for(i = 0; i <nPoints; i++)
// now you need to figure out how to populate it with the data going where it needs to go.
i suggest you start at column = 0 and row = 0
then after each insertion you could do
row++
if(row == nRows)
column++;
row = 0;

that should get you populated.

at the end of the run you should have
data[0][0] = 1.1, data[0][1] = 1.2
data[1][0] = 1.3, data[1][1] = 1.4
data[2][0] = 1.5, data[2][1] = 1.6
data[3][0] = 1.7, data[3][1] = 1.8
data[4][0] = 1.9, data[4][1] = 2.0

Good luck. I hope that makes some sense.
Edited by donkru - 3/30/11 at 12:27am
Valery
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k GA-P67A-UD4-B3 Radeon 7970 Reference G. Skill Sniper 
Hard DriveOptical DriveOSMonitor
Corsair NOVA SSD 64gb + 500gb Storage + 1TB Storag HP DVD burner Windows 7 64bit 37" 1080p60hz 
KeyboardPowerCaseMouse
Razer Blackwidow Ultimate Rosewill Lightning 1000W Single Rail LianLi PC-K58 Razer Spectre 
Mouse Pad
Razer Goliathus Speed 
  hide details  
Reply
Valery
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k GA-P67A-UD4-B3 Radeon 7970 Reference G. Skill Sniper 
Hard DriveOptical DriveOSMonitor
Corsair NOVA SSD 64gb + 500gb Storage + 1TB Storag HP DVD burner Windows 7 64bit 37" 1080p60hz 
KeyboardPowerCaseMouse
Razer Blackwidow Ultimate Rosewill Lightning 1000W Single Rail LianLi PC-K58 Razer Spectre 
Mouse Pad
Razer Goliathus Speed 
  hide details  
Reply
post #13 of 13
Thread Starter 
Quote:
Originally Posted by donkru View Post
This might not help but Here is my try.

Code:
maxArray uses nPoint as a guide to go through some loop maybe something like

if nPoint < 1
return 0.0
else
for(i = 0; i<nPoint; i++)
then compare the values to see which is the largest
return the largest

minArray is the opposite.(only in the for, you just check for smallest instead of largest)

for plot, I believe that you will be returning a 2d array.
example

data[] holds all the data you read from the text file.
nPoint is how many entries there are
nRow tell you how to break down the 2d array.

example, if data[] had 10 entries example

data[0] = 1.1
data[1] = 1.2
data[2] = 1.3
data[3] = 1.4
data[4] = 1.5
data[5] = 1.6
data[6] = 1.7
data[7] = 1.8
data[8] = 1.9
data[9] = 2.0

and nPoint = 10
and nRows =2
and then when you use plot you enter
plot(dataArr, nPoints, nRows)
// here you have to divide 10 /2
code
// now you need to take the result and make a 2d array
// you should do 
double dblArray[nPoints/nRows][nRows];
// this will give you your 2d array

// now you just need to make a loop that will populate the array
// there are many ways, a for loop would be best
// something like
for(i = 0; i <nPoints; i++)
// now you need to figure out how to populate it with the data going where it needs to go.
i suggest you start at column = 0 and row = 0
then after each insertion you could do
row++
if(row == nRows)
column++;
row = 0;

that should get you populated.

at the end of the run you should have
data[0][0] = 1.1, data[0][1] = 1.2
data[1][0] = 1.3, data[1][1] = 1.4
data[2][0] = 1.5, data[2][1] = 1.6
data[3][0] = 1.7, data[3][1] = 1.8
data[4][0] = 1.9, data[4][1] = 2.0

Good luck. I hope that makes some sense.
Dude! thank you so much for breaking it down like that. I understand it now. I'm gonna go try to get this working. Thanks again!
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Last C++ help thread - Reading txt into arrays and plotting.