473,718 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Design of C++ Periodic table project

Hi there,
I am looking to design a project using C++

The main objective of the project is to display details of periodic
table elements such as periodic element name, properties(such as atomic
number and atomic mass) for each periodic number entered by user. I am
thinking to input all the data regarding each periodic element number
in form of class.

Please give your opinion on the correct design method for the same.

Thanks

Nishant

Mar 16 '06 #1
5 8907
Hi,

I thiink you already made your design yourself:

You need a map from periodic number to element class so a stl map from
unsigned long to a class 'Element'

CElement
{
private:
// Your element data
public
// Bunch of get and set functions
Get();
};
std::map<unsign ed long, CElement> periodiclist;

Or

CPeriodicNumber
{
...
operator <( const CPeriodicNumber & PeriodicNumber )const;
{
//...
}
};

std::map<CPerio dicNumber, CElement> PeriodicList;

Fill in the details,et voila.
Regards, Ron AF Greve

http://moonlit.xs4all.nl

<ni*******@redi ffmail.com> wrote in message
news:11******** *************@e 56g2000cwe.goog legroups.com...
Hi there,
I am looking to design a project using C++

The main objective of the project is to display details of periodic
table elements such as periodic element name, properties(such as atomic
number and atomic mass) for each periodic number entered by user. I am
thinking to input all the data regarding each periodic element number
in form of class.

Please give your opinion on the correct design method for the same.

Thanks

Nishant

Mar 17 '06 #2

<ni*******@redi ffmail.com> wrote in message
news:11******** *************@e 56g2000cwe.goog legroups.com...
| Hi there,
| I am looking to design a project using C++
|
| The main objective of the project is to display details of periodic
| table elements such as periodic element name, properties(such as atomic
| number and atomic mass) for each periodic number entered by user. I am
| thinking to input all the data regarding each periodic element number
| in form of class.
|
| Please give your opinion on the correct design method for the same.
|
| Thanks
|
| Nishant
|

That should be fairly simple. Start by creating a class that stores one
element with the appropriate components required.

i) class might be simply called Element with the following components:
a) name could be a std::string
b) atomic number could be an unsigned integer
c) atomic mass could be a double

Then determine what constructors and operators as well as member functions
you'll need. Then test it. If you cannot store a single Element, how the
hell are you going to store an entire periodic table?

#include <iostream>
#include <ostream>
#include <deque> // an STL container - double ended queue
#include <iterator> // for std::ostream_it erator
#include <algorithm> // for std::copy

class Element
{
std::string name; // why not symbol too
unsigned number;
double mass;
public:
// parametized ctor
Element(std::st ring s, unsigned n, double m)
: name(s), number(n), mass (m) { }
// copy ctor
Element(const Element& copy)
{
name = copy.name;
number = copy.number;
mass = copy.mass;
}
// d~tor
~Element() { }
// assignment operator
Element& operator=(const Element& rhv)
{
if(&rhv == this) return *this; // paranoia check
name = rhv.name;
number = rhv.number;
mass = rhv.mass;
return *this;
}
// friend operator<<
friend
std::ostream&
operator<<(std: :ostream& os, const Element& e)
{
os << e.number << "\t";
os << e.name.c_str() << ", mass = ";
os << e.mass << std::endl;
return os;
}
}; // class Element

int main()
{
std::deque< Element > de;
de.push_back(El ement("Hydrogen ", 1, 1.00794)); // copies
de.push_back(El ement("Helium", 2, 4.00260));
de.push_back(El ement("Lithium" , 3, 6.941));

std::copy( de.begin(),
de.end(),
std::ostream_it erator< Element >(std::cout) );

return 0;
}

/*
1 Hydrogen, mass = 1.00794
2 Helium, mass = 4.0026
3 Lithium, mass = 6.941
*/

Once that is achieved, what container would you want the periodic table to
be composed of? A std::map? How will you provide the dataset? a file stream?
etc... The possibilities are endless.

