CIS 2003 - Introduction to C++ and C
Programming
Bob Comer, Professor, CIS/CSC
Assignment 2 - Circle Calculations
Read through Chapter 2 in your textbook before starting this assignment.
Write a C++ program that will calculate and print the diameter, circumference, or area of a circle depending on a command entered by the user. The commands are:
If the user enters 'D', 'C', or 'A', your program should input a radius for the circle from the user. Your program should have a loop to allow multiple calculations.
Formulas and constants
diameter = 2 x radius
circumference = 2 x pi x radius
area = pi x radius x radius
use 3.14159 for pi
Error Checking
Your program should check for invalid commands. If the user enters a command other than 'D', 'C', 'A', or 'E', print an appropriate error message and continue with the next command.
Sample Program Dialog
Your screen dialog should look similar to this (user input is shown in bold). You should format your output to display 2 digits to the right of the decimal point for all floating-point numbers.
Circle
Calculations Program Commands: D - print circle diameter C - print circle circumference A - print circle area E - end the program Enter a command: C Enter circle radius:1.5 A circle with radius 1.50 has circumference 9.42. Enter a command: D Enter circle radius: 2 A circle with radius 2.00 has diameter 4.00. Enter a command: E |
Program Notes/Hints
Copyright: Ó1999,
2000 by the Austin Community College
Department of Computer Studies. All rights reserved.
Comments to: Bob
Comer
Last updated: February 1, 1999