I need help with a program i am writing( i am new to programing). I am writing a program to Coordinates have the form (x, y, z)
Use double variables to represent the private data of the class.
Provide a constructor that enables an object to be initialized when it is declared and has default values of 0.0.
Provide a friend function << for cout
Provide a friend function >> for cin
Provide an overloaded operator + for this class
Provide an overloaded operator - for this class
Provide an overloaded operator * for this class
Provide an overloaded operator = for this class
Provide an overloaded operator == for this class
Provide an overloaded operator != for this class
The output should look as follows:
Enter a graphical coordinate in the form: (x, y, z)
? (3, 4, 5)
a = b + c:
(7, 9, 14) = (4, 8, 16) + (3, 1, -2)
a = b - c:
(1, 7, 18) = (4, 8, 16) - (3, 1, -2)
a = b * c:
(12, 8, -32) = (4, 8, 16) * (3, 1, -2)
(12, 8, -32) != (3, 4, 5)
(3, 4, 5) == (3, 4, 5)
what i have so far are my header file Coordinate.h
#include<iostream>
using namespace std;
#ifndef COORDINATE_H
#define COORDINATE_H
class Coordinate
{
private:
double x, y, z;
public:
friend ostream &operator<<( ostream &, const Coordinate & );
friend istream &operator>>( istream &, Coordinate &);
Coordinate (double x = 0.0, double y = 0.0, double z = 0.0);
void get_coordinates(double, double, double);
Coordinate operator+(const Coordinate&) const;
Coordinate operator-(const Coordinate&) const;
Coordinate operator*(const Coordinate&) const;
Coordinate operator=(const Coordinate&) const;
bool operator==(const Coordinate&) const;
bool operator!=(const Coordinate&) const;
};
#endif
the implementaion file Coordinate.cpp
#include <iostream>
#include "Coordinate.h"
using namespace std;
Coordinate Coordinate::operator+(const Coordinate&)
{
return Coordinate(x + a.x , y + a.y, z + a.z);
}
Coordinate Coordinate::operator-(const Coordinate&)
{
return Coordinate(x - a.x, y - a.y, z - a.z);
}
Coordinate Coordinate::operator*(const Coordinate&)
{
return Coordinate(x * a.x, y * a.y, z * a.z);
}
Coordinate Coordinate::operator==(const Coordinate&)
{
return (*this == right);
}
Coordinate Coordinate::operator!=const Coordinate&)
{
return;
}
ostream &operator<<(ostream &output, const Coordinate&)
{
output << endl;
return output;
}
istream &operator>>(istream &input, Coordinate&)
{
input << endl;
return input;
}
and the main function
#include "Coordinate.h"
#include <iostream>
using namespace std;
int main()
{
Coordinate a, b( 4, 8, 16 ), c( 3, 1, -2 ), k;
cout << "Enter a graphical coordinate in the form: (x, y, z)\n? ";
cin >> k;
a = b + c;
cout << "\na = b + c:\n" << a << " = " << b << " + " << c << '\n';
a = b - c;
cout << "\na = b - c:\n" << a << " = " << b << " - " << c << '\n';
a = b * c;
cout << "\na = b * c:\n" << a << " = " << b << " * " << c << "\n\n";
if ( a != k )
{
cout << a << " != " << k << '\n';
}
cout << '\n';
a = k;
if ( a == k )
{
cout << a << " == " << k << '\n';
}
}
when i try to compile i get crazy errors. i'm pretty sure my mistakes are in the Coordinate.cpp file. Any help or advice would be greatly appreciated