aboutsummaryrefslogtreecommitdiff
path: root/headers
diff options
context:
space:
mode:
Diffstat (limited to 'headers')
-rw-r--r--headers/baseElement.h67
-rw-r--r--headers/readElementState.cpp26
-rw-r--r--headers/readElementState.h10
3 files changed, 81 insertions, 22 deletions
diff --git a/headers/baseElement.h b/headers/baseElement.h
index fd77194..e6372a1 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
@@ -40,38 +40,61 @@ 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;
+ string initialState = "";
+ string finalState = "";
+ 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 && initialState != finalState)
+ 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 != finalState)
+ totalHeat += mass * latentHeatOfFusion;
+ if (fromTemp <= meltingPoint)
+ totalHeat += mass * specificHeatLiquid * (toTemp - meltingPoint);
+ else
+ totalHeat += mass * specificHeatLiquid * (toTemp - fromTemp);
+ if (toTemp == boilingPoint && initialState != finalState)
+ 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 != finalState)
+ totalHeat += mass * latentHeatOfFusion;
+
+ if (fromTemp < boilingPoint)
+ totalHeat += mass * specificHeatLiquid * (fromTemp - meltingPoint);
+ if (fromTemp == boilingPoint && initialState != finalState)
+ totalHeat += mass * latentHeatOfVaporization;
+
+ if (fromTemp > boilingPoint)
+ totalHeat += mass * specificHeatGas * (toTemp - fromTemp);
+ else
+ totalHeat += mass * specificHeatGas * (toTemp - boilingPoint);
}
return totalHeat;
}
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