Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with setting up array!

Status
Not open for further replies.

davemib

Programmer
Dec 31, 2002
30
GB
how can i set this up???????????????????????????

the array is 16 rows (a-p) each row containing three blocks.

123 4567 890
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p

this is the current code.

Code:
#include <stdio.h>
void displayMenu(char *a){
printf(&quot;\nPlease choose an option\n&quot;);
printf(&quot;\n1add a passenger into a plane\n&quot;);
printf(&quot;\n2display a list of all passengers\n&quot;);
printf(&quot;\n3display a plan of the plane\n&quot;);
printf(&quot;\n4clear the plan\n&quot;);
printf(&quot;\n5save list list of all passengers\n&quot;);
printf(&quot;\n6load all of the passengers\n&quot;);
printf(&quot;\n7exit\n&quot;);
scanf(&quot;%c&quot; , a);
[\code]

the array will store the name, age, seat.
 
I'm not EXACTLY sure what you're looking for. Are you using C++? Why not use a vector?

Look up the std::vector class and you can get all the class members. It's fairly easy to work with and its much less cumbersome than an array:

in your .h file:

#include <string>
#include <vector>

typedef struct tagSTRUCT{
std::string strRow; //Can also use char buffer
std::string strName; //Can also use char buffer
unsigned int nAge
unsigned int nSeat;
} STRUCT;

STRUCT m_Struct;

std::vector<STRUCT> m_vector;

Then in your .cpp file in your initialization routine:

This is one way to do it, use an index so it's almost like accessing an array...there are also other ways:

for(int i = 0; i < 17; i++)
{
m_vector.push_back(m_vector);
m_vector.strRow = &quot;put your row letter here&quot;; //need help with this? use ASCII...you can also add the row numbers manually outside of a loop.
}

Now, when the user enters their information, you can calculate your index (I'm not exactly sure of your requirements) and access the vector members:

m_vector[nIndex].strName = &quot;Their Name&quot;;
m_vector[nIndex].nAge = x;
m_vector[nIndex].nSeat = y;

I tend to shy away from arrays since I've discovered vectors. I'm not sure your requirements so it may not be what you're looking for. If you really want to use an array, then could you please clarify your requirements?
 
oops...let me repost with a cleaner version...

I'm not EXACTLY sure what you're looking for. Are you using C++? Why not use a vector?

Look up the std::vector class and you can get all the class members. It's fairly easy to work with and its much less cumbersome than an array:

in your .h file:

Code:
#include <string>
#include <vector>

typedef	struct tagSTRUCT{
    std::string    strRow;   //Can also use char buffer
    std::string    strName;  //Can also use char buffer
    unsigned int   nAge
    unsigned int   nSeat;
} STRUCT;

STRUCT     m_Struct;

std::vector<STRUCT> m_vector;

Then in your .cpp file in your initialization routine:

This is one way to do it, use an index so it's almost like accessing an array...there are also other ways:

Code:
for(int i = 0; i < 17; i++)
{
    m_vector.push_back(m_vector);
    m_vector[i].strRow = &quot;put your row letter here&quot;;  //need help with this? use ASCII...you can also add the row numbers manually outside of a loop.
}

Now, when the user enters their information, you can calculate your index (I'm not exactly sure of your requirements) and access the vector members:

Code:
m_vector[nIndex].strName = &quot;Their Name&quot;;
m_vector[nIndex].nAge = x;
m_vector[nIndex].nSeat = y;

I tend to shy away from arrays since I've discovered vectors. I'm not sure your requirements so it may not be what you're looking for. If you really want to use an array, then could you please clarify your requirements?
 
well im programming in csharp. i need an array to store the results of passengers.


the array has 16 rows (a-p) each row containing three blocks (123 4567 890).

123 4567 890
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p

the array will store the name, age, seat ((i.e. a 1) cuz that is from the array).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top