-
Best way of organizing.
hello.
I am attempting to write a program that allows the user to enter and element from the periodic table and then displays some information on that element. I was wondering how you would go about organizing a program liek this since theirs TOO MANY ELEMENTS! :eek: any suggestions and oppinions are welcome
-
You could write a class for the elements that contains their atomic weights, numbers, etc. Stick all of them in a container like an array or a vector and then access them as necessary.
You could stick all of the info into a file. Read in the file until you reach the entry you want. Then, output the info that the file contains on that element.
As for what's best, that's rather subjective. Writing a class for elements is perhaps more time consuming than you want. Oh, and there are only around 116 elements. That's diddly in the scope of computer science. Databases contain terabytes of information.
Ooh, that just gave me an idea. You could just whip up a database in Access and query it as needed, but I'm assuming you need to write this program for a C++ class, so I guess that idea's out the window.
-
I personally would say go with a file... that way you can write a quick patch if something changes without breaking into the source... but then you'll get a stupid user who likes to delete or mess with the data file... I think it's alot slower too...
on the other hand, the elements most people need don't change often at all, so your pretty safe writing them into the program...
edit: I just thought of a way to do it with the text file that would give you some good practice... create a data file like i said, then when the program initializes, have it read each element onto it's own node in a linked list...