Thread: Re: need help with the programme

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    12

    Re: need help with the programme

    Sorry, guys I forgot to tag my code in the previous post. That's why I am making a new post with code-tag of course. Anyway, here is my programme and it is not working.

    Code:
    
            #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");
    
            }

    So, when I compile it, it shows me about 5 errors. And, here are some of those errors; class WeatherStation' has no member named 'GetName' , expected constructor, destructor, or type conversion before '.' token.
    Once again, any help will be greatly appreciated.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You just copy/pasted from your previous post didn't you?

    SourceForge.net: Indentation - cpwiki
    Is the code in your IDE really that badly indented (ie, none at all)?

    EDIT your post, then copy/paste from your IDE.

    I wonder if you've been using some mix of spaces and tabs in your code?
    That will result in more chaos.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    First, read how to post and then post it.
    Second, read about classes and try to understand what constructors and destructors are for.
    Finally, indent your code and post the exact errors, you are facing as no one has enough time to look through the whole code.
    That's just for your and everyone's ease.
    I don't care if someone doesn't like me, i was not put on earth to entertain everyone.

    No King, no Queen, I am the ACE of battle.

  4. #4
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    class WeatherStation' has no member named 'GetName'
    It does what it says on the tin

    There is no member function of that name in your class, or the class it inherits from, so why are you confused by the error?
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    As mentioned in the other thread

    It's copy/paste code.
    It isn't indented, because what they copied wasn't indented.
    In short, it's not worth the effort - you DON'T want (or need) this person working next to you in a couple of years.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help me with ma c programme..
    By eddie19 in forum C Programming
    Replies: 19
    Last Post: 08-12-2009, 07:53 AM
  2. Closing a programme with cin.get
    By Dontgiveup in forum C++ Programming
    Replies: 2
    Last Post: 03-14-2009, 02:35 PM
  3. How to view the programme before it disappears
    By yousuf in forum C Programming
    Replies: 2
    Last Post: 03-22-2008, 08:12 AM
  4. Replies: 3
    Last Post: 05-13-2007, 08:55 AM
  5. Gui Programme does'nt Compiles from DOS
    By Shadowhunt in forum C++ Programming
    Replies: 1
    Last Post: 06-06-2003, 08:05 AM