File -- > Temperature.h
#pragma once
class Temperature {
public: // Programmer Interface (programmer can access/use these).
Temperature (void); // Default constructor.
void setTemperature (int); // Sets the temperature value.
int getTemperature (void); // Returns the temperature value.
// Returs true if the condition matches or else false.
bool isEthylFreezing (int);
bool isEthylBoiling (int);
bool isOxygenFreezing (int);
bool isOxygenBoiling (int);
bool isWaterFreezing (int);
bool isWaterBoiling (int);
~Temperature (void); // Destructor.
private: // Data members not accessible by programmer.
int elementTemp;
};
File --> Temperature.cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "Temperature.h"
using namespace std;
//---------------------------------------------------------------------------
// Named Constants
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Define member functions for class Temperature.
Temperature::Temperature (void) { // Default constructor.
elementTemp = 0; // Setting temperature defined by class to 0.
}
//---------------------------------------------------------------------------
void Temperature::setTemperature (int programmerInput) {
elementTemp = programmerInput; // Setting programmer input to class temperature.
}
//------------------------------------------------------------------------------
int Temperature::getTemperature (void) {
return elementTemp; // Returning to new value.
}
//------------------------------------------------------------------------------
bool Temperature::isEthylFreezing(int programmerInput) {
// Checking the input from the programmer is true or false.
bool Result = false;
if (programmerInput <= -173) {
Result = true;
}
return Result;
}
//------------------------------------------------------------------------------
bool Temperature::isEthylBoiling(int programmerInput) {
bool Result = false;
if (programmerInput >= 172) {
Result = true;
}
return Result;
}
//------------------------------------------------------------------------------
bool Temperature::isOxygenFreezing(int programmerInput) {
bool Result = false;
if (programmerInput <= -362) {
Result = true;
}
return Result;
}
//------------------------------------------------------------------------------
bool Temperature::isOxygenBoiling(int programmerInput) {
bool Result = false;
if (programmerInput >= -306) {
Result = true;
}
return Result;
}
//------------------------------------------------------------------------------
bool Temperature::isWaterFreezing(int programmerInput) {
bool Result = false;
if (programmerInput <= 32) {
Result = true;
}
return Result;
}
//------------------------------------------------------------------------------
bool Temperature::isWaterBoiling(int programmerInput) {
bool Result = false;
if (programmerInput >= 212) {
Result = true;
}
return Result;
}
//---------------------------------------------------------------------------
Temperature::~Temperature (void) { // Destructor.
}
//---------------------------------------------------------------------------
#pragma once
class Temperature {
public: // Programmer Interface (programmer can access/use these).
Temperature (void); // Default constructor.
void setTemperature (int); // Sets the temperature value.
int getTemperature (void); // Returns the temperature value.
// Returs true if the condition matches or else false.
bool isEthylFreezing (int);
bool isEthylBoiling (int);
bool isOxygenFreezing (int);
bool isOxygenBoiling (int);
bool isWaterFreezing (int);
bool isWaterBoiling (int);
~Temperature (void); // Destructor.
private: // Data members not accessible by programmer.
int elementTemp;
};
File --> Temperature.cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "Temperature.h"
using namespace std;
//---------------------------------------------------------------------------
// Named Constants
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Define member functions for class Temperature.
Temperature::Temperature (void) { // Default constructor.
elementTemp = 0; // Setting temperature defined by class to 0.
}
//---------------------------------------------------------------------------
void Temperature::setTemperature (int programmerInput) {
elementTemp = programmerInput; // Setting programmer input to class temperature.
}
//------------------------------------------------------------------------------
int Temperature::getTemperature (void) {
return elementTemp; // Returning to new value.
}
//------------------------------------------------------------------------------
bool Temperature::isEthylFreezing(int programmerInput) {
// Checking the input from the programmer is true or false.
bool Result = false;
if (programmerInput <= -173) {
Result = true;
}
return Result;
}
//------------------------------------------------------------------------------
bool Temperature::isEthylBoiling(int programmerInput) {
bool Result = false;
if (programmerInput >= 172) {
Result = true;
}
return Result;
}
//------------------------------------------------------------------------------
bool Temperature::isOxygenFreezing(int programmerInput) {
bool Result = false;
if (programmerInput <= -362) {
Result = true;
}
return Result;
}
//------------------------------------------------------------------------------
bool Temperature::isOxygenBoiling(int programmerInput) {
bool Result = false;
if (programmerInput >= -306) {
Result = true;
}
return Result;
}
//------------------------------------------------------------------------------
bool Temperature::isWaterFreezing(int programmerInput) {
bool Result = false;
if (programmerInput <= 32) {
Result = true;
}
return Result;
}
//------------------------------------------------------------------------------
bool Temperature::isWaterBoiling(int programmerInput) {
bool Result = false;
if (programmerInput >= 212) {
Result = true;
}
return Result;
}
//---------------------------------------------------------------------------
Temperature::~Temperature (void) { // Destructor.
}
//---------------------------------------------------------------------------
File --> Main.
// Programming Environment: Bloodshed
// Program Description:
// This is a simple program to demonstrate the use of class. The program asks the
// user to enter a temperature and it displays a list of substance that will
// freeze at that temperature and those that will boil at that temperature.
// It uses simple class with default constructor to perform the operation.
//------------------------------------------------------------------------------
// Date/Time: 5/12/2010 12:48:14 AM
//------------------------------------------------------------------------------
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "extras.h"
#include "Temperature.h"
using namespace std;
//---------------------------------------------------------------------------
// Named Constants
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Structure Declarations
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Function Prototypes
//---------------------------------------------------------------------------
bool Do_Again (void);
//---------------------------------------------------------------------------
int main (void) {
cout.setf (ios::fixed, ios::floatfield);
cout.setf (ios::showpoint);
cout.precision (2);
do {
int elementTemperature;
cout << endl << "FREEZING AND BOILING POINTS OF ELEMENTS";
cout << endl << "---------------------------------------";
cout << endl << endl << "Enter TEMPERATURE: ";
cin >> elementTemperature;
Temperature Elements; // Creating object of Temperature class.
// Setting the temperature to user's entered temperature.
Elements.setTemperature(elementTemperature);
cout << endl << "----------------------------------------------";
cout << endl << "Properties of Elements @ " << Elements.getTemperature()
<< " Degrees Fahrenheit";
cout << endl << "----------------------------------------------";
// Using if statement to figure out of validity of each methods and
// displaying it if it matches the condition.
if (Elements.isEthylFreezing(elementTemperature)) {
cout << endl << "ETHYL ALCOHOL WILL FREEZE.";
}
if (Elements.isEthylBoiling(elementTemperature)) {
cout << endl << "ETHYL ALCOHOL WILL BOIL.";
}
if (Elements.isOxygenFreezing(elementTemperature)) {
cout << endl << "OXYGEN WILL FREEZE.";
}
if (Elements.isOxygenBoiling(elementTemperature)) {
cout << endl << "OXYGEN WILL BOIL.";
}
if (Elements.isWaterFreezing(elementTemperature)) {
cout << endl << "WATER WILL FREEZE.";
}
if (Elements.isWaterBoiling(elementTemperature)) {
cout << endl << "WATER WILL BOIL.";
}
} while (Do_Again ());
return 0;
}
//------------------------------------------------------------------------
// Function Definitions
//------------------------------------------------------------------------
bool Do_Again (void) {
(void) fflush (stdin);
cout << endl << endl << "\aDo Again? (y/n): ";
return static_cast(tolower (_getch ())) == 'y';
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.