Simple debug Sinus and Cosinus

This is my code for a Program that finds the Sinus and Cosinus functions

// programa de calculo de funciones seno y coseno:


#include<iostream>
using namespace std;


class funciones {
long Sumatoria;
int Factorial(int);
int Potencia (int, int);
bool Turno;
public:
long Seno (long);
long Coseno (long);

}funcion;

funciones::Factorial (int b){
int factor=1;
for(b;b>1;b--){
factor*=b;
}
return (factor);
}

funciones::Potencia (int c,int Numero){
int Resultado;
for(c;c<1;c--){
Resultado*=Numero;
}
return (Resultado);
}


funciones::Seno(long x){
bool Turno=0;
for(int n=1;n<100;n++){
if (n%2==0) continue;
else {
if(funcion.Turno==0){
Sumatoria+= Potencia(n,x)*Factorial(n);
Turno=1;
}
else {
Sumatoria-=Potencia(n,x)*Factorial(n);
Turno=0;
}
}
}
return (Sumatoria);
}

int main(){

long f;

cout<< "Introduce el numero al que le deseas sacar el seno/n";
cin>> f;
cout<< "El seno del valor es: " << funcion.Seno(f);

return 0;
}









Last edited on
So?
It doesnt work, and I dont know why, it says:

C:\Users\Admin\Desktop\Ejercicios de clases\tarea de senos y cosenos\Cpp1.cpp(36) : error C2556: 'int __thiscall funciones::Seno(long)' : overloaded function differs only by return type from 'long __thiscall funciones::Seno(long)'
C:\Users\Admin\Desktop\Ejercicios de clases\tarea de senos y cosenos\Cpp1.cpp(14) : see declaration of 'Seno'
C:\Users\Admin\Desktop\Ejercicios de clases\tarea de senos y cosenos\Cpp1.cpp(36) : error C2371: 'Seno' : redefinition; different basic types
C:\Users\Admin\Desktop\Ejercicios de clases\tarea de senos y cosenos\Cpp1.cpp(14) : see declaration of 'Seno'
C:\Users\Admin\Desktop\Ejercicios de clases\tarea de senos y cosenos\Cpp1.cpp(60) : error C2264: 'Seno' : error in function definition or declaration; function not called
Error executing cl.exe.

Cpp1.obj - 3 error(s), 0 warning(s)
Your definition of funciones::Seno() doesn't match the declaration of the same function.
long Seno (long); funciones::Seno (long){
Actually, none of your declarations match the definitions. It's illegal to omit the return type in C++.

By the way, "seno" and "coseno" in English are "sine" and "cosine". Sinus is something different: http://en.wikipedia.org/wiki/Sinus_%28anatomy%29
lol thanks a lot man, ur awesome
I've made some changes in the program, but for some reason it doesn't return me the sine of that number in radians. Why is that? i've cuadruple checked it!!
This program is based in the Taylor's series aproximation.


#include<iostream>
using namespace std;


class funciones {
float Sumatoria;
int Factorial (int);
int Potencia (int, int);
bool Turno;

public:
float Seno (float);
float Coseno (float);

}funcion;

int funciones::Factorial (int b){
int factor=1;
for(b;b>=1;b--){
factor*=b;
}
return (factor);
}

int funciones::Potencia (int c,int Numero){
int Resultado=1;
for(c;c>=1;c--){
Resultado*=Numero;
}
return (Resultado);
}


float funciones::Seno(float x){
Sumatoria=0;
Turno=true;
for(int n=1;n<=10;n++){
if (n%2==0) continue;
else {
if(Turno==true){
Sumatoria+= Potencia(n,x)/Factorial(n);
Turno=false;
}
else {
Sumatoria-=Potencia(n,x)/Factorial(n);
Turno=true;
}
}
}
return (Sumatoria);
}

int main(){

float f;

cout<< "Introduce el numero al que le deseas sacar el seno/n";
cin>> f;
cout<< "El seno del valor es: " << funcion.Seno(f);

return 0;
}

Topic archived. No new replies allowed.