Just wanted to make sure if this is right

November 15, 2010 at 23:19:42
Specs: Windows Vista
Any help will be great!

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

struct WeatherStation {
string StationDesignation;
double Temperature;
};

int main()
{
char str[100];
char ch;
while ( true )
{
cout << "Choices...................." << endl;
cout << "===========================" << endl;
cout << "\tAdd Stations...allows the user to add elements into the list." << endl;
cout << "\tPost Temperatures...allows the user to put elements into the list." << endl;
cout << "\tDaily Report...allows the user to look for the mean temperature of the list." << endl;
cout << "\tHigh-Low Report...displays the highest and lowest temperature of the list." << endl;
cout << "\tQuit...exit the program." << endl;
cout << "===========================" << endl;
cout << "Enter Command: " << endl;

cin.get( str, 99 );
cin.get(ch);

if ( ( strcmpi("Post Temperatures", str) == 0 ) )
cout << "Post Temperatures..." << endl;

if ( ( strcmpi("Daily Report", str) == 0 ) )
cout << "Daily Report..." << endl;

if ( ( strcmpi("High-Low Report", str) == 0 ) )
cout << "High-Low Report..." << endl;

if ( ( strcmpi("Quit", str) == 0 ) )
break;
}

class WeatherStation
{
string StationDesignation;
string StationAgent;
double Temperature;

public:
void SetDesignation(string ID) { StationDesignation = ID; }
void SetAgent(string Agent) { StationAgent = Agent; }
void SetTemperature(double Degree) {Temperature = Degree; }

string GetDesignation() { return StationDesignation; }
string GetAgent() { return StationAgent; }
double GetTemperature() { return Temperature; }

void Displayer();
void WeatherStation::Displayer()
{
cout << "--------------------------------------" << endl;
cout << "Station:\t " << StationDesignation << endl;
cout << "Agent:\t " << StationAgent<< endl;
cout << "Current Temperature: " << Temperature << endl;
cout << "--------------------------------------" << endl;
}
class ShortName {
string FirstName;
string LastName;

public:

ShortName()
{
FirstName = "";
LastName = "";
}

ShortName(string First, string Last)
{
FirstName = First;
LastName = Last;
}

void SetFirst(string First) { FirstName = First;}
void SetLast(string Last) { LastName = Last;}

string GetFirst() { return FirstName; }
string GetLast() { return LastName; }
};

class Record {
ShortName Name;
string WeatherStation;

public:
Record(string First, string Last, string WeatherStation)
{
Name.SetFirst(First);
Name.SetLast(Last);
}

void SetFirst(string First) { Name.SetFirst(First); }
void SetLast(string Last) { Name.SetLast(Last); }
};

void Choices(WeatherStation stations[]);
void PostTemperature(WeatherStation stations[]);
void DailyReport(WeatherStation stations[]);
void FarenheitToCelsius(WeatherStation stations[]);
void H_LTempReport(WeatherStation stations[]);

{
WeatherStation stations[5];
Choices(stations);
return 0;

void H_LTempReport(WeatherStation stations[])

WeatherStation LowestStat = stations[0];
WeatherStation HighestStat = stations[0];
}

for (int i = 1; i <= 4; i++)
{
if ( HighestStat.Farenheit < stations[i].Farenheit )
HighestStat = stations[i];

cout << endl << "Farenheight Celsius";
cout << endl << "Lowest Temperature: " << LowestStat.Farenheit << " " << HighestStat.Celsius;
cout << endl << "Highest Temperature: " << HighestStat.Farenheit << " " << HighestStat.Celsius;
}

void Choices(WeatherStation stations[])
void PostTemperature(WeatherStation stations[])
{
strcpy(stations[0].StationDesignation, "Weather Station Big Basin: ");
strcpy(stations[1].StationDesignation, "Weather Station Foothill: ");
strcpy(stations[2].StationDesignation, "Weather Station DeAnza: ");
strcpy(stations[3].StationDesignation, "Weather Station MiddleField: ");
strcpy(stations[4].StationDesignation, "Weather Station Redwood City: ");
cout << endl << "Enter reported temperatures......";
for (int i = 0; i <= 4; i++)

{
cout << endl << stations[i].StationDesignation;
cin >> stations[i].Farenheit;
}

FarenheitToCelsius(stations);
}

void FarenheitToCelsius(WeatherStation stations[])
{
for (int i = 0; i <= 4; i++)
{
stations[i].Celsius = ( 5.0 / 9.0 ) * ( stations[i].Farenheit - 32.0 );
}
}
void DailyReport(WeatherStation stations[])
{
cout << endl << "A More Awesome Temperature Report Software";
cout << endl << "Farenheit Celsius";

for (int i = 0; i <= 4; i++)
{
cout << endl << stations[i].StationDesignation << stations[i].Farenheit
<< " " << stations[i].Celsius;
}
}


See More: Just wanted to make sure if this is right

Report •


#1
November 15, 2010 at 23:58:29

........................................................................................................................

int main()
{
char str[100];
char ch;
while ( true )
{
cout << "Choices...................." << endl;
cout << "===========================" << endl;
cout << "\tAdd Stations...allows the user to add elements into the list." << endl;
cout << "\tPost Temperatures...allows the user to put elements into the list." << endl;
cout << "\tDaily Report...allows the user to look for the mean temperature of the list." << endl;
cout << "\tHigh-Low Report...displays the highest and lowest temperature of the list." << endl;
cout << "\tQuit...exit the program." << endl;
cout << "===========================" << endl;
cout << "Enter Command: " << endl;

cin.get( str, 99 );
cin.get(ch);

if ( ( strcmpi("Post Temperatures", str) == 0 ) )
cout << "Post Temperatures..." << endl;

if ( ( strcmpi("Daily Report", str) == 0 ) )
cout << "Daily Report..." << endl;

if ( ( strcmpi("High-Low Report", str) == 0 ) )
cout << "High-Low Report..." << endl;

if ( ( strcmpi("Quit", str) == 0 ) )
break;
}

........................................................................................................................

suppose it has displayed these lines on screen.....

Choices....................
===========================
Add Stations...allows the user to add elements into the list.
Post Temperatures...allows the user to put elements into the list.
Daily Report...allows the user to look for the mean temperature of the list.
High-Low Report...displays the highest and lowest temperature of the list.
Quit...exit the program.
===========================
Enter Command:

......................................................................................................................

and I typed Daily Report these lines will be executed......

........................................................................................................................

if ( ( strcmpi("Daily Report", str) == 0 ) )
cout << "Daily Report..." << endl;

........................................................................................................................

cout << "Daily Report..." << endl;

this line will just display this line on screen.................

Daily Report

and nothing more............. after that these lines will be displayed again............

......................................................................................................................
Choices....................
===========================
Add Stations...allows the user to add elements into the list.
Post Temperatures...allows the user to put elements into the list.
Daily Report...allows the user to look for the mean temperature of the list.
High-Low Report...displays the highest and lowest temperature of the list.
Quit...exit the program.
===========================
Enter Command:
........................................................................................................................
it will not show daily report...........
......................................................................................................................
forgive me for my bad english......
.......................................................................................................................

_Adnan_


Report •

#2
November 16, 2010 at 08:17:51
your professor gave you data structure to reformat, so, that's why I reformatted that.

struct WeatherStation {
string StationDesignation;
double Temperature;
};

..................................................................................................................
_Adnan_


Report •

#3
November 16, 2010 at 12:17:11
Alright, looks like it's time to nip this in the bud.

_Adnan_, I don't care if you want to help people with their homework, but there's one rule: Don't give source.

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
November 16, 2010 at 14:02:03
From a user's perspective, having to enter a string for a menu choice may become tedious after entering data a few times... especially for a user with heavy fingers.

If you're using the string class, you could use a string object for the menu, which you can test using == directly.

std::string s = "test";
std::cout << (s == "test" ? "true" : "false") << std::endl;

With your loops, you'd be better off if you use a constant instead of hard coding... that way, if you need to change its value, you change one line instead of having to find each loop that would be affected.

const int MAXSTATIONS = 4;
for(int i=0; i <= MAXSTATIONS; ++i) { ... }


Report •

#5
November 16, 2010 at 14:49:33
i don't know if its work for you, but i think you missed a lot of thing like :
1- why did you put the first class (class WeatherStation) inside the main() function?
2- at the end of (class WeatherStation) u forgot ( }; ) and other or maybe just after you typed it here.

Report •

#6
November 16, 2010 at 20:39:50
I will try bro, but to learn you have to see code...

..................................................................................................................

_Adnan_


Report •

Ask Question