#include <iostream>
#include <cmath>
using namespace std;
double frac2real(int num, int den,int numOffDigit)
{
//variable declaration
double value;
value = (double) num / den;
value = (int)(value * pow(10, numOffDigit) + .5);
value = value / pow(10, numOffDigit);
return value;
}
int main()
{
//variable declaration
int num, den, numOffDigit;
//get input from the user
cout<<"Please enter the numerator and the denominator:
";
cin>>num>>den;
cout<<"Now the number of decimal digits for the real number:
";
cin>>numOffDigit;
//display output
cout<<endl<<"Numerator: "<<num;
cout<<endl<<"Denominator: "<<den;
cout<<endl<<"Fraction = "<<frac2real(num, den,
numOffDigit);
return 0;
}
OUTPUT:

Using C++ 1) Write a function that receives the numerator and denominator of a fraction and...
c++ I am suppose to write a function that gets a number from a user, say 3.123456789 and then the program gets another number from the user which is used to find out how many decimal digits we want rounded to. So if the user inputs 3 then the number would turn into 3.123 then we are suppose to add two digits next to the rounded number so it would turn into 3.12300. the rounding is suppose to be done...
dev
c+
Write the function called simplicity, which makes the denominator and denominator values of the simple fraction sent to it as simple as possible, together with a main function where the denominator and denominator information are entered from the keyboard. Print the values of variables that hold the numerator and denominator values entered from the keyboard before sending them to the function and their changed states after they are sent to the screen. (The global variable should not be...
Write a Fraction class. An example of a fraction is 1/2. Note that C/C++ will convert it to 0.5, but for this problem, it should still be displayed as 1/2. You should have at least the following two private member variables: numerator (top part), and denominator (bottom part). Overload the following operators: ==, +, << and >>. Also, implement the default constructor and a second constructor that takes two arguments for the numerator and the denominator. Make sure the denominator...
In C++ Fix any errors you had with HW5(Fraction class). Implement a function(s) to help with Fraction addition. \**************Homework 5 code*****************************/ #include<iostream> using namespace std; class Fraction { private: int wholeNumber, numerator, denominator; public: //get methods int getWholeNumber() { return wholeNumber; } int getNumerator() { return numerator; } int getDenominator() { return denominator; } Fraction()// default constructor { int w,n,d; cout<<"\nEnter whole number : "; cin>>w; cout<<"\nEnter numerator : "; cin>>n; cout<<"\nEnter denominator : "; cin>>d; while(d == 0)...
Java Write a Fraction class that implements these methods: add ─ This method receives a Fraction parameter and adds the parameter fraction to the calling object fraction. multiply ─ This method receives a Fraction parameter and multiplies the parameter fraction by the calling object fraction. divide ─ This method receives a Fraction parameter and divides the parameter fraction by the calling object fraction. print ─ This method prints the fraction using fraction notation (1/4, 21/14, etc.)...
Problem: Write a short C++ program that gets the side of a cube and the radius of a sphere from the keyboard and writes to a file the surfaces of these shapes. ------------------------------------------------------------------------------------------------------------------------ Your task: implement in C++ the algorithm solution shown below. ------------------------------------------------------------------------------------------------------------------------ Part A (79 points) Algorithm solution (in pseudocode): To accomplish this task, your program will have to take the following steps: 1. Declare a variable named outFile that represents an output stream. 2. Declare a...
C++ Fraction calculator Need help with code, cant use "using namespace std" Objectives Create and use functions. Use a custom library and namespace. Use reference variables as parameters to return values from functions. Create a robust user interface with input error checking. Use exceptions to indicate errors. Resources kishio.h kishio.cpp Assignment requirements You will need eight methods (including main). One is given to you. Their requirements are specified below: menu: The menu function takes no arguments, but returns a char...
Write a C function named date() that receives an integer number of the long date, date form is yyyymmdd, such as 20070412; and the addresses of three variables named month, day, and year. determines the corresponding month, day, and year; and returns these three values to the calling function. For example, if date() is called using the statement longdate=20200411; date(longdate, &month, &day, &year); the number 4 should be returned in month, the number 11 in day, and the number...
C++ Write a function that receives a length in yards, feet, and inches and returns the corresponding measurement in centimeters. (1 in = 2.54001 cm). The function is expected to receive the reference parameters yards, feet and inch. Ask users to enter the number of values for yards, feet and inches, and the function will convert into centimeters once the function is called. Use cout in the main() to display the result.
This in in C# There are two classes, class Fraction and class FractionDemo The user needs to be able to input a value for the numerator and the denominator Create a Fraction class with private fields that hold a positive int numerator and a positive int denominator. In addition, create Properties for each field with the set mutator such that the numerator is greater than or equal to 0 and the denominator is greater than 0 (illegal values should be...