/*x!=0 si y!=0*/
a=atan(z->y/z->x);
if(z->x <0)/*x>0 si y<0 */
return a+PI;
else /*x>0*/
if(z->y < 0) /*x>0 si y<0*/
return 2*PI + a;
/*x>0 si y>0*/
return a;
}
bx3.cpp
#include<stdio.h>
#include<math.h>
#define PI 3.14159265358979
typedef struct{
double x;
double y;
} COMPLEX;
#include "bx1.cpp"
#include "bx2.cpp"
main()/*citeste nr compplexe si le afiseaza impreuna cu modulul si argumentul corespunzator*/
{
COMPLEX numar;
while(scanf("%lf %lf",&numar.x,&numar.y)==2)
{
printf("a+ib=%g +i*(%g)/n",numar.x,numar.y);
printf("modul=%g\targ=%g\n",dmodul(&numar),darg(&numar));
}
}
The errors i receive:
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2065: 'COMPLEX' : undeclared identifier
error C2065: 'z' : undeclared identifier
error C2448: 'darg' : function-style initializer appears to be a function definition
error C2065: 'COMPLEX' : undeclared identifier
error C2065: 'z' : undeclared identifier
error C2448: 'dmodul' : function-style initializer appears to be a function definition
COMPLEX is fine as is, but it is not defined in bx1.cpp or bx2.cpp which is causing the error.
You may be thinking because you've defined COMPLEX before including either of those files that it should be visible to the functions in those files..
Each file is compiled as a seperate translation unit, bx1.cpp & bx2.cpp do not know that they are being included into another source file and do not know COMPLEX is defined before them in bx3.cpp.
You could copy your COMPLEX type into the other files, but it would be much better if you created a seperate header to include in each file.
#include <cstdio>
#include "bx.h"
int main()/*citeste nr compplexe si le afiseaza impreuna cu modulul si argumentul corespunzator*/
{
COMPLEX numar;
...
return 0;
}