ii. Write an algorithm, draw a flowchart, and write a C++ program to calculate the value of P.
Read the variables q, r, and theta.
Calculate the value of P using the formula:
P = q^2 + r^2 + cos(theta)
Print the value of P.
Note:
a) Assume theta is t.
b) Use t * 3.14/180 for calculating sin(theta).
Sample Output:
Enter the value of q: 2
Enter the value of r: 2
Enter theta(t) value: 30
The value of P is 8.
Algorithm:
1. Start
2. Read q, r, and theta
3. Calculate P = q^2 + r^2 + cos(theta)
4. Print P
5. Stop
Flowchart:
Program:
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double q, r, theta, P;
cout << "Enter the value of q: ";
cin >> q;
cout << "Enter the value of r: ";
cin >> r;
cout << "Enter theta(t) value: ";
cin >> theta;
P = pow(q, 2) + pow(r, 2) + cos(theta * 3.14/180);
cout << "The value of P is " << P << endl;
return 0;
}