blob: a3907fe14b7f4db14c5f3864dc3ca58b22236d8e (
plain) (
blame)
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
#ifndef BASEELEMENT_H_INCLUDED
#define BASEELEMENT_H_INCLUDED
#include <iostream>
#include <math.h>
#include "readElementState.h"
using namespace std;
class baseElement
{
private:
string elementName;
double latentHeatOfFusion;
double latentHeatOfVaporization;
double specificHeatSolid;
double specificHeatLiquid;
double specificHeatGas;
double meltingPoint;
double boilingPoint;
string initialState = "";
string finalState = "";
protected:
void setElementName(string value) { elementName = value; }
void setLatentHeatOfFusion(double value) { latentHeatOfFusion = value; }
void setLatentHeatOfVaporization(double value) { latentHeatOfVaporization = value; }
void setSpecificHeatSolid(double value) { specificHeatSolid = value; }
void setSpecificHeatLiquid(double value) { specificHeatLiquid = value; }
void setSpecificHeatGas(double value) { specificHeatGas = value; }
void setMeltingPoint(double value) { meltingPoint = value; }
void setBoilingPoint(double value) { boilingPoint = value; }
public:
string getElementName() { return elementName; }
double getLatentHeatOfFusion() { return latentHeatOfFusion; }
double getLatentHeatOfVaporization() { return latentHeatOfVaporization; }
double getSpecificHeatSolid() { return specificHeatSolid; }
double getSpecificHeatLiquid() { return specificHeatLiquid; }
double getSpecificHeatGas() { return specificHeatGas; }
double getMeltingPoint() { return meltingPoint; }
double getBoilingPoint() { return boilingPoint; }
double totalHeatNeeded(double mass, double fromTemp, double toTemp)
{
if (fromTemp < 0 || toTemp < 0)
{
cout << "Temperature cannot be less than 0 K" << endl;
return 0;
}
double totalHeat = 0;
if (fromTemp == meltingPoint || fromTemp == boilingPoint)
{
cout << "What is the state of the element at the initial temperature?" << endl;
initialState = readElementState();
}
if (toTemp == meltingPoint || toTemp == boilingPoint)
{
cout << "What is the state of the element at the final temperature?" << endl;
finalState = readElementState();
}
if (toTemp <= meltingPoint)
{
totalHeat += mass * specificHeatSolid * (toTemp - fromTemp);
if (toTemp == meltingPoint && finalState != "Solid")
totalHeat += mass * latentHeatOfFusion;
}
else if (toTemp <= boilingPoint)
{
if (fromTemp < meltingPoint)
totalHeat += mass * specificHeatSolid * (meltingPoint - fromTemp);
if (fromTemp == meltingPoint && initialState != "Liquid")
totalHeat += mass * latentHeatOfFusion;
if (fromTemp <= meltingPoint)
totalHeat += mass * specificHeatLiquid * (toTemp - meltingPoint);
else
totalHeat += mass * specificHeatLiquid * (toTemp - fromTemp);
if (toTemp == boilingPoint && finalState != "Liquid")
totalHeat += mass * latentHeatOfVaporization;
}
else
{
if (fromTemp < meltingPoint)
totalHeat += mass * specificHeatSolid * (meltingPoint - fromTemp);
if (fromTemp == meltingPoint && initialState != "Liquid")
totalHeat += mass * latentHeatOfFusion;
if (fromTemp < boilingPoint)
totalHeat += mass * specificHeatLiquid * (fromTemp - meltingPoint);
if (fromTemp == boilingPoint && initialState != "Gas")
totalHeat += mass * latentHeatOfVaporization;
if (fromTemp > boilingPoint)
totalHeat += mass * specificHeatGas * (toTemp - fromTemp);
else
totalHeat += mass * specificHeatGas * (toTemp - boilingPoint);
}
return totalHeat;
}
double totalEntropyChange(double mass, double fromTemp, double toTemp)
{
if (fromTemp < 0 || toTemp < 0)
{
cout << "Temperature cannot be less than 0 K" << endl;
return 0;
}
double totalEntropy = 0;
string initialState = "";
string finalState = "";
if (fromTemp == meltingPoint || fromTemp == boilingPoint)
{
cout << "What is the state of the element at the initial temperature?" << endl;
if (initialState != "")
initialState = readElementState();
}
if (toTemp == meltingPoint || toTemp == boilingPoint)
{
cout << "What is the state of the element at the final temperature?" << endl;
if (finalState != "")
finalState = readElementState();
}
if (toTemp <= meltingPoint)
{
totalEntropy += mass * specificHeatSolid * log(toTemp / fromTemp);
if (toTemp == meltingPoint && finalState != "Solid")
totalEntropy += mass * latentHeatOfFusion / meltingPoint;
}
else if (toTemp <= boilingPoint)
{
if (fromTemp < meltingPoint)
totalEntropy += mass * specificHeatSolid * log(meltingPoint / fromTemp);
if (fromTemp == meltingPoint && initialState != "Liquid")
totalEntropy += mass * latentHeatOfFusion / meltingPoint;
if (fromTemp <= meltingPoint)
totalEntropy += mass * specificHeatLiquid * log(toTemp / meltingPoint);
else
totalEntropy += mass * specificHeatLiquid * log(toTemp / fromTemp);
if (toTemp == boilingPoint && finalState != "Liquid")
totalEntropy += mass * latentHeatOfVaporization / boilingPoint;
}
else
{
if (fromTemp < meltingPoint)
totalEntropy += mass * specificHeatSolid * log(meltingPoint / fromTemp);
if (fromTemp == meltingPoint && initialState != "Liquid")
totalEntropy += mass * latentHeatOfFusion / meltingPoint;
if (fromTemp < boilingPoint)
totalEntropy += mass * specificHeatLiquid * log(fromTemp / meltingPoint);
if (fromTemp == boilingPoint && initialState != "Gas")
totalEntropy += mass * latentHeatOfVaporization / boilingPoint;
if (fromTemp > boilingPoint)
totalEntropy += mass * specificHeatGas * log(toTemp / fromTemp);
else
totalEntropy += mass * specificHeatGas * log(toTemp / boilingPoint);
}
return totalEntropy;
}
};
#endif // BASEELEMENT_H_INCLUDED
|