diff options
Diffstat (limited to 'headers')
-rw-r--r-- | headers/allElements.cpp | 2 | ||||
-rw-r--r-- | headers/baseElement.h | 161 |
2 files changed, 87 insertions, 76 deletions
diff --git a/headers/allElements.cpp b/headers/allElements.cpp index 7c0e6a2..1576dfd 100644 --- a/headers/allElements.cpp +++ b/headers/allElements.cpp @@ -1,5 +1,6 @@ #include<vector> #include "../elements/water.h" +#include "../elements/Silver.h" #include "baseElement.h" @@ -7,5 +8,6 @@ vector<baseElement*> getAllElements() { vector<baseElement*> elements; elements.push_back(new water()); + elements.push_back(new Silver()); return elements; } diff --git a/headers/baseElement.h b/headers/baseElement.h index a3907fe..42fb8e5 100644 --- a/headers/baseElement.h +++ b/headers/baseElement.h @@ -3,21 +3,33 @@ #include <iostream> #include <math.h> +#ifdef _USE_GMP +# include <gmp.h> +# include <gmpxx.h> +#endif // _USE_GMP #include "readElementState.h" using namespace std; +#ifdef _USE_GMP + typedef mpf_class bigfloat; +# define bigfloat_unwrap(X) (bigfloat(X)).get_d() +#else + typedef double bigfloat; +# define bigfloat_unwrap(X) (X) +#endif // _USE_GMP + class baseElement { private: string elementName; - double latentHeatOfFusion; - double latentHeatOfVaporization; - double specificHeatSolid; - double specificHeatLiquid; - double specificHeatGas; - double meltingPoint; - double boilingPoint;
- string initialState = "";
+ bigfloat latentHeatOfFusion; + bigfloat latentHeatOfVaporization; + bigfloat specificHeatSolid; + bigfloat specificHeatLiquid; + bigfloat specificHeatGas; + bigfloat meltingPoint; + bigfloat boilingPoint; + string initialState = ""; string finalState = ""; protected: @@ -32,15 +44,15 @@ protected: 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; } + bigfloat getLatentHeatOfFusion() { return latentHeatOfFusion; } + bigfloat getLatentHeatOfVaporization() { return latentHeatOfVaporization; } + bigfloat getSpecificHeatSolid() { return specificHeatSolid; } + bigfloat getSpecificHeatLiquid() { return specificHeatLiquid; } + bigfloat getSpecificHeatGas() { return specificHeatGas; } + bigfloat getMeltingPoint() { return meltingPoint; } + bigfloat getBoilingPoint() { return boilingPoint; } - double totalHeatNeeded(double mass, double fromTemp, double toTemp) + bigfloat totalHeatNeeded(double mass, double fromTemp, double toTemp) { if (fromTemp < 0 || toTemp < 0) { @@ -48,7 +60,7 @@ public: return 0; } - double totalHeat = 0; + bigfloat totalHeat = 0; if (fromTemp == meltingPoint || fromTemp == boilingPoint) { cout << "What is the state of the element at the initial temperature?" << endl; @@ -99,68 +111,65 @@ public: return totalHeat; } - double totalEntropyChange(double mass, double fromTemp, double toTemp) + bigfloat 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);
+ if (fromTemp < 0 || toTemp < 0) + { + cout << "Temperature cannot be less than 0 K" << endl; + return 0; + } + + bigfloat totalEntropy = 0; + 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(bigfloat_unwrap(toTemp / fromTemp)); + if (toTemp == meltingPoint && finalState != "Solid") + totalEntropy += mass * latentHeatOfFusion / meltingPoint; + } + else if (toTemp <= boilingPoint) + { + if (fromTemp < meltingPoint) + totalEntropy += mass * specificHeatSolid * log(bigfloat_unwrap(meltingPoint / fromTemp)); + if (fromTemp == meltingPoint && initialState != "Liquid") + totalEntropy += mass * latentHeatOfFusion / meltingPoint; + if (fromTemp <= meltingPoint) + totalEntropy += mass * specificHeatLiquid * log(bigfloat_unwrap(toTemp / meltingPoint)); + else + totalEntropy += mass * specificHeatLiquid * log(bigfloat_unwrap(toTemp / fromTemp)); + if (toTemp == boilingPoint && finalState != "Liquid") + totalEntropy += mass * latentHeatOfVaporization / boilingPoint; + } + else + { + if (fromTemp < meltingPoint) + totalEntropy += mass * specificHeatSolid * log(bigfloat_unwrap(meltingPoint / fromTemp)); + if (fromTemp == meltingPoint && initialState != "Liquid") + totalEntropy += mass * latentHeatOfFusion / meltingPoint; + + if (fromTemp < boilingPoint) + totalEntropy += mass * specificHeatLiquid * log(bigfloat_unwrap(fromTemp / meltingPoint)); + if (fromTemp == boilingPoint && initialState != "Gas") + totalEntropy += mass * latentHeatOfVaporization / boilingPoint; + + if (fromTemp > boilingPoint) + totalEntropy += mass * specificHeatGas * log(bigfloat_unwrap(toTemp / fromTemp)); + else + totalEntropy += mass * specificHeatGas * log(bigfloat_unwrap(toTemp / boilingPoint)); } return totalEntropy; } }; - #endif // BASEELEMENT_H_INCLUDED |