So I made a class with an array with a bunch of numbers. I want to know how I can add up all those numbers and get an average for them.
#include <iostream>
#include <string>
using namespace std;
class WeatherStation
{
string StationDesignation; //Identifies the station
string StationAgent; //Who's responsible
double Temperature; //The temperature
public:
//Define some mutators...These member functions allow us to
//change values in the object...
void SetDesignation(string ID) { StationDesignation = ID; }
void SetAgent(string Agent) { StationAgent = Agent; }
void SetTemperature(double Degree) {Temperature = Degree; }
//Define some accessors...These member functions allow us to get
// at the internal values
string GetDesignation() { return StationDesignation; }
string GetAgent() { return StationAgent; }
double GetTemperature() { return Temperature; }
//Define a displayer...this will show the contents of the object
// in an easy to read format..
void Show()
{
cout << StationDesignation << endl;
cout << StationAgent << endl;
}
void ShowTemp()
{
cout << StationDesignation << " : " << Temperature << endl;
cout << "------------------------------------------------" << endl;
}
};
//Functions
void Menu();
int AddStation(WeatherStation[],int);
void PostTemperatures(WeatherStation*, int);
void DailyReport(WeatherStation*, int);
int main()
{
string Command;
WeatherStation names[25];
int Size =0;
while (true){
Menu();
cout << "Enter Command: " ;
getline (cin,Command);
cout << endl;
cout << endl;
if (Command == "Quit")
break;
else if (Command == "Add Stations")
Size = Size + AddStation(names,25);
else if (Command == "Post Temperatures")
PostTemperatures (names,Size);
else if (Command == "Daily Report")
DailyReport (names, Size);
else if (Command == "High-Low Report")
cout << "High-Low Report" << endl;
}
}
int AddStation(WeatherStation List[], int MaxSize)
{
string ID, Agent;
int K;
cout << "Enter Station Information Below, Stop to Quit" << endl;
for (K=0 ; K<MaxSize ; K++) {
cout << "Enter Weather Station Designation: " ;
getline(cin, ID);
if (ID == "Stop")
break;
cout << "Enter Contact Person: " ;
getline(cin,Agent);
if (Agent == "Stop")
break;
List[K].SetDesignation(ID);
List[K].SetAgent(Agent);
}
return K;
}
void Menu() //The Menu
{
cout << "=========== Menu ===========" << endl;
cout << "==== Choices: ==============" << endl;
cout << "Add Stations" << endl;
cout << "Post Temperatures" << endl;
cout << "Daily Report" << endl;
cout << "High-Low Report" << endl;
cout << "Quit" << endl;
cout << "==============================" << endl;
}
void PostTemperatures(WeatherStation* List, int Size)
{
int K;
int Degree;
cout << "Enter Reported Temperatures.." << endl;
for (K=0 ; K<Size ; K++){
List[K].Show();
cout << "Enter Temperature: ";
cin>>Degree;
List[K].SetTemperature(Degree);
}
}
void DailyReport (WeatherStation* List, int Size)
{
int K;
cout << "NGS Daily Temperature Report" << endl;
cout << "================================================" << endl;
cout << " Fahrenheit Celsius" << endl;
cout << "------------------------------------------------" << endl;
for (K=0 ; K<Size ; K++){
List[K].ShowTemp();
//GET THE AVERAGE OF ALL THE TEMPERATURE, RIGHT HERE SOME HOW
}
}
Also if you guys can explain the * in void DailyReport (WeatherStation* List, int Size) and what it does. I'm kinda confused.