ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#include <iostream.h>
class Time
{
private:
int hours;
int minutes;
int seconds;
void setHour(int h);
void setMinute(int min);
void setSecond(int sec);
void setTime(int hour, int minute, int second);
public:
Time() {setTime(0,0,0); Time myTime(4, 21, 4), yourTime(3,2,24);}
void printStandard();
void printMilitary();
};
void Time::setHour(int h)
{
hours = (h >= 0 && h < 24) ? h : 0;
}
void Time::setMinute(int min)
{
minutes = (min >= 0 && min < 60) ? min : 0;
}
void Time::setSecond(int sec)
{
seconds = (sec >= 0 && sec < 60) ? sec : 0;
}
void Time::setTime(int hour, int minute, int second)
{
setHour(hour);
setMinute(minute);
setSecond(second);
}
void Time::printStandard()
{
//print leading zeroes; for example 03, not just 3
cout << "The Time is " << ( hours > 12 ? hours-12 : hours) << ":"
<< ( minutes < 10 ? "0" : "") << minutes << ":" << ( seconds < 10 ? "0" : "") << seconds << ( hours < 12 ? " am" : " pm") <<endl;
}
void Time::printMilitary()
{
//print leading zeroes; for example 03, not just 3
cout << "The Time is " << ( hours < 10 ? "0" : "") << hours << ":"
<< ( minutes < 10 ? "0" : "") << minutes << ":" << ( seconds < 10 ? "0" : "") << seconds << endl;
}
void main()
{
myTime.printStandard();
yourTime.printMilitary();
}
That is what i have now andit still does not work.
Errors:
line 14 could not find a match for 'Time::Time(int,int,int)' in Function Time::Time()
line 14 could not find a match for 'Time::Time(int,int,int)' in Function Time::Time()
line 65 Undefined symbol 'myTime' in function main()
line 65 Undefined symbol 'yourTime' in function main()
What am i todo i am getting lost from all this help and explaining and showing of bits of code and not others. Can someone show what needs to be done to get this to work.
Thanks
Tim
This code is working . I compiled with UNIX
#include <iostream.h>
class Time
{
private:
int hours;
int minutes;
int seconds;
void setHour(int h);
void setMinute(int min);
void setSecond(int sec);
void setTime(int hour, int minute, int second);
public:
Time(int x=0,int y=0,int z=0) {setTime(x,y,z);
}
void printStandard();
void printMilitary();
};
void Time::setHour(int h)
{
hours = (h >= 0 && h < 24) ? h : 0;
}
void Time::setMinute(int min)
{
minutes = (min >= 0 && min < 60) ? min : 0;
}
#include <iostream.h>
class Time
{
private:
int hours;
int minutes;
int seconds;
void setHour(int h);
void setMinute(int min);
void setSecond(int sec);
void setTime(int hour, int minute, int second);
public:
Time() {setTime(0,0,0); Time myTime(4, 21, 4), yourTime(3,2,24);}
void printStandard();
void printMilitary();
};
void Time::setHour(int h)
{
hours = (h >= 0 && h < 24) ? h : 0;
}
void Time::setMinute(int min)
{
minutes = (min >= 0 && min < 60) ? min : 0;
}
void Time::setSecond(int sec)
{
seconds = (sec >= 0 && sec < 60) ? sec : 0;
}
void Time::setTime(int hour, int minute, int second)
{
setHour(hour);
setMinute(minute);
setSecond(second);
}
void Time::printStandard()
{
//print leading zeroes; for example 03, not just 3
cout << "The Time is " << ( hours > 12 ? hours-12 : hours) << ":"
<< ( minutes < 10 ? "0" : "") << minutes << ":" << ( seconds < 10 ? "0" : "") << seconds << ( hours < 12 ? " am" : " pm") <<endl;
}
void Time::printMilitary()
{
//print leading zeroes; for example 03, not just 3
cout << "The Time is " << ( hours < 10 ? "0" : "") << hours << ":"
<< ( minutes < 10 ? "0" : "") << minutes << ":" << ( seconds < 10 ? "0" : "") << seconds << endl;
}
void main()
{
myTime.printStandard();
yourTime.printMilitary();
}
That is what i have now andit still does not work.
Errors:
line 14 could not find a match for 'Time::Time(int,int,int)' in Function Time::Time()
line 14 could not find a match for 'Time::Time(int,int,int)' in Function Time::Time()
line 65 Undefined symbol 'myTime' in function main()
line 65 Undefined symbol 'yourTime' in function main()
What am i todo i am getting lost from all this help and explaining and showing of bits of code and not others. Can someone show what needs to be done to get this to work.
Thanks
Tim
I do a pologize. I dono how the smily face came in, but instead of the smily face just put the letter p.
Abid
I do a pologize. I dono how the smily face came in, but instead of the smily face just put the letter p.
Abid
It's because you had ":p". If you want to show things like that, then select the "Disable smileys in text" option below. Edit: also, please use code tags as it helps make your code more readable.
#include <iostream.h>
class Time
{
private:
int hours;
int minutes;
int seconds;
void setHour(int h);
void setMinute(int min);
void setSecond(int sec);
void setTime(int hour, int minute, int second);
public:
Time(int h = 0, int min = 0, int sec = 0) {setTime(h, min, sec);}
void printStandard();
void printMilitary();
};
void Time::setHour(int h)
{
hours = (h >= 0 && h < 24) ? h : 0;
}
void Time::setMinute(int min)
{
minutes = (min >= 0 && min < 60) ? min : 0;
}
void Time::setSecond(int sec)
{
seconds = (sec >= 0 && sec < 60) ? sec : 0;
}
void Time::setTime(int hour, int minute, int second)
{
setHour(hour);
setMinute(minute);
setSecond(second);
}
void Time::printStandard()
{
cout << "The Time is " << ( hours > 12 ? hours-12 : hours) << ":"
<< ( minutes < 10 ? "0" : "") << minutes << ":" << ( seconds < 10 ? "0" : "") << seconds << ( hours < 12 ? " am" : " pm") <<endl;
}
void Time::printMilitary()
{
cout << "The Time is " << ( hours < 10 ? "0" : "") << hours << ":"
<< ( minutes < 10 ? "0" : "") << minutes << ":" << ( seconds < 10 ? "0" : "") << seconds << endl;
}
void main()
{
Time myTime(4, 21, 4), yourTime(3,0,0);
myTime.printStandard();
yourTime.printMilitary();
}
there it is figured it out with help from everyone here i am positive this is the way my teacher wants the program to be. Itis a little different from what everyone on here has suggested but all your help got me to this point.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.