I have a problem with my homework.
1) I should write the function SSS with inputs a, b and c. I need to output alpha, beta and gamma.
2) I should write the function SWS with inputs a, b, and gamma. And I need to output c, alpha and beta.
Here is my code:
#include <iostream>
#include <cmath>
#include <math.h>
#include <cstdio>
using namespace std;
double SSS_alpha(double a, double b, double c){
int bot1 = -2*b*c;
if(bot1==0.0){
return 0.0;
}
double alpha = acos((a*a-b*b-c*c)/bot1);
const double rad = 0.5729577951308232088;
return alpha*rad;
}
double SSS_beta(double a, double b, double c){
double bot2 = -2*c*a;
if(bot2==0.0){
return 0.0;
}
double beta = acos((b*b-c*c-a*a)/bot2);
const double rad = 0.5729577951308232088;
return beta*rad;
}
double SSS_gamma(double a, double b, double c){
double bot3 = -2*b*a;
if(bot3==0.0){
return 0.0;
}
double gamma = acos((c*c-a*a-b*b)/bot3);
const double rad = 0.5729577951308232088;
return gamma*rad;
}
double WSW_seite_c(double a, double b, double gamma){
double c_1 = (a*a+b*b-2*a*b*cos(gamma));
double c = sqrt(c_1);
return c;
}
int main(){
cout << SSS_alpha(5.0, 7.0, 8.0)<<endl;
cout <<SSS_beta(5.0, 7.0, 8.0)<<endl;
cout <<SSS_gamma(5,7,8)<<endl;
cout <<"Seite c: "<<WSW_seite_c(5, 7, 0.81)<<endl;
}
I can only return one argument in one function. And I have a lot of functions for task 1:for alpha, for beta, for gamma. And I don't know how I can write it in one function. I wrote only one function for finding c for task 2.
I am new to C++. I would be happy if you can help me.:)
A
struct
will be the simplest way of doing what you want. You can also create a class, but it might be an overkill solution for a homework (they basically are the same, but see my comment thread to get my point of view on that matter).a struct declaration goes like this :
The struct then basically becomes a type you can use pretty much like
int
,double
,bool
etc.Here's a nice reading on
struct
and how to use it