From a2d29e8b76d3969e7c5f4f4509abf92727585a1b Mon Sep 17 00:00:00 2001 From: SR Tamim Date: Sun, 10 Mar 2024 06:41:01 +0600 Subject: total entropy calculation fixed --- headers/baseElement.h | 95 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 35 deletions(-) diff --git a/headers/baseElement.h b/headers/baseElement.h index 4285fc0..a3907fe 100644 --- a/headers/baseElement.h +++ b/headers/baseElement.h @@ -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; } @@ -47,8 +49,6 @@ public: } double totalHeat = 0; - string initialState = ""; - string finalState = ""; if (fromTemp == meltingPoint || fromTemp == boilingPoint) { cout << "What is the state of the element at the initial temperature?" << endl; @@ -101,38 +101,63 @@ public: 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; } -- cgit v1.2.3