| 0 | kirasiris | Categories: Tags: , , , , , , , , , , , ,


Do you ever wonder how to get the area of a circle using a low-level computer language? Well, C++ is the best one to accomplish said task. Here take a look:

/*
* Question 30 - Quiz number 4
*/
#include <iostream>

using namespace std;

//declaring the rectangle class. this will allow us to eventually make a whole bunch of different rectangles
class Circle
{
	private:
		float radius;
	public:
		void setRadius(float r) { radius = r; }
		const double pi = 3.14159265358979323846;
		float getArea() const { return pi * radius * radius; }
		
};

int main() {
    
    float finalArea;
    
    // First circle
    Circle C1;
    float radius; // 4.5
    cout << "Please enter radius of circle" << endl; cin >> radius;
    C1.setRadius(radius);
    cout << C1.getArea() << endl;
    
    
    // Second circle
    Circle C2;
    float radius2; // 7.4
    cout << "Please enter radius of second circle" << endl; cin >> radius2;
    C2.setRadius(radius2);
    cout << C2.getArea() << endl;
    
    // Area ob both circle combined
    finalArea = C1.getArea() + C2.getArea();
	
	cout << "The total area of the two circle is " << finalArea << endl; //output total area to user
	
	return 0; //done
}

Want to play with it? Go to my repl.it at Area of Circle in C++. Bye-Bye 🙂

Leave a Reply

Back to Top