-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPeriodicTable.h
80 lines (62 loc) · 1.38 KB
/
PeriodicTable.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef __PERIODIC_TABLE_H__
#define __PERIODIC_TABLE_H__
class Periodic_Table
{
struct Info
{
string name;
string full_name;
int atomic_number;
int valence;
double atomic_mass;
};
map<string, Info> elementInfo;
public:
Periodic_Table();
Periodic_Table(string element);
double getMass( string element);
int getNumber( string element);
int getValence( string element);
string getFullName( string element );
};
Periodic_Table::Periodic_Table()
{
string name;
ifstream in;
in.open("C:\\Users\\Sultan\\Documents\\GitHub\\organ\\elements.txt");
// If we couldn't open the output file stream for reading
if (!in.is_open())
{
// Print an error and exit
cerr << "Cant open elements.txt file" << endl;
exit(1);
}
Info temp_info;
while( in >> temp_info.name )
{
in >> temp_info.full_name;
in >> temp_info.atomic_number;
in >> temp_info.atomic_mass;
in >> temp_info.valence;
// Add struct to map
elementInfo[temp_info.name] = temp_info;
}
in.close();
}
double Periodic_Table::getMass(string name)
{
return elementInfo[name].atomic_mass;
}
int Periodic_Table::getValence(string name)
{
return elementInfo[name].valence;
}
int Periodic_Table::getNumber(string name)
{
return elementInfo[name].atomic_number;
}
string Periodic_Table::getFullName(string name)
{
return elementInfo[name].full_name;
}
#endif