C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 11th, 2004, 01:08 PM
bobert bobert is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Colorado, USA
Posts: 15 bobert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 sec
Reputation Power: 0
C/C++: Multi-dimensional array or struct?

Hi all,

I am using Microsoft VC++ 6.0 and not using MFC. I need to create some way of counting the number of animals that a person has, and also keep track of the state where the person lives. The fields/variables are:

1. char State[256] (there will be up to 50 states and each will be a maximum of 256 characters)

2. char PetOwner[256] (in this example, there will be up to 30 pet owners' names and each will be a maximum of 256 characters)

3. int Dogs (this is a counter for the number of dogs that a pet owner has)

4. int Cats (this is a counter for the number of cats that a pet owner has)

5. int Birds (this is a counter for the number of birds that a pet owner has)

6. int Weight (this is the weight of each pet)

To get the above info, I am parsing a text file and it is working just fine. Now I need to put each piece of data into its respective variable so that I can create a pie chart later. That will be another topic. :-)

Here's an example of what the text file looks like:

Code:
Colorado, Bob Johnson, Dog, 30 lbs
Colorado, Bob Johnson, Cat, 12 lbs
Colorado, Debbie Smith, Dog, 15 lbs
Colorado, Debbie Smith, Dog, 25 lbs
Washington, George Jones, Cat, 10 lbs
Washington, George Jones, Cat, 15 lbs
Washington, George Jones, Bird, 3 lbs


Any ideas of how I should go about creating a multi-dimensional array or struct?

Thanks,

bobert

Reply With Quote
  #2  
Old February 12th, 2004, 04:20 AM
Buster77 Buster77 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 28 Buster77 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I would use a class, then you can use an array to store objects of the class, I find that more intuitive than a multi array. For example:

#include <string>

using std::string;

class PetOwnerInfo
{
public:
string State;
string PetOwner;
int Dogs;
int Cats;
int Birds;
int Weight;
};

Hope that helps...

Reply With Quote
  #3  
Old February 20th, 2004, 02:05 PM
bobert bobert is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Colorado, USA
Posts: 15 bobert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 sec
Reputation Power: 0
Quote:
Originally Posted by Buster77
I would use a class, then you can use an array to store objects of the class, I find that more intuitive than a multi array.


Hi,

Yes, that did work. Thanks!

bobert

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > C/C++: Multi-dimensional array or struct?


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap