0% found this document useful (0 votes)
9 views2 pages

Text

This C++ program calculates trigonometric functions for a given theta value. The program defines functions to calculate the sine, cosine, secant, tangent, and cotangent of an input theta value. It prompts the user to input a theta value and operation to perform on it. It then calls the appropriate function, displays the result, and allows the user to continue or end the program.

Uploaded by

myspacelove539
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Text

This C++ program calculates trigonometric functions for a given theta value. The program defines functions to calculate the sine, cosine, secant, tangent, and cotangent of an input theta value. It prompts the user to input a theta value and operation to perform on it. It then calls the appropriate function, displays the result, and allows the user to continue or end the program.

Uploaded by

myspacelove539
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment 1

Matric no:2009003121
Name:shotonwa gbolahan olumide

#include <iostream>
#include <cmath>
using namespace std;

int solve();
int Continue();

double sinFunc(float value) {


double valueRad = value * (M_PI / 180.0);
return sin(valueRad);
}

double cosFunc(float value) {


double valueRad = value * (M_PI / 180.0);
return cos(valueRad);
}

double secFunc(float value) {


double valueRad = value * (M_PI / 180.0);
double valueCos = cos(valueRad);
return 1.0 / valueCos;
}

double tanFunc(float value) {


double valueRad = value * (M_PI / 180.0);
return tan(valueRad);
}

double cotanFunc(float value) {


double valueRad = value * (M_PI / 180.0);
double valueTan = tan(valueRad);
return 1.0 / valueTan;
}

int Continue() {
char res;
cout << "Do you want to continue? (y/n) ";
cin >> res;
switch (res) {
case 'y':
case 'Y':
solve();
break;
case 'n':
case 'N':
cout << "---End of program, have a wonderful day---" << endl;
break;
default:
cout << "You entered an invalid answer (y/n)." << endl;
}
return 0;
}

int solve() {
cout << "Hi there, this program collects theta values and calculates
its sine, cosine, secant, tangent, and cotangent values respectively" <<
endl;
int thetaVal;
string op; // Change op to a string
cout << "Please input your theta value: ";
cin >> thetaVal;
cout << "What operation do you want to perform on the theta value
(sin, cos, sec, tan, or cotan): ";
cin >> op;

if (op == "sin") {
double convertVal = sinFunc(thetaVal);
cout << "The sine value of " << thetaVal << " is " << convertVal
<< endl;
Continue();
} else if (op == "cos") {
double convertVal = cosFunc(thetaVal);
cout << "The cosine value of " << thetaVal << " is " <<
convertVal << endl;
Continue();
} else if (op == "sec") {
double convertVal = secFunc(thetaVal);
cout << "The secant value of " << thetaVal << " is " <<
convertVal << endl;
Continue();
} else if (op == "tan") {
double convertVal = tanFunc(thetaVal);
cout << "The tangent value of " << thetaVal << " is " <<
convertVal << endl;
Continue();
} else if (op == "cotan") {
double convertVal = cotanFunc(thetaVal);
cout << "The cotangent value of " << thetaVal << " is " <<
convertVal << endl;
Continue();
} else {
cout << "You typed an invalid operation (sin, cos, sec, tan,
cotan)" << endl;
}
return 0;
}

int main() {
solve();
return 0;
}

You might also like