Computing.Net > Forums > Programming > help! program w/o class into one w/classes?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

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

Reply to Message Icon

Name: rebelswimmer290
Date: July 24, 2009 at 16:30:53 Pacific
OS: Windows XP
Subcategory: C/C++
Comment:

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!



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: July 24, 2009 at 16:45:22 Pacific
Reply:

i come up with a whole bunch of errors
Such as?


0

Response Number 2
Name: rebelswimmer290
Date: July 24, 2009 at 16:56:09 Pacific
Reply:

implicit declaration of function : weather display
new declaration ambiguates old declaration


0

Response Number 3
Name: klint
Date: July 28, 2009 at 01:43:30 Pacific
Reply:

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.


0

Response Number 4
Name: rebelswimmer290
Date: July 28, 2009 at 07:48:47 Pacific
Reply:

thanks!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: help! program w/o class into one w/classes?

combine two files into one file www.computing.net/answers/programming/combine-two-files-into-one-file/17093.html

how to combine two strings into one www.computing.net/answers/programming/how-to-combine-two-strings-into-one/800.html

Replace Underlines with spaces www.computing.net/answers/programming/replace-underlines-with-spaces-/16420.html