Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Project 7 Change the program to use structs for temperature, wind, and weather m

ID: 3604241 • Letter: P

Question

Project 7

Change the program to use structs for temperature, wind, and weather measurement.

Refactor your program so that the code for

- temperature is in two files (.h – declarations) and (.cpp – implementations)

- wind is in two files (.h – declarations) and (.cpp – implementations)

-WeatherMeasurement is in two files (.h – declarations) and (.cpp – implementations)

- And your main is in one file

I was told that this program would require at least 6 files so could you label each file and say which code goes in each file for the program. Thank you. I really appreciate it.

C++ code:

#include "stdafx.h"

#include <iostream>

#include <string>

using namespace std;

void moveTemperaturesToRight(double temperatures[],

double windSpeed[],

string windDirection[])

{

for (int i = 3; i > 0; i--)

{

temperatures[i] = temperatures[i - 1];

windSpeed[i] = windSpeed[i - 1];

windDirection[i] = windDirection[i - 1];

}

}

int main()

{

string name;

int choice;

int numOfReadings = 0;

int size;

double temperatures[4], windSpeeds[4];

string windDirections[4];

bool initialized = false;

char str;

//Have the user provide a name for the weather station upon entry.

cout << "Enter the name of weather station: ";

getline(cin, name);

//Control loop to perform various actions.

while (true)

{

cout << "I. Input a complete weather reading." << " ";

cout << "P. Print the current weather." << " ";

cout << "H. Print the weather history (from most recent to oldest)." << " ";

cout << "E. Exit the program." << " ";

cout << "Enter your choice: ";

cin >> str;

if (str != 'I'&& str != 'P'&& str != 'H'&& str != 'E')

choice = 0;

else

choice = str;

//Switch based on choice.

switch (choice)

{

case 'I':

moveTemperaturesToRight(temperatures,

windSpeeds,

windDirections);

cout << "Enter the temperature:";

cin >> temperatures[0];

//get correct wind speed

do

{

cout << "Enter the wind speed (a value >=0):";

cin >> windSpeeds[0];

while (cin.fail() || (cin.peek() != ' ' && cin.peek() != ' '))

{

cout << "Invalid Input! Re Enter the wind speed" << endl;

cin.clear();

while (cin.get() != ' ');

cin >> windSpeeds[0];

}

} while (windSpeeds[0] < 0);

//get correct wind direction

do

{

cout << "Enter the wind direction (North,South,East or West):";

cin >> windDirections[0];

} while (windDirections[0] != "North" && windDirections[0] != "South" && windDirections[0] != "East" && windDirections[0] != "West");

initialized = true;

if (initialized)

numOfReadings++;

if (numOfReadings > 4)

numOfReadings = 4;

break;

case 'H': //Print the current weather, if valid weather is entered.

cout << "Enter size of the history wants:";

cin >> size;

if (numOfReadings<size)

{

cout << "History size is high";

break;

}

for (int i = 0; i < size; i++)

{

cout << "*****" << name << "*****" << " ";

cout << "Temperature: " << temperatures[i] << " ";

cout << "Wind speed: " << windSpeeds[i] << " ";

cout << "Wind direction: " << windDirections[i] << " " << " ";

}

if (numOfReadings == 0)

cout << "Please enter the details before asking to print." << " ";

break;

case 'P':

if (numOfReadings == 0)

{

cout << "Please enter the details before asking to print." << " ";

break;

}

cout << "*****" << name << "*****" << " ";

cout << "Temperature: " << temperatures[0] << " ";

cout << "Wind speed: " << windSpeeds[0] << " ";

cout << "Wind direction: " << windDirections[0] << " " << " ";

break;

case 'E':

return 0; //Stops execution.

default:

cout << "Invalid choice. Please follow the menu." << " ";

}

}

}

Explanation / Answer

ANSWER::

#include <iostream>

#include <cmath>

using namespace std;

double windChill(double v, double t);

double f2c(int tempF);

double c2f(int tempC);

int main( )

{

double t,v,W;

int tempF,

tempC;

cout << "Enter the temperature in Farenheit: ";

cin >> t;

cout << "Enter the wind velocity in meters per second (m/s): ";

cin >> v;  

cout << "temp in F is " << t << endl;

cout << "windspeed is " << v << endl;

tempC = f2c(t);

cout << "Temp in C is : " << tempC << endl;

if (tempC <= 10)

{

W = windChill(v, tempC);  

cout << "Windchill is : " << W << endl;

tempF = c2f(tempC);

cout << "Temp in F after windchill is : " << tempF << endl;

cout.setf(ios::fixed);

cout.setf(ios::showpoint);

cout.precision(2);

cout << "The windchill is " << W << " degrees Celcius ";

cout << "and " << tempF << " degrees Farenheidt.";

return(0);

}

else

cout << "The Farenheidt temperature you entered is less than 10 degrees Celcius. Windchill is negligable.";

return (0);

}

}

double windChill(double v, double t)

{

double W;

W = (33-(((10 * sqrt(v))-v+10.5)*(33-t))/23.1);

return W;

}

double f2c(int tempF)

{

double tempC;

tempC = (5/9)*(tempF + 32);

return tempC;

}

double c2f(int tempC)

{

double tempF;

tempF = (9/5)*(tempC - 32);

return tempF;

}