Thread: trouble with objects

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    78

    trouble with objects

    ok folks check this out I actually got my first program with objects to run buuut it keeps giving me this funky output check out the code
    Code:
    #include <iostream.h>
    #include <iomanip.h>
    
    //class declaration
    
    class Time
    {
    private:
    	int hrs;
    	int mins;
    	int secs;
    public:
    	Time(int=12.0, int=00, int=00); //constructor function with defaults
    	void settime(int, int, int); //member function to copy a date
    	void showtime(void);
    };
    
    //implementation section
    
    Time::Time(int hours, int minutes , int seconds)
    {
    	hours=hrs;
    	minutes=mins;
    	secs=seconds;
    }
    
    void Time::settime(int hours, int minutes , int seconds)
    {
    	hours=hrs;
    	minutes=mins;
    	secs=seconds;
    return;
    }
    
    void Time::showtime(void)
    {
    cout<<"The time is";
    cout<< setfill('0')
        <<setw(2) << hrs << ":"
    	<<setw(2) << mins << ":"
    	<<setw(2) << secs ; 
    cout<<endl;
    return;
    }
    int main()
    {
    	Time a, b, c(13, 4, 0);
    
    	b.settime(12,25,2);
    
    	cout<<endl;
    
    	a.showtime();
    	b.showtime();
    	c.showtime();
    
    	cout<<endl;
    
    	return 0;
    }
    anyways here is the output


    The time is-858993460:-858993460:00
    The time is-858993460:-858993460:02
    The time is-858993460:-858993460:00

    Press any key to continue

    anyone got any ideas where I went wrong

  2. #2
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    Code:
    Time::Time(int hours, int minutes , int seconds)
    {
    	//hours=hrs;
    	hrs = hours;
            //minutes=mins;
            mins = minutes;
    	secs=seconds;       
    }
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    78

    feel the power

    Someone please turn off my retard switch . derrrr

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    19

    trouble with objects

    this is the code

    #include <iostream.h>
    #include <iomanip.h>

    //class declaration

    class Time
    {
    private:
    int hrs;
    int mins;
    int secs;
    public:
    Time(void):hrs(12),mins(0),secs(0){};
    Time(int hours, int minutes, int sec); //constructor function with defaults
    void settime(int, int, int); //member function to copy a date
    void showtime(void);
    };

    //implementation section

    Time::Time(int hours, int minutes , int seconds)
    {
    hrs=hours;
    mins=minutes;
    secs=seconds;
    }

    void Time::settime(int hours, int minutes , int seconds)
    {
    hrs=hours;

    mins=minutes;
    secs=seconds;
    return;
    }

    void Time::showtime(void)
    {
    cout<<"The time is";
    cout<< setfill('0')
    <<setw(2) << hrs << ":"
    <<setw(2) << mins << ":"
    <<setw(2) << secs ;
    cout<<endl;
    return;
    }
    int main()
    {
    Time a, b, c(13, 4, 0);

    b.settime(12,25,2);

    cout<<endl;

    a.showtime();
    b.showtime();
    c.showtime();

    cout<<endl;

    return 0;
    }

  5. #5
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 60
    Last Post: 12-20-2005, 11:36 PM
  2. Question about cout an stack object?
    By joenching in forum C++ Programming
    Replies: 8
    Last Post: 05-08-2005, 10:10 PM
  3. chain of objects within pop framework help needed
    By Davey in forum C++ Programming
    Replies: 0
    Last Post: 04-15-2004, 10:01 AM
  4. array of objects?
    By *~*~*~* in forum C++ Programming
    Replies: 4
    Last Post: 05-31-2003, 05:57 PM
  5. Trouble Understanding Classes and Objects. Please Help.
    By Jeffcubed in forum C++ Programming
    Replies: 4
    Last Post: 12-06-2002, 02:23 PM