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

Join 118,658 C++ Programmers for FREE! Ask your question and get quick answers from experts. There are 885 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 HELP URGENT PLS

 
Reply to this topicStart new topic

2D ARRAY GRAPH HELP URGENT PLS

liverpool0912
post 2 Jul, 2008 - 06:44 AM
Post #1


New D.I.C Head

*
Joined: 4 Jun, 2008
Posts: 36


My Contributions


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).

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


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 dun tink my code is rite help
User is offlineProfile CardPM

Go to the top of the page


lordms12
post 2 Jul, 2008 - 06:50 AM
Post #2


D.I.C Regular

Group Icon
Joined: 16 Feb, 2008
Posts: 300



Thanked 12 times

Dream Kudos: 225
My Contributions


It is right for this case only, so what is the problem?
User is offlineProfile CardPM

Go to the top of the page

liverpool0912
post 2 Jul, 2008 - 06:54 AM
Post #3


New D.I.C Head

*
Joined: 4 Jun, 2008
Posts: 36


My Contributions


SO its correct? thx im juz not sure if its rite
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 2 Jul, 2008 - 06:59 AM
Post #4


T3H R0XX0R!

Group Icon
Joined: 6 Feb, 2008
Posts: 3,553



Thanked 73 times

Dream Kudos: 2400

Expert In: (X)HTML, CSS, Batch Scripting, C, C++

My Contributions


Please don't double post.

And, you could do it another way without a formula:
cpp
for (int i = 0; i < 10; i++)
for (int j = 0; j < 10; j++)
graph[i][j] = '-';

// now the array is filled with ----

graph[0][2] = 'X';
graph[1][4] = 'X';
// etc
Hope this helps smile.gif
User is offlineProfile CardPM

Go to the top of the page

captainhampton
post 2 Jul, 2008 - 07:08 AM
Post #5


D.I.C Addict

Group Icon
Joined: 17 Oct, 2007
Posts: 501



Thanked 2 times

Dream Kudos: 775
My Contributions


As stated above, please do not double post a topic, and as before please elaborate on the use of time and strength.
User is offlineProfile CardPM

Go to the top of the page

lordms12
post 2 Jul, 2008 - 07:13 AM
Post #6


D.I.C Regular

Group Icon
Joined: 16 Feb, 2008
Posts: 300



Thanked 12 times

Dream Kudos: 225
My Contributions


Another abstract solution would be
cpp
for (int i = 0; i < 10; i++)
for (int j = 0; j < 10; j++)
graph[i][j] = '-';

for (int j = 0; j < 10; j++)
graph[time[j]][Strength[j]] = 'X';


This post has been edited by lordms12: 2 Jul, 2008 - 07:14 AM
User is offlineProfile CardPM

Go to the top of the page

liverpool0912
post 2 Jul, 2008 - 07:16 AM
Post #7


New D.I.C Head

*
Joined: 4 Jun, 2008
Posts: 36


My Contributions


ok they are just variables no real values

the values of strength and time are on the post
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 2 Jul, 2008 - 07:21 AM
Post #8


T3H R0XX0R!

Group Icon
Joined: 6 Feb, 2008
Posts: 3,553



Thanked 73 times

Dream Kudos: 2400

Expert In: (X)HTML, CSS, Batch Scripting, C, C++

My Contributions


My solution covers for the variables, and so does lordms12's if you create arrays of time and strength.

We will help you to get a solution, but we won't do it for you.

This post has been edited by gabehabe: 2 Jul, 2008 - 07:22 AM
User is offlineProfile CardPM

Go to the top of the page

AmitTheInfinity
post 2 Jul, 2008 - 07:40 AM
Post #9


D.I.C Addict

Group Icon
Joined: 25 Jan, 2007
Posts: 818



Thanked 20 times

Dream Kudos: 125
My Contributions


Your Solution will work only for the problem given. It will not plot graphs for any other strengths.

Try this.

cpp


for (int i = 0; i < 10; i++)
for (int j = 0; j < 10; j++)
graph[i][j] = '-';

for(int i=0;i<10;i++)
{
cout<<"\nEnter Strength for Time "<<i+1<<" : ";
cin >> j;
graph[(10-(j+1))][i] = 'X';
}

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



I hope this will help you. smile.gif
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 10/12/08 03:39AM

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