Week 1 Homework
Part 1: Complete the following problems.
1. A) Write a function in C++ to the following specifications:
Function name: even
Return type: bool
Parameter list: int n
Statements in the body: if (n % 1 == 0) return (true); else return (false);
B) What do you think the purpose of function? Write appropriate comments into the function to reflect this purpose.
C) Draw a corresponding flow chart that reflects the steps in the functions.
D) Write a program that includes this function. The main function should call the “even” function two times once with 232 as the argument and the second time with 137. The main function should include statements to display the return the values from the “even” function along with appropriate labels.
2. Suppose that the cost of sending an international fax is calculated as follows: Service charges $3.00; $0.20 per page for the first 10 pages; and $0.10 for each additional page. Design an algorithm that asks the user to enter the number of pages to be faxed. The algorithm then uses the number of pages to be faxed to calculate the amount.
Inputs:
Const Double serviceCharge = 3.00
Const Double perpageCostForFirst10Pages
Const double perpagecostforadditionalpages
Int numOfPages;
Outputs:double Cost of fax
Processes: Prompt for and read numOfPages, Test if numOfPages > 10
3. Bob enters a pizza shop and notices there are three different sizes of pizzas available. Sizes are given as the diameter of the pizza in inches. The cost of a pizza is based on the size. Bob would like to know which size of pizza has the lowest cost per square inch.
a. Identify the inputs and outputs for this problem.
b. Identify the processing needed to convert the inputs to the outputs.
c. Design an algorithm in pseudocode to solve this problem. Make sure to include steps to get each input and generate each output.
Part 2: Complete the