Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the three functions (Square, Multiply, and Divide) required for the following C++ program. Square and Multiply will return the result to the calling program

Write the three functions (Square, Multiply, and Divide) required for the following C++ program. Square and Multiply will return the result to the calling program and will also call PrintResult to display the answer. If successful, Divide will return a 1, set the value of the result and the remainder into the appropriate parameters, and call PrintResult twice (once for result and once for remainder). If Divide is not successful, it will return a 0 and call PrintResult to display the failure message. Link them to the above program to demonstrate their functionality.

The C++ Project is:

#include

using namespace std;

enum ResultCode {ShowSquare, ShowMultiply, ShowDivide, ShowRemainder, ShowDivideFailure};

enum SuccessCode {Failure, Success};

extern "C" SuccessCode Divide (long, long, long &, long &);

extern "C" long Multiply (long, long);

extern "C" void PrintResult (ResultCode, long);

extern "C" long Square (long);

void main ()

{

long Num1;

long Num2;

long Result;

long Remainder;

do

{

cout << "Enter Number to Square" << endl;

cin >> Num1;

Result = Square (Num1);

cout << "Square is: " << Result << endl;

cout << "Enter two numbers to multiply" << endl;

cin >> Num1 >> Num2;

Result = Multiply (Num1, Num2);

cout << "Result of multiply is: " << Result << endl;

cout << "Enter mumber to divide into then number to divide by" << endl;

cin >> Num1 >> Num2;

if (Divide (Num1, Num2, Result, Remainder) == Success)

cout << "Result is " << Result << " and remainder is " << Remainder << endl;

else

cout << "Attempted division by zero";

} while (Result > 0);

}

void PrintResult (ResultCode PrintCode, long Value)

{

switch (PrintCode)

{

case ShowSquare:

cout << "Display of square is: " << Value << endl;

break;

case ShowMultiply:

cout << "Display of multiply is: " << Value << endl;

break;

case ShowDivide:

cout << "Display of divide is " << Value << endl;

break;

case ShowRemainder:

cout << "Display of remainder is " << Value << endl;

break;

case ShowDivideFailure:

cout << "Display of Division by zero" << endl;

break;

default:

cout << "Error in assembly routines" << endl;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 19th International Conference Dexa 2008 Turin Italy September 2008 Proceedings Lncs 5181

Authors: Sourav S. Bhowmick ,Josef Kung ,Roland Wagner

2008th Edition

3540856536, 978-3540856535

More Books

Students also viewed these Databases questions