Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need some C++ Help
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
jin




PostPosted: Thu Oct 07, 2010 11:48 pm   Post subject: Need some C++ Help

Hi Guys,

so its been a while since i have programmed anything in c++ so i just have a few performance questions about my assignment.

for the assignment i need to parse a file and store form every line an email, first name, middle name and last name and then do some comparisons. its been a while and i cant quite remember the pros and cons so

1. what would be better to use a struct with 4 string fields or just use a 2d string array?
2. i also need to sort based on a field (last name) so which would be the best algorithm to use? quick, merge, heap? in my testing ill prolly only have 20-50 lines but when being marked they may have 1000s.

thanks
Sponsor
Sponsor
Sponsor
sponsor
DtY




PostPosted: Fri Oct 08, 2010 6:30 am   Post subject: RE:Need some C++ Help

A struct would be better for this, that way you can do something like person->firstname, rather than person[2] which means nothing.

I can't say for the second which would be best.
OneOffDriveByPoster




PostPosted: Sun Oct 10, 2010 10:02 pm   Post subject: Re: Need some C++ Help

A class is a better idea because you won't have to move the other fields to match the one you are sorting on.
You should also be moving pointers to the class objects instead of the actual objects.
TheGuardian001




PostPosted: Sun Oct 10, 2010 10:10 pm   Post subject: Re: Need some C++ Help

OneOffDriveByPoster @ Sun Oct 10, 2010 10:02 pm wrote:
A class is a better idea because you won't have to move the other fields to match the one you are sorting on.

What do you mean by this?
IIRC, the only difference between a class and a struct in C++ is that Struct members are public by default, while Class members are private by default.
OneOffDriveByPoster




PostPosted: Sun Oct 10, 2010 10:27 pm   Post subject: Re: Need some C++ Help

TheGuardian001 @ Sun Oct 10, 2010 10:10 pm wrote:
OneOffDriveByPoster @ Sun Oct 10, 2010 10:02 pm wrote:
A class is a better idea because you won't have to move the other fields to match the one you are sorting on.

What do you mean by this?
IIRC, the only difference between a class and a struct in C++ is that Struct members are public by default, while Class members are private by default.
I was responding to the OP's question (I should have quoted from that I guess). I did not say that "class was better then struct". I chose to use "class" instead of "struct" to represent the same option. Sorry for the confusion.

The reason I gave for using the "struct" option was additional to the one given by DtY. As for using the "class" versus "struct" keywords, you are correct that they can both be used as a class-key for non-union class types in C++.

There are some additional differences between struct and class keywords (for example, "class" has a special meaning in a template parameter list).
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: