Question

In: Computer Science

Create a c++ program to compute the product of two integers. call create the following functions:...

Create a c++ program to compute the product of two integers. call create the following functions:

1. getNum - to accept only positive numbers && will call computeProd.

2.computeProd - to compute the product of the numbers & will call the function displayProduct.

3. displayProduct - to display the product.

Call the function getNum in the main function.

Compute the product w/o using the multiplication operator(*).

using #include <iostream> only

Solutions

Expert Solution

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new cpp program with name "main.cpp" is created, which contains following code.

main.cpp :

//header files
#include <iostream>
using namespace std;
//method to display product
void displayProduct(int product)
{
cout<<"Product of two numbers : "<<product<<endl;
}
//method to compute product of two number
void computeProd(int num1,int num2)
{
//compute product of two numbers
int product=num1*num2;
//call method and pass product of two number
displayProduct(product);
}
//method to accept positive numbers
void getNum()
{
//declaring variables
int num1,num2;
//asking user to enter num1
cout<<"Enter num1 : ";
cin>>num1;//reading num1
//asking user to enter num2
cout<<"Enter num2 : ";
cin>>num2;//reading num2
//checking number
if(num1>0 && num2>0)
{//if both numbers are greater than 0 then
//calling method and passing both numbers
computeProd(num1,num2);
}
else
{
//when any of the number is not positive then
cout<<"Enter both numbers greater than 0"<<endl;
}
}

//main method
int main()
{
//calling method to get two numbers from user
getNum();
return 0;
}

======================================================

Output : Compile and Run main.cpp to get the screen as shown below

Screen 1 :Screen when any of the number is less than 0

Screen 2:Screen showing product of two numbers

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.


Related Solutions

Write a program to compute intersection of two sorted array of integers and compute the CPU...
Write a program to compute intersection of two sorted array of integers and compute the CPU time for different sets of unsigned integers generated by a random number generator. Test this using the same data sets: atleast 3 of size 1000 integers, atleast 3 of size 10000 integers, atleast 3 of size 100000 integers, atleast 3 of one million integers and atleast 3 of size 10 million integers DONT FORGET CPU TIME FOR EACH ONE NO HASH SET
1.Using C++ code, write a program named q4.cpp to compute the product (multiplication) of 4 integers...
1.Using C++ code, write a program named q4.cpp to compute the product (multiplication) of 4 integers a, b, c and d, where a is input by a user via the keyboard, b = 2a - 1, c = ab - 2 and d = |a - b - c|. 2.Using C++ code, write a program named q5.cpp to solve the equation 2n = 14.27 for n. 3.Using C++ code, write a program named q3.cpp to divide each of the elements...
Please C++ create a program that will do one of two functions using a menu, like...
Please C++ create a program that will do one of two functions using a menu, like so: 1. Do Catalan numbers 2. Do Fibonacci numbers (recursive) 0. Quit Enter selection: 1 Enter Catalan number to calculate: 3 Catalan number at 3 is 5 1. Do Catalan numbers 2. Do Fibonacci numbers (recursive) 0. Quit Enter selection: 2 Enter Fibonacci number to calculate: 6 Fibonacci number 6 is 8 Create a function of catalan that will take a parameter and return...
Write a C program with call to functions to produce the output given below. // the...
Write a C program with call to functions to produce the output given below. // the requirements are that there should be 5 files; intList.h, intList.c, hw3.h, hw3.c, and main.c. please only C and use Linked List. thank you. For the 5 different files, he wants it this way: 1) main.c This file just consists of the main() function, which only consists of the displayClassInfo() function call, and the runMenuHw3() function call. 2) intList.h This file would have the IntNode...
create a c++ proram to accept a positive number in the main program. Create and call...
create a c++ proram to accept a positive number in the main program. Create and call the following functions 1. 1. OddorEven -to determine if the number is an odd or even number ( do not use $ or modul opeartor) and will return " even number " or " odd number ". 2. Factorial - to compute the factorial of N. 3. Power - to compute the power of N without using pow function. display the result in the...
Directions: Write a C++ program that will create an array of four integers. It will allow...
Directions: Write a C++ program that will create an array of four integers. It will allow the user to enter in four valid scores and store them in the array. ( valid range is 0 - 100) It will compute the letter grade based upon the four scores, namely, A = 90 - 100, B= 80- 89, C = 70-79, D = 60-69, otherwise F. It will display the scores and letter grade to the screen. NOTE: No menu is...
Write MIPs program that will read two integers from the user and compute for the sum...
Write MIPs program that will read two integers from the user and compute for the sum and difference of the two integers. Ask the user whether he wants to repeat the program : "[Y/y] / [N/n] ?".
Need to create Mortgage Calculator Program In C++ Modify your mortgage to include two functions. A...
Need to create Mortgage Calculator Program In C++ Modify your mortgage to include two functions. A function to get principal, rate, and term. A function to calculate monthly payment. Test your program by getting the data from the user by using the first function and calculate monthly payment by calling the other function. Add version control and write proper comments with a few blank lines & indentations in order to improve your programming style.
Create an Employee class having the following functions and print the final salary in c++ program....
Create an Employee class having the following functions and print the final salary in c++ program. - getInfo; which takes the salary, number of hours of work per day of employee as parameters - AddSal; which adds $10 to the salary of the employee if it is less than $500. - AddWork; which adds $5 to the salary of the employee if the number of hours of work per day is more than 6 hours.
Implement and complement the recursive code to compute the product of two positive integers, x and...
Implement and complement the recursive code to compute the product of two positive integers, x and y, using only addition and/or subtraction. The function will take as its arguments two integers to multiply together ( x x y ) and will return the product. Hint: consider the following: 6 x 1 = 6 6 x 2 = 6 + (6 x 1) 6 x 3 = 6 + (6 x 2) = 6 + [6 + (6 x 1)] =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT