This repository has been archived by the owner on Oct 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chem_cmd.cpp
145 lines (134 loc) · 3.04 KB
/
chem_cmd.cpp
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include<iostream>
#include<string>
#include<conio.h> //for _get_restrict_che()
void disp_error(const char* str)
{
#ifdef _WINDOWS_
MessageBox(NULL,str,"Chem Analyze error",MB_ICONERROR|MB_OK);
#else
std::cout<<"Error:\t"<<str<<std::endl;
#endif
}
void disp_error(const std::string& str)
{
#ifdef _WINDOWS_
MessageBox(NULL,str.c_str(),"Chem Analyze error",MB_ICONERROR|MB_OK);
#else
std::cout<<"Error:\t"<<str<<std::endl;
#endif
}
#include"chem.h"
char _get_restrict_che(const char* a)
{
char ch;unsigned i;
while(true)
{
ch=_getch();
for(i=0;a[i]!='\0';i++)if(ch==a[i])
{_putch(ch);return ch;}
}
}
void disp_msg(const char* str)
{
#ifdef _WINDOWS_
MessageBox(NULL,str,"Chem Analyze msg",MB_ICONINFORMATION|MB_OK);
#else
std::cout<<str<<std::endl;
#endif
}
void disp_msg(const std::string& str)
{
#ifdef _WINDOWS_
MessageBox(NULL,str.c_str(),"Chem Analyze msg",MB_ICONINFORMATION|MB_OK);
#else
std::cout<<str<<std::endl;
#endif
}
using namespace std;
void reaction()
{
std::string str;
std::set<std::string> obs_set;
std::set<std::string>::iterator it;
tube_t tube;
bool heat;
do
{
cout<<"\nEnter reactants:\t";
if(cin.peek()=='\n')cin.ignore();
std::getline(cin,str);
std::remove(str.begin(),str.end(),' ');
cout<<"Heat? (y/n) ";
heat=('y'==_get_restrict_che("yn"));
cout<<endl;
tube.assign(str,heat);
tube.react_list(RXNS_FILE,obs_set);
cout<<boost::lexical_cast<std::string>(tube)<<endl;
tube.phys_obs(obs_set);
for(it=obs_set.begin();it!=obs_set.end();++it)cout<<*it<<endl;
obs_set.clear();
}
while(true);
}
void show_help()
{
std::ifstream ifile(HELP_FILE);
std::string str;
std::getline(ifile,str,char(EOF));
ifile.close();
disp_msg(str);
}
void salt_analysis(char mode)
{
std::string str;
std::set<std::string> obs_set;
std::set<std::string>::iterator it;
tube_t tube;
bool heat;
comp_t comp;
if(mode=='s')comp=get_random_salt();
else if(mode=='a')comp=get_random_anion();
else if(mode=='c')comp=get_random_cation();
tube.add(comp);
do
{
cout<<"\nEnter reagents:\t";
if(cin.peek()=='\n')cin.ignore();
getline(cin,str);
if(str==comp.form)cout<<"Correct!"<<endl;
else if(str=="answer")cout<<comp.form<<endl;
else if(str=="new")
{
if(mode=='s')comp=get_random_salt();
else if(mode=='a')comp=get_random_anion();
else if(mode=='c')comp=get_random_cation();
tube.comp_list.clear();
tube.add(comp);
}
else if(str=="clear"){tube.comp_list.clear();tube.add(comp);}
else if(str=="disp")cout<<boost::lexical_cast<std::string>(tube)<<endl;
else if(str=="help")show_help();
else
{
cout<<"Heat? (y/n) ";
heat=('y'==_get_restrict_che("yn"));
cout<<endl;
tube.add(str,heat);
tube.react_list(RXNS_FILE,obs_set);
tube.phys_obs(obs_set);
for(it=obs_set.begin();it!=obs_set.end();++it)cout<<*it<<endl;
obs_set.clear();
}
}
while(true);
}
int main()
{
char ch;
cout<<"Enter an option:\nr - Reactions\ns - Salt analysis\na - Anion analysis\nc - Cation analysis\n"<<endl;
ch=_get_restrict_che("rsac");
cout<<endl;
if(ch=='r')reaction();
else salt_analysis(ch);
return 0;
}