Place your mouse in the areas below to see comments about the corresponding sections of code | Code | |
/* A sample program file: 1ex1.cpp ( or used as 1ex1.appended) FALL 1998 ___________________________________ Jacob Y. Kazakia jyk0 July 14, 1998 Programming assignment 1 of week 1 Recitation Instructor: J.Y.Kazakia Recitation Section 01 ___________________________________ Purpose: This program calculates the area of a sector of circle, given the radius of the circle in meters and the angle of the sector in degrees. Algorithm: The area of the entire circle is given by the formula: Area = pi * radius * radius ( here pi = 3.1415927 ) If the sector angle is theta degrees, then its area is: Sector_area = ( theta / 360 ) * pi * radius * radius */ |
||
#include<iostream.h> // header which contains the functions // needed for input and output const float PI = 3.1415927; // No one should be allowed to alter // this important constant void main() { |
||
// variables are typed and defined float radius; //the value of the radius of the circle (meters) float theta; //the angle of the sector (degrees) float area; //the area of the sector (square meters) |
||
// prompt for and read the radius cout<< endl<<"Enter the radius of the circle (in meters) >>>"; cin>>radius; // prompt for and read the sector angle cout<< endl<<"Enter the angle of the sector (in degrees) >>>"; cin>>theta; |
||
// Echo printing ( we must always double check ourselves and // others) cout<<endl<<endl; cout<<"We will now calculate the area of a sector of a circle"<<endl; cout<<"The radius of the circle was given as :"<<radius ; cout <<"meters"<<endl; cout<<"The angle of the sector was given as: "<<theta ; cout <<"degrees"<<endl; |
||
// calculation ( do you really need a computer for this? ) area = (theta/360 )* PI * radius * radius; |
||
cout<<endl<<"The area is calculated as : "; cout <<area<< " square meters"<<endl; cout<<endl<<endl; |
||
cout<<" enter e (exit) to terminate the program"; |
(printable file with comments)
© 2001 J.Y. Kazakia. All rights reserved