I am currently frustrated with the current problems from my assignments and not sure how to do the following.
1 2 3 4
bool IsAnInt( float a ); // Returns true if a is an integer, else false. i.e. -2.0 is true, -2.1 is false.
float Sin( float a ); // Use the following truncated Taylor series to approximate Sin(a): Sin(a) = a – a3/6 + a5/120 – a7/5040. Sin(0)=0; Sin(PI/2)=1; Sin(PI/6)=0.5.
float Cos( float a ); // Find the Taylor series for Cosine, and use the four term truncated Taylor series to approximate Cos(a). Cos(0)=1; Cos(PI/3)=0.5; Cos(PI/2)=0;
char toUpper( char a ); // If the passed character is a lower-case letter, returns the corresponding upper-case letter; else, returns the passed character unchanged.
For the first one,
bool IsAnInt( float a ); // Returns true if a is an integer, else false. i.e. -2.0 is true, -2.1 is false.
I tried isdigit but I am not sure how to put it in the way I want it. Such as my completed ones that look like this.
1 2 3 4 5 6 7 8 9 10
int main()
{
//Rounding
cout << endl << "int Round( float a ); // Rounds a to the nearest integer.\n";
cout << "The interger 4.5 rounds to " << Round(4.5) << '\n'; //Outputs 5
}
int Round(float a)
{
returnint(a+0.5);
}
Firstly, you did not put much thought in the assignment or tried to do the work. Secondly, thanks for being honest and saying you have trouble with your assignment. bool IsAnInt( float a ); // Returns true if a is an integer, else false. i.e. -2.0 is true, -2.1 is false. you would need a if statement as it say return true if number is equal to integer and false if number is not equal to integer. So what do you think? how would you start of the code? Good Luck.
int main()
{
cout << endl << "bool IsAnInt( float a ); // Returns true if a is an integer, else false. i.e. -2.0 is true, -2.1 is false.\n";
cout << "The boolean of 2.5 is " << IsAnInt(2.5) << endl;
return 0;
}
bool IsAnInt( float a )
{
if (isdigit(a))
{
cout << " False";
returntrue;
}
else
{
cout << " True";
returnfalse;
}
}
As its late my brain is on sleep mode. Is that how you think the assignment should be like? I cannot help cause of less information I need to know more on what you need to do on the first one or that how its need be?
i assume that this test is all about checkingi f a float is a whole number ( by this we mean if it is something like 4.000 as opposed to something like 4.198) then
this should do it.
It is laid out is a nice easy to follow fashion: