aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Mubashshir <ahmubashshir@gmail.com>2024-03-12 13:36:33 +0600
committerLibravatar Mubashshir <ahmubashshir@gmail.com>2024-03-12 13:36:33 +0600
commit8808dbe579cb4a935e32b3abfb2de81cf796e977 (patch)
tree54d9d169c6bed8c5e688c77d14de269ab5c93693
parentb5590275651c8d0f80be7c698491725e7382b330 (diff)
downloadentropy-calc-8808dbe579cb4a935e32b3abfb2de81cf796e977.tar.gz
entropy-calc-8808dbe579cb4a935e32b3abfb2de81cf796e977.zip
linux: Convert CRLF to LF only
Signed-off-by: Mubashshir <ahmubashshir@gmail.com>
-rw-r--r--headers/baseElement.h118
-rw-r--r--main.cpp91
2 files changed, 103 insertions, 106 deletions
diff --git a/headers/baseElement.h b/headers/baseElement.h
index a3907fe..160d4b1 100644
--- a/headers/baseElement.h
+++ b/headers/baseElement.h
@@ -16,8 +16,8 @@ private:
double specificHeatLiquid;
double specificHeatGas;
double meltingPoint;
- double boilingPoint;
- string initialState = "";
+ double boilingPoint;
+ string initialState = "";
string finalState = "";
protected:
@@ -101,63 +101,63 @@ public:
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);
+ 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/main.cpp b/main.cpp
index 0372acd..a60839a 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,47 +1,44 @@
-#include <iostream>
-#include <vector>
-#include "headers/allElements.h"
-#include "headers/baseElement.h"
-
-using namespace std;
-
-int main()
-{
- vector<baseElement*> elements = getAllElements();
- cout << "Choose an element: " << endl;
- for (int i = 0; i < elements.size(); i++)
- {
- cout << i + 1 << ". " << elements[i]->getElementName() << endl;
- }
- int choice;
- cout << "Write the number of the element: ";
- cin >> choice;
- cout << endl << elements[choice - 1]->getElementName() << " Selected" << endl;
-
- double mass, fromTemp, toTemp;
- cout << "Enter the mass of the element (in Kg): ";
- 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;
- 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;
-
- //thank you.. feel free to contribute here..:)
-
-}
+#include <iostream>
+#include <vector>
+#include "headers/allElements.h"
+#include "headers/baseElement.h"
+
+using namespace std;
+
+int main()
+{
+ vector<baseElement*> elements = getAllElements();
+ cout << "Choose an element: " << endl;
+ for (int i = 0; i < elements.size(); i++) {
+ cout << i + 1 << ". " << elements[i]->getElementName() << endl;
+ }
+ int choice;
+ cout << "Write the number of the element: ";
+ cin >> choice;
+ cout << endl << elements[choice - 1]->getElementName() << " Selected" << endl;
+
+ double mass, fromTemp, toTemp;
+ cout << "Enter the mass of the element (in Kg): ";
+ 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;
+ 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;
+
+ //thank you.. feel free to contribute here..:)
+
+}