Thread: OK. new easy question for you guys.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    25

    OK. new easy question for you guys.

    Code:
    #include <iostream>
    #include <stdlib.h>
    
    class Employee//Class called employee
    {
    int Age;
    int YearsOfService;
    int Salary;
    public:
    Employee(): Age(18) ,YearsOfService(1) ,Salary(10000){} // Trying to make default values
    Employee(int initialAge, int initialYearsOfService, int initialSalary); // constructor
    ~Employee(); // destructor
    void SetAge(int age) {ItsAge = age; }
    void SetYearsOfService(int YearsOfService) {ItsYearsOfService = YearsOfService; }
    void SetSalary(int Salary) {ItsSalary = Salary; }
    
    int GetAge() const { return ItsAge; }
    int GetYearsOfService() const { return ItsYearsOfService ; }
    int GetSalary() const { return ItsSalary; }
    
    private:
    int ItsAge;
    int ItsYearsOfService;
    int ItsSalary;
    };
    
    // Function definitions.
    Employee::Employee (int initialAge,int initialYearsOfService,int initialSalary)
    { 
    ItsAge = initialAge;
    ItsYearsOfService = initialYearsOfService;
    ItsSalary = initialSalary;
    }
    
    Employee::~Employee() // takes no action
    {
    
    }
    
    
    int main()
    {
    Employee JohnFKennedy(36,4,2000);
    Employee Tom;
    
    std::cout<<"\nJohn F. Kennedy's Age is: "<<JohnFKennedy.GetAge();
    std::cout<<"\nJohn F. Kennedy's sallary is: $"<<JohnFKennedy.GetSalary();
    std::cout<<"\nJohn F. Kennedy's Years of service is: "<<JohnFKennedy.GetYearsOfService();
    std::cout<<"\nTom's Age is: "<<Tom.GetAge();
    std::cout<<"\nTom's sallary is: $"<<Tom.GetSalary();
    std::cout<<"\nToms's Years of service is: "<< Tom.GetYearsOfService();
    std::cout<<"\n";
    system("pause");
    return 0;
    }
    OK. The problem. when i create a new object, i want the values to be default. But i get this random number instead. what am i doing wrong?
    Last edited by arnis; 07-17-2003 at 06:47 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 01-02-2006, 04:46 PM
  2. This is hopefully an extremely easy question...
    By rachaelvictoria in forum C Programming
    Replies: 2
    Last Post: 11-07-2005, 01:36 AM
  3. 4 easy question
    By Zeratulsdomain in forum C++ Programming
    Replies: 2
    Last Post: 10-15-2005, 10:43 PM
  4. easy newbie question
    By ioaz in forum C++ Programming
    Replies: 7
    Last Post: 09-24-2003, 03:58 PM
  5. I have a 2 easy question about some homework?
    By correlcj in forum C Programming
    Replies: 3
    Last Post: 07-18-2002, 07:28 PM