Computing the Factorial of a Number Using Three Separate Functions (Coursework Sample)
write a program that will compute the factorial of a number using three separate functions.
Function 1 is to get the data from the user so we call it getInput().
Function 2 is to compute the factorial of the number we call it
factorial ().
Please use your favorite Compiler/IDE to
type the below program, compile,, link and generate the
executable file ‘factorial’. Then, submit both the source code and
the output in a PDF file for your Assignment-4 on Chapter-4.
Below is my version that did on my Linux server, and I
demonstrated it to you all, please feel free to make changes as you
like, test it and make sure it is working completely before you
submit it. Please don’t forget to update it with your name and the
date you work on it
Assignment 4 on Chapter 4
27th October 202
/*
This program will compute the factorial of a number using three separate functions.
Function 1 is to get the data from the user so we call it getInput().
Function 2 is to compute the factorial of the number we call it
factorial ().
*/
#include
using namespace std;
// All 3 Functions Prototype and Declaration goes here (lines 15,18,and 21 )
int getInput(int &number);
// The function getInput will read the number from the user.
// Will return the number if it was valid input (int)
double factorial(int &number);
int main()
{
double fact;
int number;do
{
getInput(number);
cout << factorial(number) << endl;
} while ( number != -1 );
return 0;
}
// getInput() function definition
int getInput(int &number)
{
cout << "Please enter a number, or enter '-1' to exit: ";
cin >> number;
if (! (cin.good()))
{
cout << "Please enter a number, or enter '-1' to exit: ";
cin.clear();
cin.ignore(INT8_MAX, '\n');
cin.sync();
cin >> number;
}
return (number);
}
// Definition for factorial function
double factorial(int &number)
{
double fact = 1;
// number! = (number -1 ) * number
//cout << "Inside the fac
Other Topics:
- How the CIA Triad can Protect the Organization’s Information?Description: Through the Confidentiality, Integrity, and Availability principles the triad helps to ensure sensitive information is prevented from unauthorized access, the data is correct, authentic and reliable and most importantly, it ensures systems, applications and data are available and accessible to authorized ...2 pages/≈550 words| No Sources | APA | IT & Computer Science | Coursework |
- Understanding Basic Cloud Computing Terms and CasesDescription: Platform as a Service is a cloud computing model that involves with the provision of hardware entities and software resources to users to enable them build and implement applications on the cloud platform. The model is evident both for the Windows operating systems and the linux-based solutions. List the ...2 pages/≈550 words| 2 Sources | APA | IT & Computer Science | Coursework |
- An Investigation on Mobile Cloud Computing Concepts and TaxonomyDescription: Mobile cloud computing (MCC) is a highly discussed topic attracting a range of participants in software development. Organizations such as Google, Apple, and Microsoft have entered the development of these cloud services. A majority of these ...7 pages/≈1925 words| 12 Sources | APA | IT & Computer Science | Coursework |