Thread: Help Wanted :)

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    3

    Help Wanted :)

    Hey guys, I need a little help


    1. Write a class "Bulb" which has a private member - type bool!- "Balance", default constructor which sets the state to FALSE and public methods "PushTheButton" that will turn on and off the lamp and "Check" which will print out "Light" or "Dark" depends on the current state (0-dark, 1-light). Create an object "Turning" of class "Bulb" and turn it on and off several times.

    2. Write a class "Employees" which has private data members: "path", "age" and "wages". Write constructor which initialized data members while creating a object. Write destructor which print out "Destructor employees - fired". Write an access method that can change some of the data members and methods that can get their value. Write a "friendly" function that calculates how much
    employee has earned.
    Note: the function accepts a reference to an object of class "Employees".
    You need to calculate how much employee earned during his work
    (months*number of working years*wages)
    Last edited by VioletGirl; 11-20-2011 at 05:56 PM.

  2. #2

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    3
    yup, i missed that part.. i'm one of those people who don't read rules but anyway, it makes more fun if you do by yourself and btw, i didn't need for homework or something like that..i was just interested how would someone else do the same program.


    Code:
    #include <iostream>
    using namespace std;
    
    class Bulb{
        
          private:
                   bool Balance;
          public:
             Bulb(){Balance=false;};
                 void PushTheButton (){
                 Balance=!Balance;
              }
                 void Check (){
                      if (!Balance)
                         cout<<"Dark!"<<endl;
                      else
                           cout<<"Light!"<<endl;
                 }
    };
    
    int main (){
        bool Balance;
     
    
        Bulb Turning;
        Turning.PushTheButton();
        Turning.Check ();
        Turning.PushTheButton();
        Turning.Check ();
        
        system ("pause");
        return 0;
    }



    Code:
    #include <iostream>
    using namespace std;
    
    class Employees{
       friend float Earning (Employees&);
    private:
       float path;
       float age;
       float wages;
    public:
       Employees (float,float,float);
       ~Employees();
       float Path(){return path;}
       float Age () {return age;}
       float Wages () {return wages;}
    };
    
    float Earning (Employees &earned){return (earned.path*earned.age*earned.wages);}
       
    //constructor 
      Employees::Employees(float Path,float Age, float Wages){
         path=Path;
         age=Age;
         wages=Wages;
      }
    
    //destructor
      Employees::~Employees (){
         cout<<"Destructor employees  - fired!"<<endl;
      }
    
      int main (){
    
         Employees A(12,5,3000);
    
       cout<<"Employee has earned:"<<Earning (A)<<endl;
       
    
        system ("pause");
        return 0;
    
      }

    and btw, sorry for my "not reading"

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Uh hu. You might want to read this recent thread.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    3
    1. i'm not a boy
    2. yes,i'm student on faculty for electrical engineering , branch - computer engineering.
    3. google.com is my best friend.
    4. believe it or not - i didn't come to beg for my homework or don't know what
    5. "hey guys, i need a little help" - i should use another words, then maybe you wouldn't think that i come to beg
    6.. all in all , i don't know why i'm typing all this things, when you will think so or so what do you want to think, AND when you wont reconsider about any other solutions

  6. #6
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    Quote Originally Posted by VioletGirl View Post
    i was just interested how would someone else do the same program.
    Since those are two specific exercises, I don't think anyone could code them otherwise, except from "main()" and indentation, that is.
    Devoted my life to programming...

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Bulb looks OK, except for indentation. One thing, though. CheckButton should be const.

    For Employees, you should have a look at this.
    Earning also does not need to be a friend function for the class. It can simply use the public interface to get the required data. It should also take a const reference instead of a reference. Public interface get functions should be const. Indentation should also be fixed.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by VioletGirl View Post
    1. i'm not a boy
    OK. Just bear in mind that there are a fair few boys who try to elicit homework answers by pretending to be girls.

    There are also some pretty good female programmers around here, but I won't deny them the right of introducing themselves as they see fit.

    Quote Originally Posted by VioletGirl View Post
    2. yes,i'm student on faculty for electrical engineering , branch - computer engineering.
    A female electrical engineer, eh? A rare beast, but hopefully one becoming less rare.

    Quote Originally Posted by VioletGirl View Post
    3. google.com is my best friend.
    My condolences. My two best friends are a person and a dog. Incidentally, both are female.

    Quote Originally Posted by VioletGirl View Post
    4. believe it or not - i didn't come to beg for my homework or don't know what
    5. "hey guys, i need a little help" - i should use another words, then maybe you wouldn't think that i come to beg
    It will probably help if, as you learn, you also give something back. Even if your advice to others isn't perfect, the attempt is important (even the most knowledgeable folks here get it wrong sometimes, and are picked up by someone else).

    The attempt to help someone is often the best way that you can learn too.

    Quote Originally Posted by VioletGirl View Post
    6.. all in all , i don't know why i'm typing all this things, when you will think so or so what do you want to think, AND when you wont reconsider about any other solutions
    The question you were given is pretty specific. There isn't much scope for considering other solutions.

    If you want people to really look at options, don't nail down your question so much.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help wanted
    By reticulatus in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 11-22-2009, 05:03 PM
  2. NAQ: Everything you never wanted to know about CPP
    By evildave in forum C Programming
    Replies: 21
    Last Post: 12-12-2005, 10:56 AM
  3. I just wanted....
    By ILoveVectors in forum C++ Programming
    Replies: 0
    Last Post: 06-22-2005, 09:29 PM
  4. *Wanted*
    By TeQno in forum C++ Programming
    Replies: 2
    Last Post: 07-21-2003, 03:11 AM