Weather Program

I included my original code down below....Basically I need some input on where to start off. From what I can tell it seems that I will need to re-organize the code into functions, while implementing the new data structure. For starters how would I implement the new data structure? Would I need to get rid of the original arrays? Sorry I'm a beginner, so any help would be greatly appreciated.

--Thanks..



This time the program would be written using functions instead of putting all the code in main(). You need to rewrite the software from Lab 02 so that it effects these changes.

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



========NGS Temperature Data Report========

Fahrenheit Celsius

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

Lowest Temperature: 44.0 6.67

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

Highest Temperature: 57.0 13.9

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

========End Temperature Data Report========

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include<iostream>
#include<string>

using namespace std;

int main()

{
	
	int i(0);
	
	double Calc(double fahren);
	
	double Total(0),Celsius[5],Fahrenheit[5]; 
	
	double CelsiusLowTemperature(0), FahrenheitLowTemperature(1000), 
	
	CelsiusHighTemperature(0), 
	
	FahrenheitHighTemperature(-1000);
	
	double Mean_Celsius, Mean_Fahrenheit;
	
	
	cout<< "Enter reported temperatures..."<<"\n"<< "\n";
	
	
	for(i=0;i<5;i++) //Loops
		
{
		
	cout<<"Weather Station "<<i+1<<" = ";// Takes input for Reported Temperatures For Weather Stations...
	cin>>Fahrenheit[i];
		
		
	if(Fahrenheit[i]<FahrenheitLowTemperature) // Conditionals  
			
            FahrenheitLowTemperature=Fahrenheit[i];
		
		
	if(Fahrenheit[i]>FahrenheitHighTemperature)
			
            FahrenheitHighTemperature=Fahrenheit[i];
		
		
	Celsius[i] = Calc(Fahrenheit[i]);
		
		
	Total+=Fahrenheit[i]; 
		
}
	
	CelsiusLowTemperature = Calc(FahrenheitLowTemperature);
	
	CelsiusHighTemperature = Calc(FahrenheitHighTemperature);
	
	Mean_Fahrenheit = Total/5.0; // Calculates the mean for Fahrenheit
	
	Mean_Celsius = Calc(Mean_Fahrenheit); // Calculates the mean for Celsius
	
	
	cout.precision(3);
	
	cout<<" ========NGS Temperature Data Report======== "<<endl; 
	
	cout<<"                      Fahrenheit       Celsius                          "<<endl;
	
	cout<<" --------------------------------------------------------------"<<endl;
	
	cout<<"Lowest Temperature:     "<<FahrenheitLowTemperature<<"         "<<CelsiusLowTemperature<<endl;
	
	cout<<" --------------------------------------------------------------"<<endl;
	
	cout<<"Highest Temperature:    "<<FahrenheitHighTemperature<<"               "<<CelsiusHighTemperature<<endl;
	
	cout<<" --------------------------------------------------------------"<<endl;
	
	cout<<"Mean Temperature:       "<<Mean_Fahrenheit<<"          "<<Mean_Celsius<<endl;
	
	cout<<" --------------------------------------------------------------"<<endl;
	
	cout<<"Raw Data..."<<endl;
	
	cout<<"\n";
	
	// Outputs Data that include the following: Fahrenheit Low and High, Celsius Low and High and Mean...
	
	
	for(i=0;i<5;i++) // Loops
		
{ 
		
	cout.precision(3);
		
	cout<<"WeatherStation "<< i <<" =     "<<Fahrenheit[i]<<"            "<<Celsius[i]<<endl;
		
}
	
	cout<<" --------------------------------------------------------------"<<endl;
	
	cout<<" =============End Temperature Data Report============="<<endl;
	
}

double Calc(double fah)  

{
	
	double cel; // Converts Fahrenheit to Celsius
	
	cel = (5 *(fah - 32))/9.0;
	
	return cel;
	
}
Here is what I have done in the past hour. I want to eventually pass if-else statements to process incoming commands; is that the route that I should take? And again how can I go by implementing the new data structure into the my current code?

No error codes at the moment.

--Thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include<iostream>
#include<string>
using namespace std;

struct WeatherStation  {
	
	string StationDesignation;
	
	double Temperature;
	
};

int i(0);
double Calc(double fahren);
double Total(0),Celsius[5],Fahrenheit[5];  
double CelsiusLowTemperature(0), FahrenheitLowTemperature(1000), 
CelsiusHighTemperature(0), 
FahrenheitHighTemperature(-1000);
double Mean_Celsius, Mean_Fahrenheit;

