// This is the IMPLEMENTATION FILE: templist.C. for the class
// TemperatureList. The interface for this class is in the file
// templist.h.
#include "templist.h"
#include <iostream>
using namespace std;
// Initializes the object to an empty list.
TemperatureList::TemperatureList(void)
{
size = 0;
}
// Precondition: The list is not full.
// Postcondition: The temperature has been added to the END of the list,
// if there was room.
void TemperatureList::add_temperature(double temperature)
{
if (!full())
{
list[size++] = temperature;
}
return;
}
// Returns true if the list is full, false otherwise.
bool TemperatureList::full(void) const
{
return (size == MAX_LIST_SIZE);
}
// Precondition: If outs is a file output stream, then outs has
// already been connected to a file.
// Postcondition: Temperatures are output one per line on the stream.
void TemperatureList::output(ostream & outs) const
{
long i;
for (i = 0; i < size; i++)
{
outs << list[i] << " F\n";
}
return;
}
// Returns the number of temperatures on the list.
long TemperatureList::get_size(void) const
{
return size;
}
// Precondition: 0 <= position < get_size()
// Returns the temperature that was added in position
// specified. The first temperature that was added is
// in position 0.
double TemperatureList::get_temperature(long position) const
{
return ( (position >= size) ||
(position < 0) )
? (0.0) : (list[position]);
}
Note: This project is adapted from ones given in textbooks by Walter Savitch.