Assume number1 = 56 and number2 = 12 and are passed to the following function //
ID: 3669489 • Letter: A
Question
Assume number1 = 56 and number2 = 12 and are passed to the following function
//************************************************************************************/
//
// FloatCompare
//
// Description:Accepts two float numbers and compares them bitwise based
// on floating point representations. This function will have
// to convert the given numbers into IEEE floating
// representation and then do bitwise comparison
// Preconditions:two input arguments are passed
// Postconditions:Returns 1,-1 or 0 based on the comparison
// 1 if number1>number2
// -1 if number2>number1
// 0 if equal
// Calls: N/A
// Called by: main
//
//***********************************************************************************/
int FloatCompare(float number1,float number2)
Explanation / Answer
main.cpp
#include <iostream>
using namespace std;
// function declaration
int FloatCompare(float number1,float number2);
int main ()
{
// local variable declaration:
float number1;
float number2;
int comparison;
number1=56;
number2=12;
// calling a function to get max value.
comparison=FloatCompare(number1,number2);
if (comparison==1) cout << "number1 is greater than number2";
else if (comparison==-1) cout << "number2 s greater than number1";
else if (comparison==0) cout << "Number are equal";
else cout << "Error ";
return 0;
}
// function returning the max between two numbers
int FloatCompare(float number1,float number2)
{
// local variable declaration
int result;
if (number1 > number2)
result = 1;
else if (number1 < number2)
result = -1;
else if (number1 = number2)
result = 0;
return result;
}
Output :
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.