Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 105,764 C++ Programmers for FREE! Ask your question and get quick answers from experts. There are 1,631 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



2d array graph?

 
Reply to this topicStart new topic

2d array graph?

liverpool0912
post 2 Jul, 2008 - 05:02 AM
Post #1


New D.I.C Head

*
Joined: 4 Jun, 2008
Posts: 23

heres the question

Write a function that takes in a 2D array and display a graphical plot of the data. The graph should be Strength (Y-axis) vs Time (X-axis).

CODE

#include <iostream>
using namespace std;

void main (void)
{ char graph [10][10]= {
    {'-' , '-' , '-' , '-' ,'-' , '-' ,  '-' , '-' , '-' , 'x' } ,
    {'-' , '-' , 'x' , '-' ,'-' , '-' ,  '-' , '-' , '-' , '-' } ,
    {'-' , '-' , '-' , '-' ,'-' , '-' ,  '-' , '-' , 'x' , '-' } ,
    {'-' , '-' , '-' , 'x' ,'-' , '-' ,  '-' , '-' , '-' , '-' } ,
    {'-' , 'x' , '-' , '-' ,'-' , '-' ,  '-' , '-' , '-' , '-' } ,
    {'-' , '-' , '-' , '-' ,'x' , '-' ,  '-' , '-' , '-' , '-' } ,
    {'x' , '-' , '-' , '-' ,'-' , '-' ,  '-' , '-' , '-' , '-' } ,
    {'-' , '-' , '-' , '-' ,'-' , '-' ,  '-' , 'x' , '-' , '-' } ,
    {'-' , '-' , '-' , '-' ,'-' , 'x' ,  '-' , '-' , '-' , '-' } ,
    {'-' , '-' , '-' , '-' ,'-' , '-' ,  'x' , '-' , '-' , '-' } ,
};

    for(int b=0; b<10; b++)
    {
        for(int c=0; c<10; c++)
        {
            cout << graph [b][c];
        }
        cout << endl;
    }





system("Pause");

}




i dont even think its right need help asap
User is offlineProfile CardPM

Go to the top of the page


gabehabe
post 2 Jul, 2008 - 05:08 AM
Post #2


T3H R0XX0R!

Group Icon
Joined: 6 Feb, 2008
Posts: 2,048



Thanked 40 times

Dream Kudos: 1425

Expert In: C, C++

My Contributions


Shouldn't you be making a formula to fill the array?

If so, was you given one?

QUOTE
Write a function that takes in a 2D array and display a graphical plot of the data.
You need to make a function, not just throw some stuff in your main smile.gif

This post has been edited by gabehabe: 2 Jul, 2008 - 05:10 AM
User is online!Profile CardPM

Go to the top of the page

liverpool0912
post 2 Jul, 2008 - 05:11 AM
Post #3


New D.I.C Head

*
Joined: 4 Jun, 2008
Posts: 23

no1 gave me anything onli this qn sadly and im confused
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 2 Jul, 2008 - 05:16 AM
Post #4


T3H R0XX0R!

Group Icon
Joined: 6 Feb, 2008
Posts: 2,048



Thanked 40 times

Dream Kudos: 1425

Expert In: C, C++

My Contributions


OK, well I'm crap with formulas, so I'm gonna need this explaining... strength of what against time?
User is online!Profile CardPM

Go to the top of the page

captainhampton
post 2 Jul, 2008 - 05:43 AM
Post #5


D.I.C Addict

Group Icon
Joined: 17 Oct, 2007
Posts: 501



Thanked 2 times

Dream Kudos: 775
My Contributions


How are you taking into account the strength and time in this code? How does it affect the general behavior of the 2d array?
User is offlineProfile CardPM

Go to the top of the page

liverpool0912
post 2 Jul, 2008 - 05:56 AM
Post #6


New D.I.C Head

*
Joined: 4 Jun, 2008
Posts: 23

oh w8 hold on my bad


Time 1 2 3 4 5 6 7 8 9 10
Strength 3 5 8 6 4 1 0 2 7 9

heres the value

User is offlineProfile CardPM

Go to the top of the page

Mallstrop
post 4 Jul, 2008 - 03:42 AM
Post #7


New D.I.C Head

*
Joined: 19 Jun, 2008
Posts: 30



Thanked 1 times
My Contributions


That's just a simple for loop to set the cells of the array to X at the position given.


CODE

for (int i=0;i<10;i++){
array[time[i]][strength[i]] = 'X';


That's assuming that strength never goes out of the bounds of the array. you could add checks that if strength goes over 9 then it's ignored or drawn as 9 or something.

Maybe include a nested loop to set all the cells to '-' first?

This post has been edited by Mallstrop: 4 Jul, 2008 - 03:44 AM
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 8/21/08 02:16PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month