I just finished writing a program that captures temperature information for a patient. I'm looking for suggestions on how to improve the code that I have. Although what I have compiles and does what I want, I wonder if there is anything methodology I'm using inappropriately despite it still working.
Some particular areas I worry about are redundant code and my use of the conversion and fever methods (you can ignore the clearly bad math. I just wanted any calculation until I determined functionality).
Temperature.hpp:
#ifndef Temperature_h
#define Temperature_h
#include <iostream>
#include <string>
using namespace std;
class Temperature {
private:
string newPatient;
float newTemp;
char newDegree;
public:
enum TempMethod {oral, arm, leg, bum};
Temperature();
Temperature(string, float, char);
~Temperature();
string getPatient() const;
float getTemp() const;
char getDegree() const;
float setFaren();
float setCels();
void hasFever();
};
#endif /* Temperature_h */
Temperature.cpp:
Temperature::Temperature(string patient, float temp, char degree){
newPatient = patient;
newTemp = temp;
newDegree = degree;
}
Temperature::~Temperature(){
}
string Temperature::getPatient() const{
return newPatient;
}
float Temperature::getTemp() const{
return newTemp;
}
char Temperature::getDegree() const{
return newDegree;
}
float Temperature::setFaren(){
float faren = newTemp+32;
return faren;
}
float Temperature::setCels(){
float celsi = newTemp-32;
return celsi;
}
void Temperature::hasFever(){
if(newTemp >= 100.4){
cout << "Patient " << newPatient << " has a fever!!\n";
}
}
main.cpp:
#include <iostream>
#include <string>
#include "Temperature.h"
using namespace std;
int main() {
string patient;
float temp;
float celsius;
float farenheit;
char degree;
cout << "Enter Patient Name: ";
getline(cin, patient);
cout << "Enter the tempature: ";
cin >> temp;
cout << "Enter degree method (F or C): ";
cin >> degree;
Temperature Temp_1(patient, temp, degree);
cout << "\nPatient Name: " << Temp_1.getPatient() << endl <<
"Temperature: " << Temp_1.getTemp() << " degrees " << Temp_1.getDegree() << endl;
if(Temp_1.getDegree() == 'F'){
celsius = Temp_1.setCels();
cout << "Temperate in Celsius: " << celsius << " degrees Celsius" << endl;
}
else if(Temp_1.getDegree() == 'C'){
farenheit = Temp_1.setFaren();
cout << "Temperature in Farenheit: " << farenheit << " degrees Farenheit" << endl;
}
Temp_1.hasFever();
return 0;
}