Thread: help creating a class

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    15

    help creating a class

    I am trying to creat a gaspump class. I need to creat the functions, reset fuel pump, reset fuel charge, display fuel charges, display fuel pumped, pump status ( on or off), fuel grade( leaded, unleaded, or diesel), and octane ratings. I am unsure of how to write the functions. I took a stab at it. I also wanted to know about reating objects. Should they be pump1, pump2 etc.. or the cars that use the pumps like Nissan, volvo, etc... Any help would anyone could give would ease my stress greatly. Here is the class that I created:

    Code:
    class   gaspump
    {
        private:
            void    ResetFuelCharges(int bills, int coins);
            void    ResetFuelPumped(int gal);
            float   gallons;
            float   dollars;
            float   cents;
    
    
        public:
            float    DisplayFuelCharge(char grade, int octane, int gal, float charges);
            float    DisplayFuelPumped;
            bool     PumpStatus;
            char     FuelGrades;
            int      OctaneRatings;
            
    };
    
    and the functions that I done so far:
    
    void gaspump::ResetFuelCharges(float bills, float coins)
        {
            dollars = 0.00;
            cents = .00;
        }
        
    void gaspump::ResetFuelPumped(float gals)
        {
            gallons = gal;
            gallons = 0.00;
        }
        
    float gaspump::DisplayFuelCharges(char grade, int octane, int gal, float charges)
        {
            if (grade ++ "L")   
            {
               charges = 2.00 * gallons;
               return charges;
            }
               if (grade =="D")
               {
                  charges = 2.25 * gallons;
                  return charges;
               }
                  if (grade == "U") && (octane == "R")
                  {
                     charges = 1.40 * gallons;
                     return charges;
                  }
                     if (grade =="U") && (octane == "S")
                     {
                        charges = 1.50 * gallons;
                        return charges;
                     }
                     else
                        if (grade == "U") && (octane == "G")
                        {
                            charges = 1.75 * gallons;
                            return charges;
                         }
    }

  2. #2
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146

    Re: help creating a class

    Couple of problems I can see right away.

    Code:
    class   gaspump
    {
        private:
            void    ResetFuelCharges(int bills, int coins);
            void    ResetFuelPumped(int gal);
            float   gallons;
            float   dollars;
            float   cents;
    
    
        public:
            float    DisplayFuelCharge(char grade, int octane, int gal, float charges);
            float    DisplayFuelPumped;
            bool     PumpStatus;
            char     FuelGrades;
            int      OctaneRatings;
            
    };
    
    and the functions that I done so far:
    
    void gaspump::ResetFuelCharges(float bills, float coins) // why have paramaters if you're not going to use them?
        {
            dollars = 0.00;
            cents = .00;
        }
        
    void gaspump::ResetFuelPumped(float gals)
        {
            gallons = gal;  // huh?  why have this line?
            gallons = 0.00;
        }
        
    float gaspump::DisplayFuelCharges(char grade, int octane, int gal, float charges)
        {
            if (grade ++ "L")   // I think this typo is pretty obvious
            {
               charges = 2.00 * gallons;
               return charges;
            }
               if (grade =="D")
               {
                  charges = 2.25 * gallons;
                  return charges;
               }
                  if (grade == "U") && (octane == "R")
                  {
                     charges = 1.40 * gallons;
                     return charges;
                  }
                     if (grade =="U") && (octane == "S")
                     {
                        charges = 1.50 * gallons;
                        return charges;
                     }
                     else
                        if (grade == "U") && (octane == "G")
                        {
                            charges = 1.75 * gallons;
                            return charges;
                         }
    }
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Advice: Keep everything private unless it "has" to be public, particularly data members. That way the class has greater control over what can happen to it.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  3. Creating threads from a class
    By Niara in forum C++ Programming
    Replies: 2
    Last Post: 06-02-2006, 03:52 PM
  4. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  5. Creating a string class
    By incognito in forum C++ Programming
    Replies: 2
    Last Post: 01-19-2002, 05:40 PM