GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 14-Oct-2003, 17:43
mukcl mukcl is offline
New Member
 
Join Date: Oct 2003
Posts: 2
mukcl is an unknown quantity at this point

Create Vector To Hold Object?


Hi everyone!
I have some Lab exercises to do, and well, simply i am stuck.
Can i have some help getting me started, understanding all this? thanx!

I have a Transaction class;

-----------------------------------------------------------------
CPP / C++ / C Code:
class Transaction
{
private:
   int trackingId;
   string hub;
   string transDate;
   String transTime;
   int route;
   int driver;
   string status;
public:
   Transaction (const int tid, const string& h, const string &td, const &tt, const int r, const int d, const string &s)
   {
         // complete the constructor...
   }
};
-----------------------------------------------------------------

i have to complete the constructor, i am not sure how to approach this...

the other part to my exercise is to create 20 sample records (with code provided from this file "http://www.vtr.net/~mwb/c++/part21b.cpp" )and store them in a vector named trans (not necessary to read the data from a text file)

how do i start???? gracias amigos!
  #2  
Old 15-Oct-2003, 03:16
Garth Farley Garth Farley is offline
Invalid Email Address
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
To complete the constructor, you simply assign the arguments that are sent to the Transaction() function/constructor, to the private members of the class. I.e.

A constructor is run to set up the class - so that the other functions have something to work with. All the objects variables would be undefined, unless there's a constructor to set them up.

Here's one or 2 to get you started:
CPP / C++ / C Code:
Transaction (const int tid, const string& h, const string &td, const string &tt, const int r, const int d, const string &s)
 {
 // complete the constructor...
 trackingId = tid;   //simply fill in the variables - check them if necessary
 hub = h;   //see if this works!
 //etc...
 }

Question 2: A vector is a dynamic array. Normal arrays have a fixed size - vectors can expand as required. Vectors are part of the C++ STL (Standard Template Library) - and are easy to use.

You create a vector and add a Transaction as follows:
CPP / C++ / C Code:
vector<Transaction> trans();  //empty

trans.push_back(Transaction(1365,"Norwich","20030901","1200",12,005,"Nobody present")); //adds one Transaction.
and you can keep doing that.

GF
  #3  
Old 15-Oct-2003, 03:47
mukcl mukcl is offline
New Member
 
Join Date: Oct 2003
Posts: 2
mukcl is an unknown quantity at this point
thanks for the definitions, i had them kinda mixed up....its getting clearer!

is this ok then?

CPP / C++ / C Code:
public:
	Transaction (const int tid, const string& h, const string &td, const string &tt, const int r, constint d, const string &s)

	{
		//constructor

		trackingId = tid;
		hub = h;
		transDate = td
    transTime = tt
		route = r
		driver = d
		status = s


	}

the vector...do i create a new class? or do i enter in the same transaction class??

i am not sure how to test this either? to make sure i am doing ok..

thanks again GF.
  #4  
Old 15-Oct-2003, 09:03
Garth Farley Garth Farley is offline
Invalid Email Address
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
You're forgetting your semicolons - the compiler will tell you that anyway.

The vector class is made for you already. Just include <vector> and use away. You have the Transation class coded yourself, then you pass it to the vector as I've mentioned above.

I suggest you look up some books on C++ to get comfortable with the syntax.

GF
 
 

Recent GIDBlogLast Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
gxx linker accepts only 7 object files danielxs66 CPP / C++ Forum 1 12-Dec-2003 09:27
Can't seem to create db Tigress7 MySQL / PHP Forum 3 19-Aug-2003 09:19
How do I access an object from inside another object? JdS MySQL / PHP Forum 5 10-Jun-2003 08:51
How do I create JavaScript Links? JdS Web Design Forum 8 29-Jan-2003 15:02

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 03:16.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.