Exercise 14: Calculating A Circle's Diameter, Circumference And Area

Date completed: 13/09/2017

Write a program that reads the radius of a circle (as a double value) and computes and prints the diameter, the circumference and the area. Use the value 3.14159 for Π.

The Code: Circle.cpp

                
/*
 * Circle.cpp
 *
 */

/*
 * (Calculating a Circle‘s Diameter, Circumference and Area) Write a program that reads the
 * radius of a circle (as a double value) and computes and prints the diameter, the
 * circumference and the area. Use the value 3.14159 for pi.
 *
 * The following formulas are used:
 * diameter = 2r
 * circumference = 2*pi*r
 * area = pi*r*2
 *
 */

#include <iostream>     // Allows program to output data to the screen.

using namespace std;

// The function main() begins program execution.
int main() {
    
    // Variable declarations
    double radius;
    double PI = 3.14159;

    cout << "Enter the radius: ";	// prompt the user for the first integer
    cin >> radius;			// read the in the first integer

    // Calculation and output of the variables
    cout << "\n" <<  "The diameter of the circle  is " 
                                                    << 2*radius << "\n" << endl;
    cout << "The circumference of the circle  is " 
                                                 << 2*PI*radius << "\n" << endl;
    cout << "The diameter of the circle  is " 
                                            << PI*radius*radius << "\n" << endl;

    return 0;
} // end of function main

            

Some screen prints

Description Screen Print Out
The output as seen in Eclipse. cpp_s03_ex14 image