Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,147 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,970 people online right now. Registration is fast and FREE... Join Now!




Class and Header files

 
Reply to this topicStart new topic

Class and Header files, contains inline and non inline methods

ghettoMan
post 4 Oct, 2008 - 09:08 AM
Post #1


New D.I.C Head

*
Joined: 20 Sep, 2008
Posts: 11


My Contributions


I have a project that implements my own created header file and my own class. They are simple and just check whether time is correct on a 24 hour clock. the get methods should be inline and the rest are non inline. I am having problems with the get methods in my main file. I believe it should return the value entered but it does not. the set methods seem to be working correctly. they return a bool value if the given integers for minutes and hours are correct . I am just wondering if my get methods are correct or is there another error.

my header file.
CODE

class MyTime
{
    int myMinute, myHour;

public:

    int getHour()
    {
        return myHour;
    
    }
    int GetMinute()
    {
        return myMinute;
    }
    bool setHour(int);
    bool setMinute(int);
    bool setTime(int, int);



};

my implementation file
CODE
#include "MyTime.h"
#include <iostream>
using namespace std;


bool MyTime::setHour(int hr)
{
    if((hr >= 0)  && (hr<=24))
    {
        if(hr ==24)
            myHour = 0;

        hr = myHour;
        return true;
    }
    else
    {
        myHour = 0;
        return false;
        
    }
}

bool MyTime::setMinute(int min)
{
    if((min >=0) && (min <=59))
    {
        min = myMinute;
        return true;
    }
    else
    {
        myMinute = 0;
        return false;
    }
}

bool MyTime::setTime(int min,int hr)
{
    if(((min >=0) && (min <=59)) && ((hr >= 0)  && (hr<=24)))
    {
        if(hr ==24)
            myHour = 0;

        min = myMinute;
        hr = myHour;
        return true;
    }
    else
    {
        myMinute = 0;
        myHour = 0;
        return false;
    }
}

my main file
CODE
#include <iostream>
#include "MyTime.h"
using namespace std;

void main ()
{
    bool mins, hrs, time;
    int xm, xh;
    MyTime T;

    cout<<"Enter hour "<<endl;
    cin>>xh;
    cout<<endl<<"Enter minute "<<endl;
    cin>>xm;




    mins = T.setMinute(xm);
    hrs = T.setHour(xh);

    time =T.setTime(xm,xh);

    cout<<endl<<" Hour "<< hrs << " Mins " << mins <<endl;
    cout<<" Time " << time <<endl;


}


This post has been edited by ghettoMan: 4 Oct, 2008 - 09:09 AM
User is offlineProfile CardPM

Go to the top of the page

Sadaiy
post 4 Oct, 2008 - 09:43 AM
Post #2


New D.I.C Head

*
Joined: 3 Oct, 2008
Posts: 35



Thanked 1 times
My Contributions


your set functions are wrong, hr = myHour; should be myHoud = hr; and you made that mistake more than once all over the place
User is online!Profile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/21/08 01:06PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month