Im having trouble with an assignment where I have to convert three variables of a clock (int hour, int minutes, and bool afternoon) to be converted to a string in a method. I tried converting the int to a char and then replacing each string with the char. The function is suppose to return T/F if the conversion worked or not. Here is what I have so far:
class Time { private: int hour; int minutes; bool afternoon; public: void setHour(int hr); void setMinutes(int min); void setAfternoon(bool aft); int getHour(); int getMinutes(); bool getAfternoon(); bool setAsString(string time); string getAsString(); Time(void); ~Time(void); }; and
bool Time::setAsString(string time){ char min = minutes; char hr = hour; char hr[0] = time[0]; char hr[1]= time[1]; char min[0] = time[3]; char min[1] = time[4]; char afternoon = time[6]; if ((hourTens > 1) || (minTens > 5)) { return false; } else { return true; } } string Time::getAsString(){ return false; }
atoianditoafunctions'1' - '0'? What is1 + '0'? 2)/ 10divided by 10,% 10gets the remainder you'd get from dividing by 10 (e.g. whatever is in the units column) Now you know enough to solve the problem.int intday = 15; string strDay = "00"; char day = intday + '0'; strDay[1] = intDay[1];'1' - 0is'1'but'1' - '0'is different.