help! program w/o class into one w/classes?

July 24, 2009 at 16:30:53
Specs: Windows XP
was wondering if anyone could give me some hints on how to change a program from just a main program with sub programs into one with object oriented design paradigm/classes.
i can write the program without the object oriented design fine, but then i come up with a whole bunch of errors when trying to switch them.

This was my original program
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

struct WeatherStation {
string StationDesignation;
double Temperature;
string Agent;
} Station[5];


void PostTemperature();
void AddStations();
int MainMenu();

/*************************************************************************************/
int main()
{
int option=0, flag=0;
cout << "Welcome to the newly revised Not So Global (NSG) Weather Service\n";

while (option < 1000)
{
option = MainMenu();
if (option==1)
{
AddStations();
flag=1;
}
if (option==2 & flag==1)
PostTemperature();
if (option==3)
option = 1000;
}

char response;
cout << "\n\nType any key to exit ......";
cin >> response;

return 0;
}


/************************************************************/
void AddStations()
{
int i;
cout << "Enter Station Information Below, Stop To Quit. \nPlease leave out spaces between words\n";
cout << "----------------------------------\n";
for (int i=0; i<5; i++)
{
cout << "Enter Weather Station Designation: ";
cin >> Station[i].StationDesignation;
cout << "\nEnter Contact Person: ";
cin >> Station[i].Agent;
cout << "\n----------------------------------\n";
cout << "----------------------------------\n";

}
}

/*************************************************************************************/
void PostTemperature()
{
cout << "\n\nPlease enter temperatures in Farenheits \n\n";
for (int i=0; i<5; i++)
{
cout << Station[i].StationDesignation <<"\n" <<Station[i].Agent<<"\n";

cin >> Station[i].Temperature;

cout << "\n";

}
}
int MainMenu()
{
int option;

cout << "\nMain Menu\n\n";
cout << "Choices.........\n";
cout << "--------------------\n";
cout << "1: Add Stations\n";
cout << "2: Post Temperatures\n";
cout << "3: Quit\n";
cout << "---------------------\n\n";
cout << "Please enter option number (1, 2, or 3): ";

cin >> option;
return (option);
}

and this is the one im working on but im getting a whole bunch of errors
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

class WeatherStation {
string StationDesignation;
string StationAgent;
double Temperature;
public:
void SetDesignation(string ID)
{
StationDesignation = ID;
}
void SetAgent(string Agent)
{
StationAgent = Agent;
}
void SetTemperature(double Degree)
{
Temperature = Degree;
}
string GetDesignation()
{
return StationDesignation;
}
string GetAgent()
{
return StationAgent;
}
double GetTemperature()
{
return Temperature;
}
void Displayer();
};


void WeatherStation::Displayer()
{
cout << "--------------------------------------" << endl;
cout << "Station:\t "
cin >> StationDesignation;
cout << "\nAgent:\t "
cin >> StationAgent;
cout << "\nCurrent Temperature: "
cin >> Temperature;
cout << "\n--------------------------------------\n";
}

int MainMenu()
{
int option;

cout << "\nMain Menu\n\n";
cout << "Choices.........\n";
cout << "--------------------\n";
cout << "1: Add Stations\n";
cout << "2: Post Temperatures\n";
cout << "3: Quit\n";
cout << "---------------------\n\n";
cout << "Please enter option number (1, 2, or 3): ";

cin >> option;
return (option);
}

int main()
{
int option=0, flag=0;

while (option < 1000)
{
option = MainMenu();
if (option==1)
{
cout << WeatherStation.Displayer();
flag=1;
}
}

char response;
cout << "\n\nType any key to exit ......";
cin >> response;

return 0;
}


if you could perhaps give some tips that would be wonderful!
thanks!


See More: help! program w/o class into one w/classes?

Report •


#1
July 24, 2009 at 16:45:22
i come up with a whole bunch of errors
Such as?

Report •

#2
July 24, 2009 at 16:56:09
implicit declaration of function : weather display
new declaration ambiguates old declaration

Report •

#3
July 28, 2009 at 01:43:30
There is no function called "weather display". Your error
message must have been something else.

Looking at your code, you seem to have got a bit confused
about what you're trying to do. You've defined class
WeatherStation, then you've defined the member function
Displayer(), which is a misleading name because it doesn't
just display. You haven't made Displayer a static function, so
it has to act on a specific instance. Yet you are calling it as
WeatherStation.Displayer(). You need to create an instance
to call Displayer() on, not just the class name. Also,
Displayer() returns void, yet you are passing it to cout. Those
are just some of the problems.


Report •

Related Solutions

#4
July 28, 2009 at 07:48:47
thanks!

Report •


Ask Question