943,845 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 6187
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Aug 4th, 2008
0

Re: C++ Extracting data from text files

Thanks for all that code but how would that be used in my program as I have two member types, a full member and a young member type. These member types have there own classes and a derived from a partent Member class.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
davidleeis14 is offline Offline
11 posts
since Aug 2008
Aug 4th, 2008
0

Re: C++ Extracting data from text files

It's exactly C++ battlefield!

Declare class Member as an abstract class (with pure virtual functions), define these virtual functions in FullMember and YoungMember classes, use vector<Member*> in your variant of my PlainDb - that's all. Polymorphism works!..

I suspect that it's a true aim of your (homework?) task.
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Aug 4th, 2008
0

Re: C++ Extracting data from text files

I wonder how you guessed that! Thanks for the help guys.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
davidleeis14 is offline Offline
11 posts
since Aug 2008
Aug 4th, 2008
0

Re: C++ Extracting data from text files

It might not be that simple if you also need to keep track of whether a member is full or young. You would need to output that in some form to your text file, and then as you read the data, create an appropriate object based on whether its a full or young member.
Reputation Points: 77
Solved Threads: 40
Posting Pro in Training
CoolGamer48 is offline Offline
401 posts
since Jan 2008
Aug 4th, 2008
0

Re: C++ Extracting data from text files

Yes, it's (one of) a technical problem with deserializing. Fortunately, there are many ways to simplify its solution. We need an arbiter who make a decision (in the PlainDb::load() from my snippet equivalent): new FullMember() or new YoungMember ...
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Aug 5th, 2008
0

Re: C++ Extracting data from text files

Are you saying that it would be better to output both member types in one text file?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
davidleeis14 is offline Offline
11 posts
since Aug 2008
Aug 5th, 2008
0

Re: C++ Extracting data from text files

you could add one more field to the structure which specifies the 'member_type' and write that to your file then when you load the file based on the 'member_type' you can create the correct object type.
Featured Poster
Reputation Points: 431
Solved Threads: 116
Practically a Master Poster
Agni is offline Offline
654 posts
since Dec 2007
Aug 5th, 2008
0

Re: C++ Extracting data from text files

Don't shoot me for this, but where do I write the structure for member type (I have two child classes and one parent class that defines the objects) and where do I put "vector<Member*>" and what do I do with it?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
davidleeis14 is offline Offline
11 posts
since Aug 2008
Aug 5th, 2008
0

Re: C++ Extracting data from text files

you dont need a separate structure for a member_type, use the exisiting structure which coolgamer had suggested and add another field to it.

i think best would be that you try to write some code from whatever you have understood till now and post it, then we can take it from there.
Featured Poster
Reputation Points: 431
Solved Threads: 116
Practically a Master Poster
Agni is offline Offline
654 posts
since Dec 2007
Aug 5th, 2008
0

Re: C++ Extracting data from text files

How do you load the data from the txt files into a vector, thats what I can't understand. I have changed my program so that it only uses on text file, but each line of that files starts with either Full Mem or Young Mem depending on the account stored. Also the Young member has 4 pieces of data stored with it wheras the full mem only has three.

I want the program to call up this data so that it can be used in the accounts assciated functions i.e. deposit money, withdraw or calculate the interest etc.
Last edited by davidleeis14; Aug 5th, 2008 at 8:24 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
davidleeis14 is offline Offline
11 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: plotting cpu and mem consumption
Next Thread in C++ Forum Timeline: HELP ME MY MISTAKE and HELP THE CORRECT The my homework





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC