You are on page 1of 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