Help please! Does this look right?

December 10, 2010 at 17:42:11
Specs: Windows Vista
I just finished my project..it wants me to be able to copy and load files through a disk. Is this correct?

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

class GreenStation {
double AirQualityIndex;
double PollenCount;

public:
GreenStation(){;}
GreenStation(double, double);

//Define mutators...

void SetPCount(double Count) { PollenCount = Count; }
void SetAQScore(double Score) { AirQualityIndex = Score; }

//Define accessors...

double GetPCount() { return PollenCount; }
double GetAQScore() { return AirQualityIndex; }
};

class WeatherStation : public GreenStation {

string StationDesignation; //Identifies the station
string StationAgent; //Who's responsible
double Temperature; //...and, of course, how hot is it?
public:
//Define some mutators...These member functions allow us to
// change values in the object...
void SetDesignation(string ID) { StationDesignation = ID; }
void SetAgent(string Agent) { StationAgent = Agent; }
void SetTemperature(double Degree) {Temperature = Degree; }

//Define some accessors...These member functions allow us to get
// at the internal values

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

//Define a displayer...this will show the contents of the object
// in an easy to read format..

void Displayer();
};

class WeatherStationList {
vector<WeatherStation> List; //These two lines essentially implement the list...
vector<WeatherStation>::iterator ThroughTheList;

string FileName; //We need to know where we're putting things...

public:
WeatherStationList() { FileName = "GreenStation"; } //Default constructor...
WeatherStationList(string FName) { FileName = FName; } //The initializing constructor lets you set a different file name..

//The traditional actions...

void AddStations();
void PostTemperature();
void PostPollenCount();
void PostAirQuality();
void Report();
void Remove(string);
void Show();

//The file related actions

void SetFileName (string FName) { FileName = FName; } //This lets you change the name while it runs...
void WriteToFile();
void ReadFromFile();
};

void WeatherStationList::AddStations()
{
string Name, Agent;
WeatherStation TemporaryBuffer;

cout << "Enter Station Information Below, Stop To Quit" << endl;

while(true) {
cout << "Weather Station Designaton: ";
getline(cin, Name);
if(Name == "Stop")
break;

cout << "Contact Person: ";
getline(cin, Agent);
if(Agent == "Stop")
break;

TemporaryBuffer.SetDesignation(Name);
TemporaryBuffer.SetAgent(Agent);
List.push_back(TemporaryBuffer);
}
}

//Remove() erases a specified object from the vector...

void WeatherStationList::Remove(string ID)
{
//Use an iterator to move through the list in order...

for(ThroughTheList = List.begin() ; ThroughTheList < List.end() ; ThroughTheList++)
if( ID == ThroughTheList->GetAgent()) { //If there's a match...
List.erase(ThroughTheList); //Remove it..
return;
}

cout << ID << " Not Found " << endl;
}

void WeatherStationList::PostTemperature()
{
int K;
double Temperature;

cout << "Enter Temperatures Below" << endl;

for(K = 0 ; K < List.size() ; K++) {
cout << List[K].GetDesignation() << ": ";
cin >> Temperature;
List[K].SetTemperature(Temperature);
}
}

void WeatherStationList::PostPollenCount()
{
double PollenCount;
int K;

cout << "Pollen count Below" << endl;

for(K = 0 ; K < List.size() ; K++) {
cout << List[K].GetDesignation() << ": ";
cin >> PollenCount;
List[K].SetPCount(PollenCount);
}
}

void WeatherStationList::PostAirQuality()
{
double AirQualityScore;
int K;

cout << "Air Quality Score count Below" << endl;

for(K = 0 ; K < List.size() ; K++) {
cout << List[K].GetDesignation() << ": ";
cin >> AirQualityScore;

List[K].SetAQScore(AirQualityScore);
}
}

void WeatherStationList::Report()
{
int K;

for(K = 0 ; K < List.size() ; K++)
List[K].Displayer();
}

int main()
{
WeatherStationList Norcal;

Norcal.AddStations();
Norcal.PostTemperature();
Norcal.PostPollenCount();
Norcal.PostAirQuality();
Norcal.Report();
}

void WeatherStationList::WriteToFile()
{
fstream OutFile(FileName.c_str(), ios::out);

for(ThroughTheList = List.begin() ; ThroughTheList < List.end() ; ThroughTheList++) {
OutFile << ThroughTheList->GetName() << endl;
OutFile << ThroughTheList->GetAgent() << endl;
}

OutFile.close();
}

