Hello!

I'm trying to make a simple array that will increase its column size dynamicly and it will have 3 rows.
On the 1st row i want the user to enter a name(aka char type)
and on the other two rows i want the user to enter some float values which refer to the name of the 1st row.

the result i want to be like this

Jack Tom Helen ..... Jenny
1.3 3 523.2 ..... 23.1
2.5 144.3 10000 ..... 12.1

any suggestions?

Thank you in advance.

Recommended Answers

All 3 Replies

Hello!

I'm trying to make a simple array that will increase its column size dynamicly and it will have 3 rows.
On the 1st row i want the user to enter a name(aka char type)
and on the other two rows i want the user to enter some float values which refer to the name of the 1st row.

the result i want to be like this

Jack Tom Helen ..... Jenny
1.33 4334. 4523.2 ..... 23.1
2.543 144.3 10000 ..... 12.1

any suggestions?

Thank you in advance.

Dynamic array== vector , http://cplusplus.com/reference/stl/vector/

There are at least two ways to do what you want, depending on the specifics of your problem.

One is to make three vectors, or make your own struct/class to hold all three in a single place.

The other is make a struct with name and those two floats and then make a vector of that struct.

i asssume that you are using visual c++ .

*** YourArrayStructure.h
-------------------------
 
public ref class YourArrayStructure {

public :
   String ^name;
   float dataMember2;
   float dataMember3;
   YourArrayStructure() : dataMember2(0.0) , dataMember3(0.0) {}
   ~YourArrayStructure() {}
};

*** main file :
---------------
# include "YourArrayStructure.h"


array<YourArrayStructure ^> ^arrayObject = gcnew array <YourArrayStructure>(4) ;
arrayObject[0] = gcnew YourArrayStructure ;
arrayObject[1] = gcnew YourArrayStructure ;
arrayObject[2] = gcnew YourArrayStructure ;
arrayObject[3] = gcnew YourArrayStructure ;

arrayObject[0]->name = "minnnnnas";
arrayObject[0]->dataMember2 = 1.254 ;
arrayObject[0]->dataMember3 = 3.419 ;

arrayObject[1]->name = "Thku";
arrayObject[1]->dataMember2 = 10.259 ;
arrayObject[1]->dataMember3 = 33.413 ;

arrayObject[2]->name = "sota";
arrayObject[2]->dataMember2 = 15.251 ;
arrayObject[2]->dataMember3 = 39.413 ;

arrayObject[3]->name = "Ok";
arrayObject[3]->dataMember2 = 11.266 ;
arrayObject[3]->dataMember3 = 3.443 ;
 
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.