Tuesday, July 28, 2009

In C++ how do I?

Decimal Point, how do I calculate the number after the decimal point...? Example 10.1 how do I multiply the digit 1 a decimal point...?





float a; //Enter 10.1..


cout %26lt;%26lt; "Enter A Number...? ";


cin %26gt;%26gt; a;





how do I multiply the digit after the decimal point, like 10.1


where 10 is hours and 1 is remainder like minutes, so all i would have to do is 6 times 1 is 10 Hours and 6 Mins.... since 6 times 10 is 60 seconds, so 6 times 1 would be 6 mins...





ive looked everywhere, in my C++ book and even on the internet.. what is the code to multiply, devide, subtract, or add or even work with the digit after teh decimal point...?

In C++ how do I?
You have to create a time class like follows and also you have oveload "+" operator accordingly to add user defined class's object. I am giving you a hint





class time


{


private:


int hour;


int min;


int sec;


public:


void gettime()


{


cout%26lt;%26lt;"Enter hour";


cin %26gt;%26gt;hour;


cout %26lt;%26lt;"Enter min;


cin%26gt;%26gt;min;


cout%26lt;%26lt;"Enter secs";


cin%26gt;%26gt;sec;


}


void showtime


{


cout%26lt;%26lt;"Time ="%26lt;%26lt;hour%26lt;%26lt;"."%26lt;%26lt;min%26lt;%26lt;"."%26lt;%26lt;sec;


}


time operator+(time);





};





time time:: operator +(time t)


{


logic to add hour min sec and increment according to your requirement





}
Reply:/* I am getting what you are saying. It's like you want get the remainder, right?Try this. Then send me a message if this will not work. */





#include%26lt;iostream.h%26gt;


#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;





main() {





float num, mins;


int hours = 0;


clrscr();





cout%26lt;%26lt;"Enter number";


cin%26gt;%26gt;num;





while(num%26gt;=1.0) {


num = num - 1.0;


hours++;


}





mins = num * 60.0;





cout%26lt;%26lt;"\n"%26lt;%26lt;hours%26lt;%26lt;" Hours and "%26lt;%26lt;mins%26lt;%26lt;" Minutes";





return 0;


getch();





}


No comments:

Post a Comment