void ShowList()
{
	
	cout<<"Command Choices................"<<"\n"<<endl;
	cout<<"_____________________________"<<"\n"<<endl;
	cout<<"\t"<<"Post Temperatures" <<"\n"<<endl;
	cout<<"\t"<<"Daily Report" <<"\n"<<endl;
	cout<<"\t"<<"High-Low Report" <<"\n" <<endl;
	cout<<"\t"<<"Quit" <<"\n"<<endl;
	cout<<"_____________________________"<<"\n"<<endl;

}	

void PostTemperatures()
{
	cout<< "Please enter reported temperatures..."<<"\n"<< "\n";
	cout<< "Weather Station Big Basin: "; 
	cin>>Fahrenheit[i];
	cout<< "Weather Station Foothill: "; 
	cin>>Fahrenheit[i];
	cout<< "Weather Station DeAnza: ";
	cin>>Fahrenheit[i];
	cout<< "Weather Station MiddleField: ";
	cin>>Fahrenheit[i];
	cout<< "Weather Station Redwood City: ";
	cin>>Fahrenheit[i];
	cout<<"\n"<<"\n"
	<<"----------------------------------------------"<<endl;
}

void DailyReport()
{
	cout<<"\t"<< "NGS Daily Temperature Report"<<endl;
	cout<<"================================================="<<endl;
	cout<<"                      Fahrenheit       Celsius                          "<<endl;
	cout<<" --------------------------------------------------------------"<<endl;
	
}

void HighLowReport()
{
	cout<< "===========NGS Temperature Data Report========="<<endl;
	//cout<<"Lowest Temperature:     "<<FahrenheitLowTemperature<<"         "<<CelsiusLowTemperature<<endl;
	cout<<" --------------------------------------------------------------"<<endl;
	//cout<<"Highest Temperature:    "<<FahrenheitHighTemperature<<"               "<<CelsiusHighTemperature<<endl;
	cout<<" --------------------------------------------------------------"<<endl;
	
}

void Quit()
{
	cout<<"===============End Temperature Data Report============="<<endl;
}

	
 int main()
{
	ShowList();
	PostTemperatures();
	
	for(i=0;i<5;i++) //Loops
		
	{
		
		cout<<"Weather Station "<<i+1<<" = ";// Takes input for Reported Temperatures For Weather Stations...
		
		cin>>Fahrenheit[i];
		
		if(Fahrenheit[i]<FahrenheitLowTemperature) // Conditionals  
			
            FahrenheitLowTemperature=Fahrenheit[i];
		
		if(Fahrenheit[i]>FahrenheitHighTemperature)
			
            FahrenheitHighTemperature=Fahrenheit[i];
		
		Celsius[i] = Calc(Fahrenheit[i]);
		
		Total+=Fahrenheit[i]; 
		
	}
	
	CelsiusLowTemperature = Calc(FahrenheitLowTemperature);
	
	CelsiusHighTemperature = Calc(FahrenheitHighTemperature);
	
	Mean_Fahrenheit = Total/5.0; // Calculates the mean for Fahrenheit
	
	Mean_Celsius = Calc(Mean_Fahrenheit); // Calculates the mean for Celsius
	
	
	
	cout.precision(3);
	
	cout<<" ========NGS Temperature Data Report======== "<<endl; 
	cout<<"                      Fahrenheit       Celsius                          "<<endl;
	cout<<" --------------------------------------------------------------"<<endl;
	cout<<"Lowest Temperature:     "<<FahrenheitLowTemperature<<"         "<<CelsiusLowTemperature<<endl;
	cout<<" --------------------------------------------------------------"<<endl;
	cout<<"Highest Temperature:    "<<FahrenheitHighTemperature<<"               "<<CelsiusHighTemperature<<endl;
	cout<<" --------------------------------------------------------------"<<endl;
	cout<<"Mean Temperature:       "<<Mean_Fahrenheit<<"          "<<Mean_Celsius<<endl;
	cout<<" --------------------------------------------------------------"<<endl;
	cout<<"Raw Data..."<<endl;
	cout<<"\n";
	
	// Outputs Data that include the following: Fahrenheit Low and High, Celsius Low and High and Mean...
	
	for(i=0;i<5;i++) // Loops
		
	{ 
		
		cout.precision(3);
		
		cout<<"WeatherStation "<< i <<" =     "<<Fahrenheit[i]<<"            "<<Celsius[i]<<endl;
		
	}
	
	cout<<" --------------------------------------------------------------"<<endl;
	cout<<" =============End Temperature Data Report============="<<endl;
	
}

double Calc(double fah) 

{
	
	double cel; // Converts Fahrenheit to Celsius
	
	cel = (5 *(fah - 32))/9.0;
	
	return cel;
	
	
}
Topic archived. No new replies allowed.