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. Any input would be greatly appreciated.


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========

#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;
	
}

Well... It is somewhat straight forward... Though, you can implement this in many ways. You just need to decide and identify which portion of the code is being called many times, and then take that part out and put in a function. Also, the temperature computation part (min, max, average) could become a function as well.

Sound about right. But how would I go by implementing the new data structure into the program?

Sorry I'm very new to this so excuse any questions that might seem obvious.

-- Thanks.

OK, for example, the structure of displaying all 3 messages are the same, you could take them out and create a function for it. What you need is to supply the function with matched arguments' data type and the return type. If the return type is 'void', it means that the function will not return a value. A sample is below.

// this portion of code lines
cout.precision(3);
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;

// could turn into function calls
displayData("Lowest Temperature:     ", FahrenheitLowTemperature, CelsiusLowTemperature);
displayData("Highest Temperature:    ", FahrenheitHighTemperature, CelsiusHighTemperature);
displayData("Mean Temperature:       ", Mean_Fahrenheit, Mean_Celsius);

// and this is the function definition
void displayData(string str, double val1, double val2) {
  cout.precision(3);
  cout<<str<<val1<<"          "<<val2<<endl;
  cout<<" --------------------------------------------------------------"<<endl;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.