0% found this document useful (0 votes)
75 views9 pages

Project 7 .CPP: Edwardmagruderweatherstation

The program reads in a list of grades from the user into an array. It then calculates and displays the sum, median, mean, and standard deviation of the grades. It lists the grades, putting an asterisk in front of grades below the average. It also displays each grade and its letter equivalent based on a provided scale. C++ code: - Detailed summary and description of what the program does #include "stdafx.h" - Includes header files needed for the program int main() - Main function that runs the program double grade[100]; int n; - Declares an array to store grades and a variable to count grades cout

Uploaded by

pavan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views9 pages

Project 7 .CPP: Edwardmagruderweatherstation

The program reads in a list of grades from the user into an array. It then calculates and displays the sum, median, mean, and standard deviation of the grades. It lists the grades, putting an asterisk in front of grades below the average. It also displays each grade and its letter equivalent based on a provided scale. C++ code: - Detailed summary and description of what the program does #include "stdafx.h" - Includes header files needed for the program int main() - Main function that runs the program double grade[100]; int n; - Declares an array to store grades and a variable to count grades cout

Uploaded by

pavan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Hello, what I need done is for the below code write a detailed summary on the

programming project and then break up each part of the code and write what that part of
the code does. For example,
The entire program code
- Detailed summary and description of what the program does
Snippet of code in the program
- detailed summary and description of what it does
Keep doing that for the code
Thank you. I appreciate it
C++ code:
Project 7
EdwardMagruderWeatherStation.cpp
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include<string>
#include <stdlib.h>
#include<vector>
#include<sstream>
#include "weather.h"
using namespace std;
string DisplayMenu(string station_name)
{
string str, temp;
do
{
cout << "*******************WEATHER STATION: " << station_name\
<< " *******************" << endl << endl;
cout << "I. Input a complete weather reading." << endl;
cout << "P. Print the current weather." << "\n";
cout << "H. Print the weather history (from most recent to oldest)." << endl;
cout << "E. Exit the program." << "\n";
cout << "Enter your choice: " << endl;
cin >> str;
temp = str;
for (std::string::size_type i = 0; i < str.length(); ++i)
temp[i] = toupper(str[i]);
str = temp;
} while (!(str == "I" || str == "P" || str == "H" || str == "E"));
return str;
}
/*
double getTemperature()
{
double temp;
string temp_string;
stringstream converter;
cout << "Enter the temperature: ";
cin >> temp_string;
converter << temp_string;
converter >> temp;
return temp;
}
double getWindSpeed()
{
double temp;
string temp_string;
stringstream converter;
//this loop will be iterated continuously untill user enters windspeed which is greater than
zero
do
{
cout << "Enter Wind speed(>=0): ";
cin >> temp_string;
converter << temp_string;
converter >> temp;
if (temp <= 0)
cout << "Wind speed should be always greater or equal to 0(zero)";
} while (temp < 0);
return temp;
}
string getWindDirection()
{
string temp_string, temp;
do {
cout << "Enter the Wind Direction (North,South,East,West): ";
cin >> temp_string;
temp = temp_string;
for (std::string::size_type i = 0; i < temp_string.length(); ++i)
temp[i] = toupper(temp_string[i]);
} while (!(temp == "NORTH" || temp == "SOUTH" || temp == "EAST" || temp ==
"WEST"));
temp_string = temp;
return temp_string;
};
void printWeather(Weather_Station ws)
{
cout << "Station Name " << ws.name << endl;
cout << "Temperature " << ws.temperatureMeasure.temperature << endl;
cout << "Wind Direction " << ws.windMeasure.windDirection << endl;
cout << "Wind Speed " << ws.windMeasure.windspeed << endl;
cout << endl;
}
*/
int main()
{
//Have the user provide a name for the weather station upon entry.
weather_t * history;
int historySize;

string station_name, input_choice;


int histCount = 0;
cout << "Enter the name of Weather Station: ";
getline(cin, station_name);
do {
cout << "Please enter how many records you want" << "\n";
cin >> historySize;
if (historySize <= 0)
cout << "Input record count should always be greater than 0(zero)" << "\n";

} while (historySize <= 0);


history = new weather_t[historySize];
while (1)
{
//Control loop to perform various actions
input_choice = DisplayMenu(station_name);
if (input_choice == "I")
{
/*
// get the details
int valid_wind_direction = 0, valid_wind_speed = 0;
myWeather_Details.temperatureMeasure.temperature = getTemperature(); // get
temperature
myWeather_Details.windMeasure.windDirection = getWindDirection(); //get wind
direction
myWeather_Details.windMeasure.windspeed = getWindSpeed(); //get wind direction

if (myWeather_Details.windMeasure.windspeed >= 0)
{
valid_wind_speed = 1;
}

if ((myWeather_Details.windMeasure.windDirection == "NORTH") ||
(myWeather_Details.windMeasure.windDirection == "SOUTH") ||
(myWeather_Details.windMeasure.windDirection == "EAST") ||
(myWeather_Details.windMeasure.windDirection == "WEST"))
{
valid_wind_direction = 1;
}
//store the details
if (valid_wind_direction && valid_wind_speed)
myStation.push_back(myWeather_Details);
*/
for (int i = historySize - 1; i > 0; i--) {
history[i] = history[i - 1];
}
history[0] = getWeather();
histCount++;
}
else if (input_choice == "P")
{

cout << "*************Printing Current Weather*************" << endl;


if (histCount > 0) {
printWeather(history[0]);
}
else {
cout << "no data has been entered" << "\n";
}
}
else if (input_choice == "H")
{
cout << "*************Printing Current Weather*************" << endl;
if (histCount == 0)
cout << "no data to output" << "\n";
//this loop will be iterated continuously untill user gives the input count more than 0 and
it is not greater than available record count in vector
int max = histCount > historySize ? historySize : histCount;
for (int i = 0; i < max; i++) {
printWeather(history[i]);
}

else if (input_choice == "E")

{
exit(0);
}
}
return 0;
}
temperature.cpp
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include<string>
#include <stdlib.h>
#include<vector>
#include<sstream>
#include "temperature.h"
using namespace std;
temperature_t getTemperature()
{
temperature_t temp;
string temp_string;
stringstream converter;
cout << "Enter the temperature: ";
cin >> temp_string;
converter << temp_string;
converter >> temp.temperature;
return temp;
}
weather.cpp
#include "stdafx.h"
#include "temperature.h"
#include<string>
#include<sstream>
#include "weather.h"
void printWeather(weather_t ws)
{
//cout << "Station Name " << ws.name << "\n";
cout << "Temperature " << ws.temperature.temperature << "\n";
cout << "Wind Direction " << ws.wind.direction << "\n";
cout << "Wind Speed " << ws.wind.speed << "\n";
cout << "\n";
}
weather_t getWeather() {
weather_t result;
result.wind = getWind();
result.temperature = getTemperature();
return result;
}
wind.cpp
#include "stdafx.h"
#include "wind.h"
#include <stdio.h>
#include <iostream>
#include<string>
#include <stdlib.h>
#include<vector>
#include<sstream>
using namespace std;
double getWindSpeed()
{
double temp = -1;
string temp_string;
stringstream converter;
//this loop will be iterated continuously untill user enters windspeed which is greater than
zero
do
{
cout << "Enter Wind speed(>=0): ";
cin >> temp_string;
stringstream(temp_string) >> temp;
if (temp < 0)
cout << "Wind speed should be always greater or equal to 0(zero)";
} while (temp < 0);
return temp;
}
string getWindDirection()
{
string temp_string, temp;
do {
cout << "Enter the Wind Direction (North,South,East,West): ";
cin >> temp_string;
temp = temp_string;
for (std::string::size_type i = 0; i < temp_string.length(); ++i)
temp[i] = toupper(temp_string[i]);
} while (!(temp == "NORTH" || temp == "SOUTH" || temp == "EAST" || temp
=="WEST"));
temp_string = temp;
return temp_string;
};
wind_t getWind() {
wind_t result;
result.speed = getWindSpeed();
result.direction = getWindDirection();
return result;
}
temperature.h
#pragma once
struct temperature_t {
int temperature;
};
temperature_t getTemperature();
weather.h
#pragma once
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include<string>
#include <stdlib.h>
#include<vector>
#include<sstream>
#include "wind.h"
#include "temperature.h"
using namespace std;
struct weather_t {
wind_t wind;
temperature_t temperature;
};
weather_t getWeather();
void printWeather(weather_t ws);
wind.h
#include<string>
#pragma once
struct wind_t {
double speed;
std::string direction;
};
wind_t getWind();
EXIT
i need 5 9 and 10 answered (need the syntax to be copy and paste ) and screenshots of the
output thank you ..

using functions
Write a C++ program that reads a list of double-precision grades from the keyboard into
an array named grade. The grades are to be counted as they’re read. After all grades have
been input, your program should find and display the sum, median, mean and standard
deviation of the grades. The grades should then be listed with an asterisk (*) placed in
front of each grade that’s below the average.
The program should also display each grade and its letter equivalent, using the following
scale:
Between 70 and 100 = A.
Greater than or equal to 60 and less than 70 = B.
Greater than or equal to 50 and less than 60 = C.
Greater than or equal to 40 and less than 50 = D.
Less than 40 = F.

if(grade>70 && grade<=100)


return 'A';
else if(grade>=60&&grade<70)
return 'B';
else if(grade>=50&&grade<60)
return ‘c’;

else if(grade>=40&&grade<50)
return ‘c’;
else if(grade<40)
return ‘c’;

else if(grade==7)
return 'C';
else if(grade==6)
return 'D';
else if(grade>=0 && grade<=5)
return 'F';
else
return 'E';
}
double CalculateMean()
{
double sum = 0;
for(int i = 0; i < max; i++)
sum += value[i];
return (sum / max);
}

double CalculateVariane()
{
mean = CalculateMean();

double temp = 0;
for(int i = 0; i < max; i++)
{
temp += (value[i] - mean) * (value[i] - mean) ;
}
return temp / max;
}
double GetStandardDeviation()
{
return sqrt(CalculateVariane());
}

You might also like