void WeatherStationList::ReadFromFile()
{
fstream InFile(FileName.c_str(), ios::in);

string Name, Agent;
ShortName Buffer;

while( true ) {
getline(InFile, Name);
getline(InFile, Agent);
Buffer.SetFirst(Name);
Buffer.SetLast(Agent);
if(InFile.eof())
break;
List.push_back(Buffer);
}

InFile.close();

}

void Menu();

int main()
{
VectorList Collection;

string Command;

while(true) {
Menu();

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

if(Command == "Quit")
break;
else if(Command == "Station")
Collection.Station();
else if(Command == "Contact Person")
Collection.ContactPerson();
else if(Command == "Current Temperature")
Collection.CurrentTemperature();
else if(Command == "Current Pollen Count")
Collection.CurrentPollenCount();
else if(Command == "Current Air Quality")
Collection.CurrentAirQuality();
else if(Command == "Write")
Collection.WriteToFile();
else if(Command == "Read")
Collection.ReadFromFile();
}
cout << "Another product from EnviroMeasurementGreenStation" << endl;
}

void Menu()
{
cout << "--------------------------------------" << endl;
cout << " Station:\t " << endl;
cout << " Contact Person:\t " << endl;
cout << " Current Temperature:\t " << endl;
cout << " Current Pollen Count:\t " << endl;
cout << " Current Air Quality:\t " <<endl;
cout << " Write:\t " << endl;
cout << " Read:\t " << endl;
cout << " Quit:\t " << endl;
cout << "--------------------------------------" << endl;

system("pause");
}


See More: Help please! Does this look right?

Report •


#1
December 10, 2010 at 18:07:46
I revised it, but its still not working...

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

class GreenStation {
double AirQualityIndex;
double PollenCount;

public:
GreenStation(){;}
GreenStation(double, double);

//Define mutators...

void SetPCount(double Count) { PollenCount = Count; }
void SetAQScore(double Score) { AirQualityIndex = Score; }

//Define accessors...

double GetPCount() { return PollenCount; }
double GetAQScore() { return AirQualityIndex; }
};

class WeatherStation : public GreenStation {

string StationDesignation; //Identifies the station
string StationAgent; //Who's responsible
double Temperature; //...and, of course, how hot is it?
public:
//Define some mutators...These member functions allow us to
// change values in the object...
void SetDesignation(string ID) { StationDesignation = ID; }
void SetAgent(string Agent) { StationAgent = Agent; }
void SetTemperature(double Degree) {Temperature = Degree; }

//Define some accessors...These member functions allow us to get
// at the internal values

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

//Define a displayer...this will show the contents of the object
// in an easy to read format..

void Displayer();
};

class WeatherStationList {
vector<WeatherStation> List; //These two lines essentially implement the list...
vector<WeatherStation>::iterator ThroughTheList;

string FileName; //We need to know where we're putting things...

public:
WeatherStationList() { FileName = "GreenStation"; } //Default constructor...
WeatherStationList(string FName) { FileName = FName; } //The initializing constructor lets you set a different file name..

//The file related actions...

void SetFileName (string FName) { FileName = FName; } //This lets you change the name while it runs...
void WriteToFile();
void ReadFromFile();

//The traditional actions...

void AddStations();
void PostTemperature();
void PostPollenCount();
void PostAirQuality();
void Report();
void Remove(string);
void Show();
};

void WeatherStationList::AddStations()
{
string Name, Agent;
WeatherStation TemporaryBuffer;

cout << "Enter Station Information Below, Stop To Quit" << endl;

while(true) {
cout << "Weather Station Designaton: ";
getline(cin, Name);
if(Name == "Stop")
break;

cout << "Contact Person: ";
getline(cin, Agent);
if(Agent == "Stop")
break;

TemporaryBuffer.SetDesignation(Name);
TemporaryBuffer.SetAgent(Agent);
List.push_back(TemporaryBuffer);
}
}

//Remove() erases a specified object from the vector...

void WeatherStationList::Remove(string ID)
{
//Use an iterator to move through the list in order...

for(ThroughTheList = List.begin() ; ThroughTheList < List.end() ; ThroughTheList++)
if( ID == ThroughTheList->GetAgent()) { //If there's a match...
List.erase(ThroughTheList); //Remove it..
return;
}

cout << ID << " Not Found " << endl;
}

