Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercise 5.1 For this experiment you will need to divide into teams of three mem

ID: 3756074 • Letter: E

Question

Exercise 5.1 For this experiment you will need to divide into teams of three members. Each of the three members will be responsible for writing part of the entire program. The program will calculate the product of two natural numbers The first team member needs to write a function that asks the user for a natural number (an integer larger than zero). If the user doesn't enter a natural number the function should print a message and request another number. Loop until user enters an integer greater than zero, then return that value. (Hint: a do-while loop will work well for this function) The natural number is returned by the function . The second team member needs to write a function that accepts two integers as arguments; calculates their product (multiply) and returns the product . The third team member needs to write a function that accepts one integer (the product, calculated in the previous step) as an argument and prints it . The main) program needs to be written to use these three functions. Note: the second two functions are easier to write so the team members in charge of those functions should write the main program as well e Put the names of all three team members in the comment block at the top of the program source . Each function shld ilude a comment block giving the name of the team member who wrote that function To put the program together you will need to place all of the functions in one directory and then combine them into one file. Two of the team members wll need to transfer (email their portion of the program to the person maintaining the whole program All editors allow you to read (load) a file into the current file. Read (copy) the separate function files into the main program file. Note: Don't forget the function declarations (prototypes) at the beginning of the program . Compile and run the program

Explanation / Answer

/* comment block Add your details


*/

#include <iostream>

using namespace std;

int GetNaturalNumber();      //Function decleration of get natural number
int Product(int,int);        // Function decleration of Product function
void PrintResult(int);       // Function decleration of display result
int main()                  // The main function
{
   int Num1,Num2,Prod;        // Variables for the numbers an dproduct6
   Num1 = GetNaturalNumber();    //calling function to get first number
   Num2= GetNaturalNumber();   //Calling function to get second number
   Prod = Product(Num1,Num2);   // Caling function to find the product
   PrintResult(Prod);              // Calling function to print the result

   return 0;
}


/* comment block Add your details


*/
int GetNaturalNumber()
{
    int Number,ext =1;   // Variable to store the narural number
    float TestNum;       // variable to check the floating point No. or Not
        cout<<"Enter a Natural Number"<<endl; //ask to entera number
        cin>>TestNum;    // geting as a floating Number
        Number = TestNum; // converting to integer
    do //loop starts
    {
        if(Number<=0||Number!=TestNum) // checking wether natural Number or not
        {
            cout<<"WARNING: It is not a Natural Number"<<endl;
            cout<<"Please Enter A Natural Number"<<endl; //ask to entera number
            cin>>TestNum;           // getting number
            Number = TestNum;
        }
        else
        {
            ext =0; // exiting the loop if Number is a Natural number
        }
    }while(ext);
    return Number; // function return
}


/* comment block Add your details


*/
int Product(int a,int b)
{
    return a*b; // function return
}


    /* comment block Add your details


    */
    void PrintResult(int a)
    {
        cout<<" The Product is"<<a<<endl; // result printing
    }