Please help me with my weather program!

October 30, 2010 at 16:45:34
Specs: Windows Vista
My Professor gave me a weather data structure to reformat. Where would I even begin? It seems so confusing..

How would I start this?

First, there is a new data structure to represent the information that comes from each weather station:

struct WeatherStation {

string StationDesignation;

double Temperature;

};

Your new program will need to store this information in an array of WeatherStation objects, and you will have to supply functions to allow the user to

post the temperatures that come in from the various weather stations

display the temperatures in both fahrenheit and celsius for each weather station

calculate and display the highest temperature as well as the lowest among the five stations.

In addition, you need to design and implement a reasonable user interface (NOT A GUI!). Study the sample screens below to gain insight into what the program is expected to do...

Choices...................

---------------------------

Post Temperatures

Daily Report

High-Low Report

Quit

---------------------------

Enter Command:

-------------------------------------------------

Choices...................

---------------------------

Post Temperatures

Daily Report

High-Low Report

Quit

---------------------------

Enter Command: Post Temperatures

Enter reported temperatures...

Weather Station Big Basin: 55

Weather Station Foothill: 56

Weather Station DeAnza: 55

Weather Station MiddleField: 44

Weather Station Redwood City: 57

Enter Command: Daily Report

NGS Daily Temperature Report

Fahrenheit Celsius

Weather Station Big Basin : 55.0 12.8

Weather Station Foothill : 56.0 13.3

Weather Station DeAnza : 55.0 12.8

Weather Station MiddleField : 44.0 6.67

Weather Station Redwood City: 57.0 13.9

Mean Temperature: 66.8 19.3

Enter Command: High-Low Report

Fahrenheit Celsius

Lowest Temperature: 44.0 6.67

Highest Temperature: 57.0 13.9


See More: Please help me with my weather program!

Report •

#1
November 9, 2010 at 21:40:36
Ok first I am a beginner in c++, but i start with the class (design) book i mean OOP
so i think :
1 - you can write a class include the data you need to work on like the ( struct
WeatherStation ) and the name of the city and the variables for the
temperatures.
2- after that you can write a very simple code for the program you want.
by using the data and the objects ( functions in the class that work only on the
class data)
3- you can also write two functions to convert from C to F .

i am sorry i am just a new i can't help you more


Report •

#2
November 15, 2010 at 08:10:28
#include <iostream.h>
#include <string.h>

struct WeatherStation
{
char StationDesignation[100];
double Farenheit;
double Celsius;
};


void Choices(WeatherStation stations[]);
void PostTemperature(WeatherStation stations[]);
void DailyReport(WeatherStation stations[]);
void FarenheitToCelsius(WeatherStation stations[]);
void H_LTempReport(WeatherStation stations[]);

int main()
{
WeatherStation stations[5];
Choices(stations);
return 0;
}

void H_LTempReport(WeatherStation stations[])
{
WeatherStation LowestStat = stations[0];
WeatherStation HighestStat = stations[0];

//.....................................................
for (int i = 1; i <= 4; i++)
{
if ( LowestStat.Farenheit > stations[i].Farenheit )
LowestStat = stations[i];
}
//......................................................

//......................................................
for (int i = 1; i <= 4; i++)
{
if ( HighestStat.Farenheit < stations[i].Farenheit )
HighestStat = stations[i];
}
//........................................................

cout << endl << "Farenheight Celsius";
cout << endl << "Lowest Temperature: " << LowestStat.Farenheit << " " << HighestStat.Celsius;
cout << endl << "Highest Temperature: " << HighestStat.Farenheit << " " << HighestStat.Celsius;

//............................................................................................
}

void Choices(WeatherStation stations[])
{
char str[100];
char ch;

while ( true )
{
cout << endl << "Choices................";
cout << endl << "------------------------------";
cout << endl << "Post Temperatures";
cout << endl << "Daily Report";
cout << endl << "High-Low Report";
cout << endl << "Quit";
cout << endl << "--------------------------------";
cout << endl << "Enter Command: ";
cin.get( str, 99 );
cin.get(ch);

if ( ( strcmpi("Post Temperatures", str) == 0 ) )
{
PostTemperature(stations);
cout << endl;
}

if ( ( strcmpi("Daily Report", str) == 0 ) )
DailyReport(stations);

if ( ( strcmpi("High-Low Report", str) == 0 ) )
H_LTempReport(stations);

if ( ( strcmpi("Quit", str) == 0 ) )
break;
}
}

void PostTemperature(WeatherStation stations[])
{
strcpy(stations[0].StationDesignation, "Weather Station Big Basin: ");
strcpy(stations[1].StationDesignation, "Weather Station Foothill: ");
strcpy(stations[2].StationDesignation, "Weather Station DeAnza: ");
strcpy(stations[3].StationDesignation, "Weather Station MiddleField: ");
strcpy(stations[4].StationDesignation, "Weather Station Redwood City: ");
//.................................................................

cout << endl << "Enter reported temperatures......";

for (int i = 0; i <= 4; i++)
{
cout << endl << stations[i].StationDesignation;
cin >> stations[i].Farenheit;
}

FarenheitToCelsius(stations);

}

void FarenheitToCelsius(WeatherStation stations[])
{
for (int i = 0; i <= 4; i++)
{
stations[i].Celsius = ( 5.0 / 9.0 ) * ( stations[i].Farenheit - 32.0 );
}
}

void DailyReport(WeatherStation stations[])
{
cout << endl << "NGS Daily Temperature Report";
cout << endl << "Farenheit Celsius";
//..............................................

for (int i = 0; i <= 4; i++)
{
cout << endl << stations[i].StationDesignation << stations[i].Farenheit
<< " " << stations[i].Celsius;
}
}


........................................................................................................................
_Adnan_


Report •

#3
November 16, 2010 at 14:57:28
this is 2 functions to convert from C to F or from F to C, its the same of above, its but more simple you can use the idea in any program u wanna write it.

float far_to_cel(int f)
{
float c =(f-32) * 0.555;
return c;
}


float cel_to_far(int c)
{
float f =(1.8 * c) + 32;
return f;
}


Report •
Related Solutions


Ask Question