aboutsummaryrefslogtreecommitdiff
path: root/headers/baseElement.h
diff options
context:
space:
mode:
Diffstat (limited to 'headers/baseElement.h')
-rw-r--r--headers/baseElement.h67
1 files changed, 45 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;
}