Please help with the following C++ questions. Please provide results with commen
ID: 3809660 • Letter: P
Question
Please help with the following C++ questions. Please provide results with comments as how how you derived the answers. If there are no errors in the program, show what will be printed by each of the following programs. If there are any errors in the program explain what is wrong.
Write a function that returns the cost of mailing a package, given the weight of the package in pounds and ounces, and a cost per ounce. Recall that there are a pound at these values will be passed to the function 16 ou means th as paramete given 4. rite a prototype for your function in the previous question. atements to read in the weight of a package (in pounds es), and the cost per ounce fo mailing. Then cal you function to calculate the mailing cost, and print the mailing cost. ise the function prints NO rite a function checkeven which receives 3 integer variables and prints receives" means YES if all three numbers are even otherw that these values will be passed to the function as parameters) Write a prototype for the checkeven function. 8. rite the statements to read in three numbers and call the checkeven function 9. rite another version of the checkeven function. This version receives 3 integer variables and returns true if all three numbers are even. Otherwise, the function returns false 10 rite a prototype for the new version of the even function 11 rite the statements to read in three numbers and call the checkeven function. Then print YES if all three numbers were even or print NO if they were not all evenExplanation / Answer
Questions: 1 - 5: The following program is the required one for you for the questions 1 - 5.
#include<iostream>
using namespace std;
//I'm assuning weight say 8.8 pounds , means 8.8 * 16= 140.8 ounces
//cpo _ cost per ounce
double calc_cost(double weight, double cpo)
{
return cpo * weight * 16;
}
int main(void)
{
double cpo, weight;
cout<<"Enter the weight of the package:";
cin>>weight;
cout<<"Enter cost per ounce:";
cin>>cpo;
cout<<"Cost of mailing the package:"<<calc_cost(weight,cpo)<<endl;
return 0;
}
Output:
Enter the weight of the package:8.8
Enter cost per ounce:12
Cost of mailing the package:1689.6
Questions 6-10: The following is the code for both functions checkeven1 and checkeven2
#include<iostream>
using namespace std;
//This functions prints YES if all the three numbers
//are even otherwise prints NO
void checkeven1(int a,int b, int c)
{
if(a%2==0 && b%2==0 && c%2==0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
//This functions returns true if all the three numbers
//are even otherwise false
bool checkeven2(int a,int b, int c)
{
if(a%2==0 && b%2==0 && c%2==0)
return true;
else
return false;
}
int main(void)
{
int a,b,c;
cout<<"Enter three numbers:";
cin>>a>>b>>c;
checkeven1(a,b,c);
if(checkeven2(a,b,c))
cout<<"True"<<endl;
else
cout<<"False"<<endl;
return 0;
}
Output:
Enter three numbers:2 4 6
YES
True
$ ./a.out
Enter three numbers:2 4 5
NO
False