The step-by-step approach at developing this specific project (the periodic
table) is simple enough to help you gain the knowledge you seek and then
some.
If your knowledge of C++ is not quite at par: Consider researching a few
topics.

Topics:
a) encapsulation
b) constructors and initialisation lists
c) references
d) the rule of three
e) templates
f) streams (like std::ostream)
g) iterators
h) algorithms
i) sequential STL containers (vector, list, deque, etc)
j) associative STL containers (map, set, multimap, etc)

There is no need to delve into inheritance yet. At least not until some
smart-a** starts arguing that some elements are non-metallic, some noble
gasses, then metals and yet others radio-active. hmmm.

Mar 17 '06 #3

"Peter_Juli an" <pj@antispam.co digo.ca> wrote in message
news:Rb******** ***********@new s20.bellglobal. com...
|
| <ni*******@redi ffmail.com> wrote in message
| news:11******** *************@e 56g2000cwe.goog legroups.com...
| | Hi there,
| | I am looking to design a project using C++
| |
| | The main objective of the project is to display details of periodic
| | table elements such as periodic element name, properties(such as atomic
| | number and atomic mass) for each periodic number entered by user. I am
| | thinking to input all the data regarding each periodic element number
| | in form of class.
| |
| | Please give your opinion on the correct design method for the same.
| |
| | Thanks
| |
| | Nishant
| |
|
| That should be fairly simple. Start by creating a class that stores one
| element with the appropriate components required.
|
| i) class might be simply called Element with the following components:
| a) name could be a std::string
| b) atomic number could be an unsigned integer
| c) atomic mass could be a double
|
| Then determine what constructors and operators as well as member functions
| you'll need. Then test it. If you cannot store a single Element, how the
| hell are you going to store an entire periodic table?
|
| #include <iostream>
| #include <ostream>

#include <string> // duh !!

| #include <deque> // an STL container - double ended queue
| #include <iterator> // for std::ostream_it erator
| #include <algorithm> // for std::copy
|
<snip>

Mar 17 '06 #4
posted:
Hi there,
I am looking to design a project using C++

The main objective of the project is to display details of periodic
table elements such as periodic element name, properties(such as atomic
number and atomic mass) for each periodic number entered by user. I am
thinking to input all the data regarding each periodic element number
in form of class.

Please give your opinion on the correct design method for the same.

Thanks

Nishant

Here's how I'd go about it:

First of all, the Periodic Table is composed of Elements, so it'd be handy
if we had an object type called "Element". What info do we need about an
element? Just the amount of protons in the nucleus of an atom of the
element, therefore:

class Element
{
private:

unsigned const amount_protons;

const char* const full_name;

const char* const short_name;
public:

Element( unsigned const a, const char* const b, const char* const c)
: protons_in_nucl eus(a), full_name(b), short_name(c) {}

unsigned AtomicNumber() const { return amount_protons; }
};
From here, there's two alternative routes you can take. We could make
"Carbon" as follows:

Element carbon(6, "Carbon", "C");
In the above case, "carbon" is a single object. This would probably make
sense for your particular project. Also, you may want to specify the average
atomic weight of an atom of the element.
Or... if it were a more elaborate Chemistry program, we could make "Carbon"
a type, as follows:

class Carbon : public Element
{
public:

Carbon() : Element(6, "Carbon", "C") {}
};
From here, we could go on to define the concept of Carbon-12. There's
another two alternatives... we could make the Carbon-12 isotope as an
object:

Carbon carbon_twelve(6 );
//Let's pretend its constructor takes the quantity of neutrons
Or, we could make it a class:
class Carbon_Twelve : public Carbon
{
//...
}
but before we got that far, we could make an "Isotope":

class Isotope : public Element
{
public:

unsigned GetQuantityNeut rons() const;
};

And then have:

class Carbon_Twelve : public Isotope
{
//...
};
And finally we can make an individual atom:

