Am I programming this correctly?

November 1, 2010 at 00:36:08
Specs: Windows Vista
I'm suppose to incorporate struct WeatherStation into my C++. It consists of a weather data that he has given to us and he wants us to be able to type in numbers and have it processed out. I have done it, but am I doing anything wrong? Please help!

Here is what he wants us to incorporate:

struct WeatherStation {
string StationDesignation;
double Temperature;
};

This is what I have so far:
/*
Title: NGSDailyTemperatureReport.cpp
Description: this illustrates an array of weather station objects that will allow the user to post the temperatures in a simple list...
*/
#include <iostream>
#include <string>
#include <vector>
using namespace std;

struct WeatherStation {
string StationDesignation;
double Temperature;
};

vector<WeatherStation> FillList();
WeatherStation SearchList(vector<WeatherStation>, string);
void ShowList(vector<WeatherStation>);
void Menu();

int main()
{
vector<WeatherStation> List;
string Command; //A variable to contain the specific command...
string Value;
WeatherStation Result;

//Define a command processor...

while(true) {
Menu(); //Display the choices

cout << "Command: ";
getline(cin, Command); //Get the choice from the keyboard

if(Command == "Quit") //Process the choice...
break;
else if(Command == "Post Temperatures")
List = FillList(); //call the fill funtions...
else if(Command == "Daily Report") {
int Count, Sum = 0;
string Value;
double List[57];

cout << "Enter reported temperatures..." << endl;
cout << " Fahrenheit Celsius" << endl;
cout << "Weather Station Big Basin: 55.0 12.8" << endl;
cout << "Weather Station Foothill: 56.0 13.3" << endl;
cout << "Weather Station DeAnza: 55.0 12.8" << endl;
cout << "Weather Station MiddleField: 44.0 6.67" << endl;
cout << "Weather Station Redwood City: 57.0 13.9" << endl;

cout << "========NGS Temperature Data Report========" << endl;
cout << "Raw Data..." << endl;
cout << "Enter Values Below, Stop To Quit" << endl;
for(Count = 0 ; Count < 57 ; Count++) {
cout << "Enter Value: ";
cin >> Value;
if(Value == "Stop")
break;

List[Count] = atoi(Value.c_str() );
}

int K;

for(K = 0 ; K < Count ; K++)
Sum += List[K];

for(K = 0 ; K < Count ; K++)
cout << "List[" << K << "] = " << List[K] << endl;
if(Count > 0)
cout << "Mean Temperature = " << Sum / Count << endl;
else
cout << "No Values Entered" << endl;
cout << " Fahrenheit Celsius" << endl;
cout << "-----------------------------------------------------" << endl;
cout << "Mean Temperature: 53.4 11.9" << endl;
cout << "-----------------------------------------------------" << endl;
cout << "Raw Data..." << endl;
cout << "Weather Station Big Basin: 55.0 12.8" << endl;
cout << "Weather Station Foothill: 56.0 13.3" << endl;
cout << "Weather Station DeAnza: 55.0 12.8" << endl;
cout << "Weather Station MiddleField: 44.0 6.67" << endl;
cout << "Weather Station Redwood City: 57.0 13.9" << endl;
cout << "-----------------------------------------------------" << endl;
cout << "========End Temperature Data Report========" << endl;
}
else if(Command == "High-Low Report") {
int Count, Sum = 0;
string Value;
double List[57];

cout << "Enter reported temperatures..." << endl;
cout << " Fahrenheit Celsius" << endl;
cout << "Weather Station Big Basin: 55.0 12.8" << endl;
cout << "Weather Station Foothill: 56.0 13.3" << endl;
cout << "Weather Station DeAnza: 55.0 12.8" << endl;
cout << "Weather Station MiddleField: 44.0 6.67" << endl;
cout << "Weather Station Redwood City: 57.0 13.9" << endl;

cout << "========NGS Temperature Data Report========" << endl;
cout << "Raw Data..." << endl;
cout << "Enter Values Below, Stop To Quit" << endl;
for(Count = 0 ; Count < 57 ; Count++) {
cout << "Enter Value: ";
cin >> Value;
if(Value == "Stop")
break;

List[Count] = atoi(Value.c_str() );
}

int K;

int Smallest = List[0];

for(K = 1 ; K < Count ; K++)
if(List[K] < Smallest)
Smallest = List[K];
cout << "Lowest Temperature = " << Smallest << endl;

int Largest = List[0];

for(K = 1 ; K < Count ; K++)
if(List[K] > Largest)
Largest = List[K];
cout << "Highest Temperature = " << Largest << endl;
cout << " Fahrenheit Celsius" << endl;
cout << "-----------------------------------------------------" << endl;
cout << "Lowest Temperature: 43.0 6.11" << endl;
cout << "-----------------------------------------------------" << endl;
cout << "Highest Temperature: 51.0 10.6" << endl;
cout << "-----------------------------------------------------" << endl;
cout << "Raw Data..." << endl;
cout << "Weather Station Big Basin: 55.0 12.8" << endl;
cout << "Weather Station Foothill: 56.0 13.3" << endl;
cout << "Weather Station DeAnza: 55.0 12.8" << endl;
cout << "Weather Station MiddleField: 44.0 6.67" << endl;
cout << "Weather Station Redwood City: 57.0 13.9" << endl;
cout << "-----------------------------------------------------" << endl;
cout << "========End Temperature Data Report========" << endl;
}

cout << "Another report from the head of software development for NGS..." << endl;

}

Is this right?


See More: Am I programming this correctly?

Report •


#1
November 1, 2010 at 11:30:10
At a glance:
WeatherStation SearchList(vector<WeatherStation>, string);
void ShowList(vector<WeatherStation>);

Should be:
WeatherStation SearchList(vector<WeatherStation> const&, string);
void ShowList(vector<WeatherStation> const&);

else if(Command == "Daily Report") {
No closing }

cout << "Weather Station Big Basin: 55.0 12.8" << endl;
I'm pretty sure your professor wants your program to compute the output, not you.

How To Ask Questions The Smart Way


Report •

#2
November 1, 2010 at 12:39:16
Would it be like this?

#include <iostream>
#include <string>
#include <vector>
using namespace std;

struct WeatherStation {
string StationDesignation;
double Temperature;
};

vector<WeatherStation> FillList();
WeatherStation SearchList(vector<WeatherStation> const&, string);
void ShowList(vector<WeatherStation> const&);
void Menu();

void Menu()
{
cout << "Choices...................." << endl;
cout << "===========================" << endl;
cout << "\tPost Temperatures" << endl;
cout << "\tDaily Report" << endl;
cout << "\tHigh-Low Report" << endl;
cout << "===========================" << endl;
}

int main()
{
vector<WeatherStation> List;
string Command;
string Value;
WeatherStation Result;

while(true) {
Menu();

cout << "Enter Command: ";
getline(cin, Command);

if(Command == "Quit")
break;
else if(Command == "Post Temperatures")
List = FillList();
else if(Command == "Daily Report") {
cout << "Search For: ";
getline(cin, Value);
Result = SearchList(List, Value);
else if(Command == "High-Low Report")
ShowList(List);
}

cout << "Another report from the head of software development for NGS..." << endl;

}

vector<WeatherStation> FillList()
{
vector<WeatherStation> LocalList;
WeatherStation LocalName;
string WeatherStation;

cout << "Enter Reported Temperatures Below, Stop To Quit" << endl;

while(true) {
cout << "WeatherStation: ";
getline(cin, WeatherStation);

LocalList.push_back(LocalName);
}

return LocalList;
}

WeatherStation SearchList(vector<WeatherStation> const&, string);
{
int K;

int Count, Sum = 0;
string Value;
double List[57];
cout << "Enter Values Below, Stop To Quit" << endl;
for(Count = 0 ; Count < 57 ; Count++) {
cout << "Enter Value: ";
cin >> Value;
if(Value == "Stop")
break;

List[Count] = atoi(Value.c_str() );
}
int K;

for(K = 0 ; K < Count ; K++)
Sum += List[K];

for(K = 0 ; K < Count ; K++)
cout << "List[" << K << "] = " << List[K] << endl;
if(Count > 0)
cout << "Mean Temperature = " << Sum / Count << endl;
}

void ShowList(vector<WeatherStation> const&);
{
int K;

int Count, Sum = 0;
string Value;
double List[57];
cout << "Enter Values Below, Stop To Quit" << endl;
for(Count = 0 ; Count < 57 ; Count++) {
cout << "Enter Value: ";
cin >> Value;
if(Value == "Stop")
break;

List[Count] = atoi(Value.c_str() );
}
int K;

int Smallest = List[0];

for(K = 1 ; K < Count ; K++)
if(List[K] < Smallest)
Smallest = List[K];
cout << "Lowest Temperature = " << Smallest << endl;

int Largest = List[0];

for(K = 1 ; K < Count ; K++)
if(List[K] > Largest)
Largest = List[K];
cout << "Highest Temperature = " << Largest << endl;
}

I'm sorry, its my first time taking a C++ class and everything is sort of confusing at the moment.


Report •

Related Solutions


Ask Question