help w/ single inheritence?

August 2, 2009 at 18:02:02
Specs: Windows XP
hi i was wondering if anyone could possibly help me or give me some suggestions on how to change from a program WITHOUT inheritance to one WITH single inheritance.
ive written the program here without already and with the first part of the pollencounter class but am stumped as how to dervive it. Its supposed to be weatherstation:public pollencounter
but with an array, im completely confused as how to do so.
ANY help at all would be taken so gratefully!

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

class PollenCounter
{
public:
//constructor+destructor
PollenCounter(){}
~PollenCounter(){}

//accessors
double GetHighCount() {return HighCount;}
void SetHighCount(double High) {HighCount = High;}
double GetLowCount() {return LowCount;}
void SetLowCount(double Low) {LowCount = Low;}

//Other Method
void AverageCount(double AverageCount)
{
AverageCount = (HighCount+LowCount)/2;
}
protected:
double HighCount;
double LowCount;
};

class WeatherStation
{
string StationDesignation;
string StationAgent;
double Temperature;
double HighCount;
double LowCount;
double AverageCount;
//defines a class that represents a single weather stations
public:
WeatherStation() { ; }

WeatherStation(string ID, string Agent, double Degree, double High, double Low, double Average)
{
StationDesignation = ID;
StationAgent = Agent;
Temperature = Degree;
HighCount = High;
LowCount = Low;
AverageCount = Average;
}
void SetDesignation(string ID) { StationDesignation = ID; }
void SetAgent(string Agent) { StationAgent = Agent; }
void SetTemperature(double Degree) { Temperature = Degree; }
void SetHighCount(double High) { HighCount = High; }
void SetLowCount(double Low) { LowCount = Low; }
void SetAverageCount(double Average){ AverageCount = Average; }
//mutators

string GetDesignation() { return StationDesignation; }
string GetAgent() { return StationAgent; }
double GetTemperature() { return Temperature; }
double GetHighCount() { return HighCount; }
double GetLowCount() { return LowCount; }
double GetAverageCount() { return AverageCount; }
//accessors
};

void MainMenu();
int AddStations(WeatherStation[]);
void PostStationInfo(WeatherStation[], int);
void DailyPollenCounter(WeatherStation[], int);
//declaring functions
const int MAXSIZE = 100;
//declaring a constant maximum value of weather stations

/*************************************************************************************/
int main()//main program
{
WeatherStation StationList[MAXSIZE];
string Command;
int Number_Station=0;

for( ; ; ) //using a for loop to respond to users input/command
{
MainMenu();
cout << "Enter Command: ";
getline(cin, Command);
if(Command == "Quit")
break;
else if(Command == "Add Stations")
Number_Station = AddStations(StationList);
else if(Command == "Post Station Info")
PostStationInfo(StationList, Number_Station);
else if (Command == "Daily Pollen Count")
DailyPollenCounter(StationList,Number_Station);
}
return 0;
}

/*************************************************************************************/
void MainMenu() //defining the main menu and what choices the user has to pick from
{
cout << "\nMain Menu\n\n";
cout << "Choices.........\n";
cout << "--------------------\n";
cout << "Add Stations\n";
cout << "Post Station Info\n";
cout << "Daily Pollen Count\n";
cout << "Quit\n";
cout << "---------------------\n\n";
}

/*************************************************************************************/

int AddStations(WeatherStation StationList[])//defining the function for adding stations and both naming them and their contact person
{
string ID, Agent;
int i;
cout << "\n****** Enter Station Information Below. Enter 'Stop' To Quit ******" << endl;
for(i = 0 ; i < MAXSIZE ; i++)
{
cout << "\nEnter Station Designation: ";
getline(cin, ID);//reads an entire line of input from the user
if (ID == "Stop")
break;
cout << "Enter Contact Person: ";
getline(cin, Agent);

StationList[i].SetDesignation(ID);//storing information
StationList[i].SetAgent(Agent);
}
return i;
}

/*************************************************************************************/
void PostStationInfo(WeatherStation StationList[], int Size)// defining the function that takes user's inputed temperatures and stores them in an array
{
double Degree, HighCount, LowCount, High, Low;
cout << "\n\nPlease enter temperature in Farenheits \n\n";
for (int i=0; i < Size; i++)
{
cout << "Weather Station "<<StationList[i].GetDesignation() <<": \n"; //calling back stored numbers
cout << "Weather Agent "<<StationList[i].GetAgent() <<": \n";
cout << "Temperature: ";
cin >> Degree; //get input of temperature from user
StationList[i].SetTemperature(Degree); //storing data
cout << "Pollen Count:\n\tHigh:";
cin >> High;
StationList[i].SetHighCount(High);
cout << "\tLow:";
cin >> Low;
StationList[i].SetLowCount(Low);
cin.ignore(100, '\n'); //Clear Buffer
}
}

/*************************************************************************************/
void DailyPollenCounter(WeatherStation StationList[], int Size)
{
double High;
double Low;
int i;

for (int i=0; i < Size; i++)
{
double Average;
Average = (StationList[i].GetHighCount()+StationList[i].GetLowCount())/2;
StationList[i].SetAverageCount(Average);

}
for (int i=0; i < Size; i++)
{
cout << setiosflags (ios::showpoint) << setprecision (3)<< setprecision(3);
cout << "Weather Station: "<<StationList[i].GetDesignation()<<" \t " <<StationList[i].GetAverageCount()<<"\n";
}
}


See More: help w/ single inheritence?

Report •


#1
August 5, 2009 at 06:53:14
You want what to inherit what, now?

Report •
Related Solutions


Ask Question