answersLogoWhite

0


Best Answer

The Periodic Table Of Elements has a well defined order. The layout can be emulated easily since the arrangement is quite logical.

The first step would be to define a struct containing the following members as a minimum:

- atomic number (int - number of protons in its nucleus)

- symbol (char* - short form of the element name)

- name (char* - long form of the element name)

i.e.:

struct elementinfo {

int atomicnumber;

char *symbol, *name;

};

Other members can be added as your program develops.

The next step is to arrange the table itself. If you're using Win32 or another graphical system, it's a matter of drawing a box (Win32 would require a MoveToEx() call and four LineTo() calls) and TextOut() (or a related function) for the atomic number and element symbol (centered horizontally and aligned top and bottom respectively).

Including conio.h or curses.h would give you the ability to position the cursor and even change the text color, allowing for an alternate "graphical" method.

To keep things simple, storing the elements in an array would require something akin to the following:

struct elementinfo elementlist[]={

{1, "H", "Helium"}, {0, NULL, NULL}, {0, NULL, NULL},

{0, NULL, NULL}, {0, NULL, NULL}, {0, NULL, NULL},

{0, NULL, NULL}, {0, NULL, NULL}, {0, NULL, NULL},

{0, NULL, NULL}, {0, NULL, NULL}, {0, NULL, NULL},

{0, NULL, NULL}, {0, NULL, NULL}, {0, NULL, NULL},

{0, NULL, NULL}, {0, NULL, NULL}, {2, "He", "Helium"},

{-1, NULL, NULL},

{3, "Li", "Lithium"}, {4, "Be", "Beryllium"}, {0, NULL, NULL},

{0, NULL, NULL}, {0, NULL, NULL}, {0, NULL, NULL},

{0, NULL, NULL}, {0, NULL, NULL}, {0, NULL, NULL},

{0, NULL, NULL}, {0, NULL, NULL}, {0, NULL, NULL},

{5, "B", "Boron"}, {6, "C", "Carbon"}, {7, "N", "Nitrogen"},

{8, "O", "Oxygen"}, {9, "F", "Fluorine"}, {10, "Ne", "Neon"},

{-1, NULL, NULL},

...

{-2, NULL, NULL}

};

In the above array, {0, NULL, NULL} represents a blank displayed for that particular cell, and {-1, NULL, NULL} represents a newline. The {-2, NULL, NULL} signifies the end of the table. The following for() loop would wrap around your display code like so:

for (count=0; elementlist[count].atomicnumber!=-2; count++) {

if elementlist[count].atomicnumber==-1) {

// jump to next line of elements

}

else {

// display current element

}

}

Drawing this graphically, you'd have to keep track of the current cursor (X, Y) position.

If you are sending this to stdout or another text stream (i.e. text file), you could draw each line, referencing the array of elements as you go. The list of elements would have to be stored in a nested array: the outermost array contains each line of elements in an array. This would do away with the {-1, NULL, NULL} terminating each line of elements.

Extending this code to use classes would be relatively simple, but might only make sense if you were drawing this graphically storing each element as an object.

The Lanthanides and Actinides, since they're displayed separately from the main table, would probably have to be stored separately for sake of convenience.

Also, as laboratories continue to synthesize (or, on the rare chance, discover) new elements, the layout of the table may change (even drastically) to suit. Thus, the code would have to be altered accordingly.

See the related links below for more ideas on how to design a program that displays the Periodic Table of Elements.

(Note: Code originally posted was copyrighted. Added to related links.)

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C plus plus program of periodic table?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering
Related questions

Can ti-84 plus c have periodic table?

You can download it from TI's website.


What does C means on the periodic table?

C means 'carbon' in periodic table.


What is C in the periodic table?

C is Carbon.


What is area C of the periodic table?

Carbon.


What is c called in the periodic table?

Carbon


What element is c on the periodic table?

Carbon


What does c stand for the periodic table?

Carbon


What is the element carbon's name on periodic table?

Carbon's name is C on periodic table. It belongs to group no. 14.


Can you program games with c plus plus?

Yes, you can program games with C++.


Number 6 in the periodic table of the elements?

Atomic Number 6 on the periodic table is Carbon (C). It has a mass of 12.011g/mol.


What is the symbol for carbon in the periodic table?

The symbol for Carbon is C.


Is C or F in the periodic table more reactive?

F