C++ Program to Find Length and Area of Arc in Circular Sector
Introduction
A circular sector is a part of a circle formed by two radii and the arc between them. It has practical applications in fields like engineering, architecture, and mathematics. To work with circular sectors, two essential aspects often need to be calculated:
- The length of the arc (curved portion of the circle).
- The area of the sector (portion enclosed by the arc and radii).
In this article, we will discuss how to compute the length and area of an arc in a circular sector using C++. We will provide formulas, the C++ implementation, sample output, and a detailed explanation of the program.
Formulas
The following formulas are used to calculate the length and area of an arc in a circular sector:
-
Arc Length (L): The arc length is given by:
L = r × Î¸
, where:r
is the radius of the circle.θ
is the angle subtended at the center in radians.
-
Area of Sector (A): The area of the sector is calculated as:
A = 0.5 × r² × Î¸
, where:r
is the radius of the circle.θ
is the angle in radians.
Code
Below is the C++ implementation to compute the arc length and area of a circular sector:
#include <iostream> #include <cmath> using namespace std; int main() { // Variables for radius and angle double radius, angle; // Input radius and angle in degrees cout << "Enter the radius of the circle: "; cin >> radius; cout << "Enter the angle of the sector in degrees: "; cin >> angle; // Convert angle from degrees to radians double angleRadians = angle * M_PI / 180.0; // Calculate arc length double arcLength = radius * angleRadians; // Calculate area of the sector double sectorArea = 0.5 * radius * radius * angleRadians; // Display results cout << "Arc Length: " << arcLength << endl; cout << "Area of Sector: " << sectorArea << endl; return 0; }
Output
When you run the program, you will be prompted to input the radius of the circle and the angle of the sector in degrees. Below is an example of the program execution:
Enter the radius of the circle: 5 Enter the angle of the sector in degrees: 60 Arc Length: 5.23599 Area of Sector: 13.0899
Explanation
Let’s break down the program step-by-step:
-
Input:
The program first asks the user to input the radius of the circle and the angle of the sector in degrees.
These values are stored in variables
radius
andangle
. -
Conversion to Radians:
Since mathematical formulas use radians, the angle provided in degrees is converted to radians using the formula:
angleRadians = angle × Ï€ / 180
. -
Calculations:
Using the formulas:
Arc Length = radius × angleRadians
Area of Sector = 0.5 × radius² × angleRadians
- Output: The computed arc length and sector area are displayed to the user.
This program is straightforward and demonstrates how to handle mathematical operations and user inputs in C++ effectively.