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

July 23, 2009 at 23:26:30
Specs: Windows XP
i 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 15:36:56
Try the 'Programming' forum.

Report •
Related Solutions


Ask Question