From a8aa863d7e9732dc65f86bb3f4cbdd243e6ad6da Mon Sep 17 00:00:00 2001 From: SR Tamim Date: Thu, 7 Mar 2024 01:39:41 +0600 Subject: Add water element and entropy calculator project files --- .gitignore | 40 ++++++++++++++++++++++++ elements/water.h | 23 ++++++++++++++ entropy-calculator.cbp | 44 +++++++++++++++++++++++++++ headers/allElements.cpp | 11 +++++++ headers/allElements.h | 12 ++++++++ headers/genericElement.h | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ main.cpp | 30 ++++++++++++++++++ 7 files changed, 239 insertions(+) create mode 100644 .gitignore create mode 100644 elements/water.h create mode 100644 entropy-calculator.cbp create mode 100644 headers/allElements.cpp create mode 100644 headers/allElements.h create mode 100644 headers/genericElement.h create mode 100644 main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eff81b2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,40 @@ +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Code::Blocks project files +*.layout +*.depend + +# Debug files +bin/ +obj/ \ No newline at end of file diff --git a/elements/water.h b/elements/water.h new file mode 100644 index 0000000..a1a597e --- /dev/null +++ b/elements/water.h @@ -0,0 +1,23 @@ +#ifndef WATER_HPP_INCLUDED +#define WATER_HPP_INCLUDED + +#include "../headers/genericElement.h" + +class water : public genericElement +{ +public: + water() + { + setElementName("Water"); + setSpecificHeatLiquid(4184); + setSpecificHeatSolid(2093); + setSpecificHeatGas(2010); + setLatentHeatOfFusion(334000); + setLatentHeatOfVaporization(2260000); + setMeltingPoint(273); + setBoilingPoint(373); + } +}; + + +#endif // WATER_HPP_INCLUDED diff --git a/entropy-calculator.cbp b/entropy-calculator.cbp new file mode 100644 index 0000000..f9b1570 --- /dev/null +++ b/entropy-calculator.cbp @@ -0,0 +1,44 @@ + + + + + + diff --git a/headers/allElements.cpp b/headers/allElements.cpp new file mode 100644 index 0000000..435f680 --- /dev/null +++ b/headers/allElements.cpp @@ -0,0 +1,11 @@ +#include +#include "../elements/water.h" +#include "genericElement.h" + + +vector getAllElements() +{ + vector elements; + elements.push_back(new water()); + return elements; +} diff --git a/headers/allElements.h b/headers/allElements.h new file mode 100644 index 0000000..5bf3627 --- /dev/null +++ b/headers/allElements.h @@ -0,0 +1,12 @@ +// get all elements from elements folder + +#pragma once +#ifndef ALL_ELEMENTS +#define ALL_ELEMENTS + +#include +#include "genericElement.h" + +std::vector getAllElements(); + +#endif diff --git a/headers/genericElement.h b/headers/genericElement.h new file mode 100644 index 0000000..5e7044d --- /dev/null +++ b/headers/genericElement.h @@ -0,0 +1,79 @@ +#ifndef GENERICELEMENT_H_INCLUDED +#define GENERICELEMENT_H_INCLUDED + + +#include +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 new file mode 100644 index 0000000..f9e2c38 --- /dev/null +++ b/main.cpp @@ -0,0 +1,30 @@ +#include +#include +#include "headers/allElements.h" +#include "headers/genericElement.h" + +using namespace std; + +int main() +{ + vector 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; + 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 entropy change is: " << elements[choice - 1]->totalEntropyChange(mass, fromTemp, toTemp) << " J/K" << endl; +} -- cgit v1.2.3