aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar SR Tamim <saifur.rahman.tamim1@gmail.com>2024-03-07 10:05:41 +0600
committerLibravatar SR Tamim <saifur.rahman.tamim1@gmail.com>2024-03-07 10:05:41 +0600
commit48110b812253975b6e2437fef07b84dd7382db9e (patch)
tree1ea043569604280ca8f10bb5811871a8f3c9dbbb
parentd9f58439b81b2505456c05dc2e64864b1cbcfde2 (diff)
downloadentropy-calc-48110b812253975b6e2437fef07b84dd7382db9e.tar.gz
entropy-calc-48110b812253975b6e2437fef07b84dd7382db9e.zip
total heat needed & entropy change
-rw-r--r--elements/water.h4
-rw-r--r--entropy-calculator.cbp2
-rw-r--r--headers/allElements.cpp6
-rw-r--r--headers/allElements.h4
-rw-r--r--headers/baseElement.h118
-rw-r--r--headers/genericElement.h79
-rw-r--r--main.cpp6
7 files changed, 130 insertions, 89 deletions
diff --git a/elements/water.h b/elements/water.h
index a1a597e..a20eacd 100644
--- a/elements/water.h
+++ b/elements/water.h
@@ -1,9 +1,9 @@
#ifndef WATER_HPP_INCLUDED
#define WATER_HPP_INCLUDED
-#include "../headers/genericElement.h"
+#include "../headers/baseElement.h"
-class water : public genericElement
+class water : public baseElement
{
public:
water()
diff --git a/entropy-calculator.cbp b/entropy-calculator.cbp
index f9b1570..daf78a5 100644
--- a/entropy-calculator.cbp
+++ b/entropy-calculator.cbp
@@ -35,7 +35,7 @@
<Unit filename="elements/water.h" />
<Unit filename="headers/allElements.cpp" />
<Unit filename="headers/allElements.h" />
- <Unit filename="headers/genericElement.h" />
+ <Unit filename="headers/baseElement.h" />
<Unit filename="main.cpp" />
<Extensions>
<lib_finder disable_auto="1" />
diff --git a/headers/allElements.cpp b/headers/allElements.cpp
index 435f680..7c0e6a2 100644
--- a/headers/allElements.cpp
+++ b/headers/allElements.cpp
@@ -1,11 +1,11 @@
#include<vector>
#include "../elements/water.h"
-#include "genericElement.h"
+#include "baseElement.h"
-vector<genericElement*> getAllElements()
+vector<baseElement*> getAllElements()
{
- vector<genericElement*> elements;
+ vector<baseElement*> elements;
elements.push_back(new water());
return elements;
}
diff --git a/headers/allElements.h b/headers/allElements.h
index 5bf3627..9db7188 100644
--- a/headers/allElements.h
+++ b/headers/allElements.h
@@ -5,8 +5,8 @@
#define ALL_ELEMENTS
#include<vector>
-#include "genericElement.h"
+#include "baseElement.h"
-std::vector<genericElement*> getAllElements();
+std::vector<baseElement*> getAllElements();
#endif
diff --git a/headers/baseElement.h b/headers/baseElement.h
new file mode 100644
index 0000000..fd77194
--- /dev/null
+++ b/headers/baseElement.h
@@ -0,0 +1,118 @@
+#ifndef BASEELEMENT_H_INCLUDED
+#define BASEELEMENT_H_INCLUDED
+
+
+#include <iostream>
+#include <math.h>
+using namespace std;
+
+class baseElement
+{
+private:
+ string elementName;
+ double latentHeatOfFusion;
+ double latentHeatOfVaporization;
+ double specificHeatSolid;
+ double specificHeatLiquid;
+ double specificHeatGas;
+ double meltingPoint;
+ double boilingPoint;
+
+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)
+ {
+ double totalHeat = 0;
+ if (fromTemp <= meltingPoint && toTemp <= meltingPoint)
+ {
+ totalHeat = mass * specificHeatSolid * (toTemp - fromTemp);
+ }
+ else if (fromTemp <= meltingPoint && toTemp >= meltingPoint && toTemp <= boilingPoint)
+ {
+ totalHeat = mass * specificHeatSolid * (meltingPoint - fromTemp);
+ totalHeat += mass * latentHeatOfFusion / meltingPoint;
+ totalHeat += mass * specificHeatLiquid * (toTemp - meltingPoint);
+ }
+ else if (fromTemp <= meltingPoint && toTemp >= boilingPoint)
+ {
+ totalHeat = mass * specificHeatSolid * (meltingPoint - fromTemp);
+ totalHeat += mass * latentHeatOfFusion;
+ totalHeat += mass * specificHeatLiquid * (boilingPoint - meltingPoint);
+ totalHeat += mass * latentHeatOfVaporization;
+ totalHeat += mass * specificHeatGas * (toTemp - boilingPoint);
+ }
+ else if (fromTemp >= meltingPoint && fromTemp <= boilingPoint && toTemp >= meltingPoint && toTemp <= boilingPoint)
+ {
+ totalHeat = mass * specificHeatLiquid * (toTemp - fromTemp);
+ }
+ else if (fromTemp >= meltingPoint && fromTemp <= boilingPoint && toTemp >= boilingPoint)
+ {
+ totalHeat = mass * specificHeatLiquid * (boilingPoint - fromTemp);
+ totalHeat += mass * latentHeatOfVaporization;
+ totalHeat += mass * specificHeatGas * (toTemp - boilingPoint);
+ }
+ else if (fromTemp >= boilingPoint && toTemp >= boilingPoint)
+ {
+ totalHeat = mass * specificHeatGas * (toTemp - fromTemp);
+ }
+ return totalHeat;
+ }
+
+ double totalEntropyChange(double mass, double fromTemp, double toTemp)
+ {
+ double totalEntropy = 0;
+ if (fromTemp <= meltingPoint && toTemp <= meltingPoint)
+ {
+ totalEntropy = mass * specificHeatSolid * log(toTemp / fromTemp);
+ }
+ else if (fromTemp <= meltingPoint && toTemp >= meltingPoint && toTemp <= boilingPoint)
+ {
+ totalEntropy = mass * specificHeatSolid * log(meltingPoint / fromTemp);
+ totalEntropy += mass * latentHeatOfFusion / meltingPoint;
+ totalEntropy += mass * specificHeatLiquid * log(toTemp / meltingPoint);
+ }
+ else if (fromTemp <= meltingPoint && toTemp >= boilingPoint)
+ {
+ totalEntropy = mass * specificHeatSolid * log(meltingPoint / fromTemp);
+ totalEntropy += mass * latentHeatOfFusion;
+ totalEntropy += mass * specificHeatLiquid * log(boilingPoint / meltingPoint);
+ totalEntropy += mass * latentHeatOfVaporization;
+ totalEntropy += mass * specificHeatGas * log(toTemp / boilingPoint);
+ }
+ else if (fromTemp >= meltingPoint && fromTemp <= boilingPoint && toTemp >= meltingPoint && toTemp <= boilingPoint)
+ {
+ totalEntropy = mass * specificHeatLiquid * log(toTemp / fromTemp);
+ }
+ else if (fromTemp >= meltingPoint && fromTemp <= boilingPoint && toTemp >= boilingPoint)
+ {
+ totalEntropy = mass * specificHeatLiquid * log(boilingPoint / fromTemp);
+ totalEntropy += mass * latentHeatOfVaporization;
+ totalEntropy += mass * specificHeatGas * log(toTemp / boilingPoint);
+ }
+ else if (fromTemp >= boilingPoint && toTemp >= boilingPoint)
+ {
+ totalEntropy = mass * specificHeatGas * log(toTemp / fromTemp);
+ }
+ return totalEntropy;
+ }
+};
+
+#endif // BASEELEMENT_H_INCLUDED
diff --git a/headers/genericElement.h b/headers/genericElement.h
deleted file mode 100644
index 5e7044d..0000000
--- a/headers/genericElement.h
+++ /dev/null
@@ -1,79 +0,0 @@
-#ifndef GENERICELEMENT_H_INCLUDED
-#define GENERICELEMENT_H_INCLUDED
-
-
-#include <iostream>
-using namespace std;
-
-class genericElement
-{
-private:
- string elementName;
- double latentHeatOfFusion;
- double latentHeatOfVaporization;
- double specificHeatSolid;
- double specificHeatLiquid;
- double specificHeatGas;
- double meltingPoint;
- double boilingPoint;
-
-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 totalEntropyChange(double mass, double fromTemp, double toTemp)
- {
- double totalEntropy = 0;
- if (fromTemp <= meltingPoint && toTemp <= meltingPoint)
- {
- totalEntropy = mass * specificHeatSolid * (toTemp - fromTemp);
- }
- else if (fromTemp <= meltingPoint && toTemp >= meltingPoint && toTemp <= boilingPoint)
- {
- totalEntropy = mass * specificHeatSolid * (meltingPoint - fromTemp);
- totalEntropy += mass * latentHeatOfFusion / meltingPoint;
- totalEntropy += mass * specificHeatLiquid * (toTemp - meltingPoint);
- }
- else if (fromTemp <= meltingPoint && toTemp >= boilingPoint)
- {
- totalEntropy = mass * specificHeatSolid * (meltingPoint - fromTemp);
- totalEntropy += mass * latentHeatOfFusion;
- totalEntropy += mass * specificHeatLiquid * (boilingPoint - meltingPoint);
- totalEntropy += mass * latentHeatOfVaporization;
- totalEntropy += mass * specificHeatGas * (toTemp - boilingPoint);
- }
- else if (fromTemp >= meltingPoint && fromTemp <= boilingPoint && toTemp >= meltingPoint && toTemp <= boilingPoint)
- {
- totalEntropy = mass * specificHeatLiquid * (toTemp - fromTemp);
- }
- else if (fromTemp >= meltingPoint && fromTemp <= boilingPoint && toTemp >= boilingPoint)
- {
- totalEntropy = mass * specificHeatLiquid * (boilingPoint - fromTemp);
- totalEntropy += mass * latentHeatOfVaporization;
- totalEntropy += mass * specificHeatGas * (toTemp - boilingPoint);
- }
- else if (fromTemp >= boilingPoint && toTemp >= boilingPoint)
- {
- totalEntropy = mass * specificHeatGas * (toTemp - fromTemp);
- }
- return totalEntropy;
- }
-};
-
-#endif // GENERICELEMENT_H_INCLUDED
diff --git a/main.cpp b/main.cpp
index f9e2c38..6b6fa8e 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,13 +1,13 @@
#include <iostream>
#include <vector>
#include "headers/allElements.h"
-#include "headers/genericElement.h"
+#include "headers/baseElement.h"
using namespace std;
int main()
{
- vector<genericElement*> elements = getAllElements();
+ vector<baseElement*> elements = getAllElements();
cout << "Choose an element: " << endl;
for (int i = 0; i < elements.size(); i++)
{
@@ -26,5 +26,7 @@ int main()
cout << "Enter the final temperature of the element (in K): ";
cin >> toTemp;
+ cout << "The total heat needed is: " << elements[choice - 1]->totalHeatNeeded(mass, fromTemp, toTemp) << " J" << endl;
+
cout << "The total entropy change is: " << elements[choice - 1]->totalEntropyChange(mass, fromTemp, toTemp) << " J/K" << endl;
}