Hey all, for my next assignment, I decided to try and compile from multiple source files. One as a header for function and structure definitions, a cpp file for declarations, and a main for a driver. The code looks something like this:
Header:
Code:
#include <iostream>
using namespace std;
struct point
{ double x;
double y;
};
struct circle
{ point center;
double radius;
};
struct triangle
{
point a;
point b;
point c;
};
double Distance (point a, point b);
double areaOfcircle (double radius);
double Perimeter (double radius);
void triangleDistance( point a, point b, point c);
Main program file:
Code:
#include <iostream>
#include "untitled.h"
using namespace std;
int main()
{
point p1;
point p2;
p1.x = 1;
p1.y = 2;
p1.x = -1;
p1.x = -2;
cout << Distance (p1,p2) << endl;
circle a;
a.center.x = 1;
a.center.y = 2;
a.radius = 3;
cout << areaOfcircle (a.radius) << endl;
cout << Perimeter (a.radius) << endl;
point b;
point c;
point d;
b.x = 1;
b.y = 2;
c.x = 3;
c.y = 4;
d.x = 5;
d.y = 6;
triangleDistance(b,c,d);
return 0;
}
And Function Declaration file (this is the file that's giving me errors):
Code:
/*
#include "untitled.h"
//Function Declarations
#include <iostream>
#include <cmath>
using namespace std;
const double pi = 3.14159265358979323846;
double Distance (point a , point b )
{
double answer = sqrt ((a.x-b.x)(a.x-b.x) + (a.y-b.y)(a.y-b.y) );
return answer; // The error states : '(a.point::x-b.point::x)' cannot be used as a function
}
double areaOfcircle (double radius)
{
double answer = pi * radius* radius;
return answer;
}
double Perimeter (double radius)
{
double answer = 2 * pi * radius;
return answer;
}
void triangleDistance( point b, point c, point d)
{
double answer = sqrt ((b.x-c.x)(b.x-c.x) + (b.y-c.y)(b.y-c.y) ); // The error states : '(a.point::x-b.point::x)' cannot be used as a function
cout << "length of side 'a' is: "<< answer;
double answer2 = sqrt ((b.x-d.x)(b.x-d.x) + (b.y-d.y)(b.y-d.y) ); // The error states : '(a.point::x-b.point::x)' cannot be used as a function
cout << "length of side 'a' is: "<< answer2;
double answer3 = sqrt ((c.x-d.x)(c.x-d.x) + (c.y-d.y)(c.y-d.y) ); // The error states : '(a.point::x-b.point::x)' cannot be used as a function
cout << "length of side 'a' is: "<< answer3;
return;
}
I've never split up a project into different files before, and I'm only just learning about structures, so I'm not sure what my error in the declaration file is, much less understand what the compiler's trying to say. Thanks in advance for any and all help.