aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar SharafatKarim <sharafat2004@gmail.com>2024-03-10 21:50:38 +0600
committerLibravatar SharafatKarim <sharafat2004@gmail.com>2024-03-10 21:50:38 +0600
commit9bb1850eb74237917c3ff8d3ab8315f3c196ff73 (patch)
tree60df5b0ca119515de1d9a456d570b250baf4b5da
parent0be48808422176133d21147d0dbbeeefdc3d4dac (diff)
parenta2d29e8b76d3969e7c5f4f4509abf92727585a1b (diff)
downloadentropy-calc-9bb1850eb74237917c3ff8d3ab8315f3c196ff73.tar.gz
entropy-calc-9bb1850eb74237917c3ff8d3ab8315f3c196ff73.zip
Merge branch 'main' into vscode
-rw-r--r--README.md5
-rw-r--r--entropy-calculator.cbp2
-rw-r--r--headers/baseElement.h158
-rw-r--r--headers/readElementState.cpp26
-rw-r--r--headers/readElementState.h10
-rw-r--r--main.cpp24
6 files changed, 164 insertions, 61 deletions
diff --git a/README.md b/README.md
index ef903b7..5aff9db 100644
--- a/README.md
+++ b/README.md
@@ -120,3 +120,8 @@ If you find any issues with the project, please open an issue in the repository.
[SR Tamim](https://sr-tamim.vercel.app)
[![sr-tamim's Profilator](https://profilator.deno.dev/sr-tamim?v=1.0.0.alpha.4)](https://github.com/sr-tamim)
+
+## Contributors
+
+[![sr-tamim's Profilator](https://profilator.deno.dev/sr-tamim?v=1.0.0.alpha.4)](https://github.com/sr-tamim)
+[![SharafatKarim's Profilator](https://profilator.deno.dev/SharafatKarim?v=1.0.0.alpha.4)](https://github.com/SharafatKarim)
diff --git a/entropy-calculator.cbp b/entropy-calculator.cbp
index daf78a5..797dabf 100644
--- a/entropy-calculator.cbp
+++ b/entropy-calculator.cbp
@@ -35,6 +35,8 @@
<Unit filename="elements/water.h" />
<Unit filename="headers/allElements.cpp" />
<Unit filename="headers/allElements.h" />
+ <Unit filename="headers/readElementState.cpp" />
+ <Unit filename="headers/readElementState.h" />
<Unit filename="headers/baseElement.h" />
<Unit filename="main.cpp" />
<Extensions>
diff --git a/headers/baseElement.h b/headers/baseElement.h
index fd77194..a3907fe 100644
--- a/headers/baseElement.h
+++ b/headers/baseElement.h
@@ -1,9 +1,9 @@
#ifndef BASEELEMENT_H_INCLUDED
#define BASEELEMENT_H_INCLUDED
-
#include <iostream>
#include <math.h>
+#include "readElementState.h"
using namespace std;
class baseElement
@@ -16,7 +16,9 @@ private:
double specificHeatLiquid;
double specificHeatGas;
double meltingPoint;
- double boilingPoint;
+ double boilingPoint;
+ string initialState = "";
+ string finalState = "";
protected:
void setElementName(string value) { elementName = value; }
@@ -40,76 +42,122 @@ public:
double totalHeatNeeded(double mass, double fromTemp, double toTemp)
{
- double totalHeat = 0;
- if (fromTemp <= meltingPoint && toTemp <= meltingPoint)
+ if (fromTemp < 0 || toTemp < 0)
{
- totalHeat = mass * specificHeatSolid * (toTemp - fromTemp);
+ cout << "Temperature cannot be less than 0 K" << endl;
+ return 0;
}
- else if (fromTemp <= meltingPoint && toTemp >= meltingPoint && toTemp <= boilingPoint)
+
+ double totalHeat = 0;
+ if (fromTemp == meltingPoint || fromTemp == boilingPoint)
{
- totalHeat = mass * specificHeatSolid * (meltingPoint - fromTemp);
- totalHeat += mass * latentHeatOfFusion / meltingPoint;
- totalHeat += mass * specificHeatLiquid * (toTemp - meltingPoint);
+ cout << "What is the state of the element at the initial temperature?" << endl;
+ initialState = readElementState();
}
- else if (fromTemp <= meltingPoint && toTemp >= boilingPoint)
+ if (toTemp == meltingPoint || toTemp == boilingPoint)
{
- totalHeat = mass * specificHeatSolid * (meltingPoint - fromTemp);
- totalHeat += mass * latentHeatOfFusion;
- totalHeat += mass * specificHeatLiquid * (boilingPoint - meltingPoint);
- totalHeat += mass * latentHeatOfVaporization;
- totalHeat += mass * specificHeatGas * (toTemp - boilingPoint);
+ cout << "What is the state of the element at the final temperature?" << endl;
+ finalState = readElementState();
}
- else if (fromTemp >= meltingPoint && fromTemp <= boilingPoint && toTemp >= meltingPoint && toTemp <= boilingPoint)
+
+ if (toTemp <= meltingPoint)
{
- totalHeat = mass * specificHeatLiquid * (toTemp - fromTemp);
+ totalHeat += mass * specificHeatSolid * (toTemp - fromTemp);
+ if (toTemp == meltingPoint && finalState != "Solid")
+ totalHeat += mass * latentHeatOfFusion;
}
- else if (fromTemp >= meltingPoint && fromTemp <= boilingPoint && toTemp >= boilingPoint)
+ else if (toTemp <= boilingPoint)
{
- totalHeat = mass * specificHeatLiquid * (boilingPoint - fromTemp);
- totalHeat += mass * latentHeatOfVaporization;
- totalHeat += mass * specificHeatGas * (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 >= boilingPoint && toTemp >= boilingPoint)
+ else
{
- totalHeat = mass * specificHeatGas * (toTemp - fromTemp);
+ 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)
{
- 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);
+ 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;
}
diff --git a/headers/readElementState.cpp b/headers/readElementState.cpp
new file mode 100644
index 0000000..494594a
--- /dev/null
+++ b/headers/readElementState.cpp
@@ -0,0 +1,26 @@
+#include <iostream>
+using namespace std;
+
+string readElementState()
+{
+ string state;
+ cout << "1. Solid\n2. Liquid\n3. Gas" << endl;
+ int choice;
+ cin >> choice;
+ switch (choice)
+ {
+ case 1:
+ state = "Solid";
+ break;
+ case 2:
+ state = "Liquid";
+ break;
+ case 3:
+ state = "Gas";
+ break;
+ default:
+ cout << "Invalid choice" << endl;
+ break;
+ }
+ return state;
+}
diff --git a/headers/readElementState.h b/headers/readElementState.h
new file mode 100644
index 0000000..5e0a2fa
--- /dev/null
+++ b/headers/readElementState.h
@@ -0,0 +1,10 @@
+// get all elements from elements folder
+
+#pragma once
+#ifndef READ_ELEMENT_STATE
+#define READ_ELEMENT_STATE
+
+#include <iostream>
+std::string readElementState();
+
+#endif
diff --git a/main.cpp b/main.cpp
index 6b6fa8e..9b78f4f 100644
--- a/main.cpp
+++ b/main.cpp
@@ -20,13 +20,25 @@ int main()
double mass, fromTemp, toTemp;
cout << "Enter the mass of the element (in Kg): ";
- cin >> mass;
+ cin >> mass;
+ if (mass <= 0)
+ {
+ cout << "Mass must be a positive value" << endl;
+ return 0;
+ }
cout << "Enter the initial temperature of the element (in K): ";
cin >> fromTemp;
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;
+ cin >> toTemp;
+ if (fromTemp > toTemp)
+ {
+ cout << "Initial temperature can not be greater than final temperature" << endl;
+ return 0;
+ }
+
+ double totalHeat = elements[choice - 1]->totalHeatNeeded(mass, fromTemp, toTemp);
+ double totalEntropy = elements[choice - 1]->totalEntropyChange(mass, fromTemp, toTemp);
+ cout << "The total heat needed is: " << totalHeat << " J" << endl;
+ cout << "The total entropy change is: " << totalEntropy << " J/K" << endl;
+ return 0;
}