A fraction-handling program contains this menu:
A. Add two fractions
B. Convert a fraction to decimal
C. Multiply two fractions
Q. Quit
a.Write C++ code for the program with stub functions for the choices.
b.Insert the Fraction To Decimal()function from Questions into the code with
commands to pass and display t he parameters.
1
Expert's answer
2013-04-03T09:53:07-0400
#include <iostream> using namespace std;
double FractionToDecimal (double numerator, double denominator) { return denominator == 0 ? 0 : numerator / denominator; //it's bad to divide by zero }
int main() { & cout << "A. Add two fractions\n" "B. Convert a fraction to decimal\n" "C. Multiply two fractions\n" "Q. Quit\n"; & bool ok_choice = false; & while (ok_choice != true) { char choice; cout << "Please enter your choice: "; cin >> choice; //in OK cases you can insert functions that you need switch (choice) { case 'A': cout << "Add : " << Add() << endl; ok_choice = true; break;
Comments
Leave a comment