class Atom
{
private:
Element element;
unsigned amount_neutrons ;

//...
};

And also go on to define an "Ion":

class Ion : public Atom
{
public:

//...
}
Best thing to do is sit down with a pencil and a lots of sheets of paper and
try to come up with some good relationships, meaningful reasons for deriving
"Atom" from "Ion", or vice versa.

There's more than one way to solve this problem -- you just have to find a
way you like.
-Tomás

Mar 17 '06 #5
ni*******@redif fmail.com wrote:
Hi there,
I am looking to design a project using C++

The main objective of the project is to display details of periodic
table elements such as periodic element name, properties(such as atomic
number and atomic mass) for each periodic number entered by user. I am
thinking to input all the data regarding each periodic element number
in form of class.

Please give your opinion on the correct design method for the same.

Thanks

Nishant


Whatever you do with the rest of the program, I definitely recommend
NOT to hardcode the numerical values (of the elements in the periodic
table) in your code. If you store all of those values in a seperate
file, you will be able to edit/append things easily without recompiling
the code all the time. You just have to make sure that that file is
not tampered with by the user.

Mahurshi Akilla

Mar 17 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
6390
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but something I'll need in this case is some experience-based set of rules about how to use python in this context. For example... is defining readonly attributes in classes worth the hassle ? Does duck-typing scale well in complex
20
2815
by: Karl Smith | last post by:
I heard a rumour that Opera succeeded where none have before, and implemented the tables described in HTML4 and CSS2. So I thought I'd try it out with the well known Periodic Table. http://users.tpg.com.au/karl6740/css/table_elements_periodic.html CSS: Notice in the TRs with the lanthanides and actinides, the empty TDs at the end taking the background colour of the TR? I say they shouldn't
9
2936
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with a device. The definition of the table is as follows: CREATE TABLE devicedata ( device_id int NOT NULL REFERENCES devices(id), -- id in the device
0
1557
by: allyn44 | last post by:
Hello, I have a situation where I have to create 20 labels for each instance of an ID-each of the 20 labels has a different test number on it but needs the same id and one of 3 project names--for each label I need: ID number Project name (there are currently 3 but will be more in the future) Test number: There are 20 different tests for each ID number
10
2114
by: BlueDolphin | last post by:
I'm not sure if this is a question or more of a rant... but I'm looking for some input on this from other developers out there. How often has the following happened to you and how have you dealt with it. I am consulting on a new project. Originally I was going to get data dumped to me from an external system, and import the needed data once a week into a normalized design that I had created. I knew what my fields were going to be,...
17
2708
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but know nothing about ASP. He can build the design of the pages in HTML with tables, labels, textboxes etc. But then I would need to change them to ASP.net objects and write the code to make the page work (normally I do this as I go - can't do this...
8
16622
by: Brett | last post by:
I have a form with a Form1_Load() Subprocedure and no other code. For some reason, the design view does not come up. If I add a new form, the design view does come up. The form does appear when I execute the EXE. The design view for this form use to come up but I'm not sure when it stopped appearing. I do notice the form1.vb and class1.vb files in the Solution Explorer (Visual Studio.NET) have little arrows in the bottom left corner...
1
2050
by: nishantxl | last post by:
Hi there, I am looking to design a project using C++ The main objective of the project is to display details of periodic table elements such as periodic element name, properties(such as atomic number and atomic mass) for each periodic number entered by user. I am thinking to input all the data regarding each periodic element number in form of class. Please give your opinion on the correct design method for the same.
12
7012
by: nyathancha | last post by:
Hi, I have a question regarding best practices in database design. In a relational database, is it wise/necessary to sometimes create tables that are not related to other tables through a foreign Key relationship or does this always indicate some sort of underlying design flaw. Something that requires a re evaluation of the problem domain? The reason I ask is because in our application, the user can perform x
0
8723
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9354
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
5971
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4481
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4741
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3182
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2553
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2122
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.