void WeatherStationList::PostTemperature()
{
int K;
double Temperature;

cout << "Enter Temperatures Below" << endl;

for(K = 0 ; K < List.size() ; K++) {
cout << List[K].GetDesignation() << ": ";
cin >> Temperature;
List[K].SetTemperature(Temperature);
}
}

void WeatherStationList::PostPollenCount()
{
double PollenCount;
int K;

cout << "Pollen count Below" << endl;

for(K = 0 ; K < List.size() ; K++) {
cout << List[K].GetDesignation() << ": ";
cin >> PollenCount;
List[K].SetPCount(PollenCount);
}
}

void WeatherStationList::PostAirQuality()
{
double AirQualityScore;
int K;

cout << "Air Quality Score count Below" << endl;

for(K = 0 ; K < List.size() ; K++) {
cout << List[K].GetDesignation() << ": ";
cin >> AirQualityScore;

List[K].SetAQScore(AirQualityScore);
}
}

void WeatherStationList::Report()
{
int K;

for(K = 0 ; K < List.size() ; K++)
List[K].Displayer();
}

int main()
{
WeatherStationList Norcal;

Norcal.AddStations();
Norcal.PostTemperature();
Norcal.PostPollenCount();
Norcal.PostAirQuality();
Norcal.Report();
}

void WeatherStationList::Show()
{

cout << "========================================" << endl;

for(ThroughTheList = List.begin() ; ThroughTheList < List.end() ; ThroughTheList++)
ThroughTheList->Displayer();

cout << "========================================" << endl;
}

void WeatherStationList::WriteToFile()
{
fstream OutFile(FileName.c_str(), ios::out);

for(ThroughTheList = List.begin() ; ThroughTheList < List.end() ; ThroughTheList++) {
OutFile << ThroughTheList->GetName() << endl;
OutFile << ThroughTheList->GetAgent() << endl;
}

OutFile.close();
}

void WeatherStationList::ReadFromFile()
{
fstream InFile(FileName.c_str(), ios::in);

string Name, Agent;
ShortName Buffer;

while( true ) {
getline(InFile, Name);
getline(InFile, Agent);
Buffer.SetFirst(Name);
Buffer.SetLast(Agent);
if(InFile.eof())
break;
List.push_back(Buffer);
}

InFile.close();

}

void Menu();

int main()
{
VectorList Collection;

string Command;

while(true) {
Menu();

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

if(Command == "Quit")
break;
else if(Command == "Station")
Collection.AddStations();
else if(Command == "Contact Person")
Collection.AgentName();
else if(Command == "Current Temperature")
Collection.PostTemperature();
else if(Command == "Current Pollen Count")
Collection.PostPollenCount();
else if(Command == "Current Air Quality")
Collection.PostAirQuality();
else if(Command == "Show")
Collection.Show();
else if(Command == "Set") {
cout << "Enter File Name: ";
getline(cin,File);
Collection.SetFileName(File);
}
else if(Command == "Write")
Collection.WriteToFile();
else if(Command == "Read")
Collection.ReadFromFile();
}
cout << "Another product from EnviroMeasurementGreenStation" << endl;
}

void Menu()
{
cout << "--------------------------------------" << endl;
cout << " Station:\t " << endl;
cout << " Contact Person:\t " << endl;
cout << " Current Temperature:\t " << endl;
cout << " Current Pollen Count:\t " << endl;
cout << " Current Air Quality:\t " << endl;
cout << " Show:\t" << endl;
cout << " Set:\t " << endl;
cout << " Write:\t " << endl;
cout << " Read:\t " << endl;
cout << " Quit:\t " << endl;
cout << "--------------------------------------" << endl;

system("pause");
}


Report •

#2
December 11, 2010 at 08:09:16
brian08: its still not working...
Behold, the three words I shouldn't have to ask: "Not working" how?

How To Ask Questions The Smart Way


Report •

#3
December 13, 2010 at 12:57:44
I haven't looked to deep into your code..but why do you have 2 main() functions...
can you post what error messages you are getting

Report •

Related Solutions

#4
December 13, 2010 at 13:45:03
you have a bunch of errors..looks like this is a school assignment
you should meet with your class TA..its not just 1 or 2 things there are several things that are wrong with this code

Report •

Ask Question