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

Join 136,477 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,590 people online right now. 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
2 Jul, 2008 - 05: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
+Quote Post

lordms12
RE: 2D ARRAY GRAPH HELP URGENT PLS
2 Jul, 2008 - 05:50 AM
Post #2

D.I.C Regular
Group Icon

Joined: 16 Feb, 2008
Posts: 314



Thanked: 15 times
Dream Kudos: 225
My Contributions
It is right for this case only, so what is the problem?
User is offlineProfile CardPM
+Quote Post

liverpool0912
RE: 2D ARRAY GRAPH HELP URGENT PLS
2 Jul, 2008 - 05: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
+Quote Post

gabehabe
RE: 2D ARRAY GRAPH HELP URGENT PLS
2 Jul, 2008 - 05:59 AM
Post #4

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,539



Thanked: 98 times
Dream Kudos: 2650
Expert In: ruling the world.

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
+Quote Post

captainhampton
RE: 2D ARRAY GRAPH HELP URGENT PLS
2 Jul, 2008 - 06:08 AM
Post #5

Jawsome++;
Group Icon

Joined: 17 Oct, 2007
Posts: 518



Thanked: 2 times
Dream Kudos: 825
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
+Quote Post

lordms12
RE: 2D ARRAY GRAPH HELP URGENT PLS
2 Jul, 2008 - 06:13 AM
Post #6

D.I.C Regular
Group Icon

Joined: 16 Feb, 2008
Posts: 314



Thanked: 15 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 - 06:14 AM
User is offlineProfile CardPM
+Quote Post

liverpool0912
RE: 2D ARRAY GRAPH HELP URGENT PLS
2 Jul, 2008 - 06: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
+Quote Post

gabehabe
RE: 2D ARRAY GRAPH HELP URGENT PLS
2 Jul, 2008 - 06:21 AM
Post #8

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,539



Thanked: 98 times
Dream Kudos: 2650
Expert In: ruling the world.

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 - 06:22 AM
User is offlineProfile CardPM
+Quote Post

AmitTheInfinity
RE: 2D ARRAY GRAPH HELP URGENT PLS
2 Jul, 2008 - 06:40 AM
Post #9

C Surfing ∞
Group Icon

Joined: 25 Jan, 2007
Posts: 1,025



Thanked: 35 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
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 06:16PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month