Please write in C++ Write a function void sum (int num1, int num2, int diff, int
ID: 3703593 • Letter: P
Question
Please write in C++
Write a function void sum (int num1, int num2, int diff, int prod) which finds the sum and difference of num1 and num2. If any of the parameters should be reference parameters, modify the heading appropriately.
void sum (int num1, int num2, int diff, int prod)
{
}
Write a function void sum (int n) which reads n numbers and prints the sum of the numbers.
void sum (int n)
{
}
Write a value-return function which accepts the cost of an item (price) and the amount paid by a customer (amount_paid) as parameters. The function must calculate the amount of change the customer is owed and return that value.
double change (double price, double amountPaid)
{
}
Write a void function which accepts two integers (a and b) as parameters and does at least one of the following based on the values of a and b :
prints "The numbers are equal" if a and b are equal,
prints "a is greater than b" if a is greater than b, or
prints "b is greater than a" if b is greater than a.
void evaluateNumbers (int a, int b)
{
}
Explanation / Answer
int sum(int num1, int num2, int& diff, int& prod)
{
diff = num1-num2;
prod = num1*num2;
return num1+num2;
}
void sum(int n)
{
int sum=0;
int number;
while(n>=0)
{
cin>>number;
sum+=number;
n--;
}
cout<<sum;
}
double change (double price, double amountPaid)
{
return amountPaid-change;
}
void evaluateNumbers (int a, int b)
{
if(a==b)
cout<<"The numbers are equal";
else if(a>b)
{
cout<<"a is greater than b";
}
else
{
cout<<"b is greater than a";
}
}