homework assignment 5
DESCRIPTION
Homework Assignment 5TRANSCRIPT
Lawrence Technological UniversityDepartment of Mathematics and Computer Science
MCS 1142 Introduction to C – Fall 2008
This homework assignment builds on the previous assignments. In the last assignment you used function calls to generate circumference and area of circles with radii 5, 10, and 6.3 units. For this assignment we will continue the same work but will put the if statement inside a loop. Details are below:
Use a C loop construct (do, for, do … while) to print the radius, circumference and area for each circle. For this exercise it is ok to assume that the loop will have to be executed 3 times. The generalized structure for the loop is shown below
loop_counter = 0begin loop
increment loop_counterif statement for printing radius, circumference and areaif loop_counter >= 3
exit loopend loop
Continue using the if … else statement from your last assignment inside the loop. However generalize the statement so that it will work for all radii. It should have the following form:
// Calculate and print circumference and area for the circle.printf("Circle %d radius: \t\t%6.2f\n", loop_counter, rad);if (rad == 5){
printf("Circle %d circum: \t\t%6.2f\n", loop_counter, calcCircum(rad));printf("Circle %d area: \t\tNot Calculated\n\n", loop_counter);
}else if (rad == 10){
printf("Circle %d circum: \t\tNot Calculated\n", loop_counter);printf("Circle %d area: \t\t%6.2f\n\n", loop_counter, calcArea(rad));
}else{
printf("Circle %d circum: \t\tNot Calculated\n", loop_counter);printf("Circle %d area: \t\tNot Calculated\n\n", loop_counter);
}
Please note you will only need to include one such if statement because it is generalized to work for all loops.
The output should have the following format:
Circle 1 radius: ###.##Circle 1 circumference: ###.##Circle 1 area: ###.##
Circle 2 radius: ###.##Circle 2 circumference: ###.##Circle 2 area: ###.##
Circle 3 radius: ###.##Circle 3 circumference: ###.##Circle 3 area: ###.##
Please note that the circles don’t have to be listed in this order. For example, you could print circle with radius 6.3 first.
Try several test runs with the order of the radii changed. Start with order 5, 10, and 6.3 then revise the order and run it again. This will help verify that your if … else statements work for all radii.
Don’t forget the following program head for all programs submitted for grading.
// Program Author: Your name// Student ID: xx000012345// Email Address: [email protected]// Name of Program: Name of Program.c// Program Due Date: MM-DD-YY// Objective: The Instructors description of the programming
assignment// Program Description: The Students description of how the program works// Honor Code: I have neither given nor received unauthorized aid in // completing this work, nor have I presented someone else's // work as my own!
Enjoy!