|
No type named
Hi all,
I am trying to test every function in the class and stuck with the distance function. I produces an error with no type named. I got no idea what I am doing wrong, appreciate any help form you.
/*
FILE: Point.h
class provide: Point(an ADT for a point on a two-dimension plane)
CONSTRUCTOR
Point(double initial_x = 0, double initial_y = 0);
// Post: the Point has been set to (initial_x, initial_y)
MODIFICATION MEMBER FUNCTION for Point class
void shift(double x_amount, double y_amount);
//Post: The Point has been move along x axis by x_amount, y axis by y_amount
void rotate90();
//Post: The Point has been rotate 90 degree clockwise around the origin
int rotate_needed(Point p)
// Post: return the value of the number of 90 degree clockwise rotations
//need to move p to upper right quadrant(where x>=0, y>=0)
void rotation_upper_right(Point &p)
//Post: The Point p has been rotated 90 degree increment until p has moved
//to upper right quadrant (where x>=0, y>=0)
CONSTANT MEMBER FUNCTIONS
doubel get_x() const {return x;}
//Post: return the x coordinate of the Point
double get_y() const {return y;}
//Post: return the y coordinate of the Point
FRIEND FUNCTIONS
friend istream& Point::operator >>(istream &ins, cost Point &target)
//Post: the x and y coordinates of target has been read form ins.
//the return value is the istream ins.
NON-MEMBER FUNCITONS
double distance(const Point &p1, const Point &p2)
//Post: return the value of the distance form p1 to p2
Point mid_point(const Point &p1, const Point &p2)
//Post: return the value of the Point is halfway between p1 & p2
bool operator ==(const Point &p1, const Point &p2)
//Post: return true if p1 and p2 are identical, otherwise, return false
bool operator !=(const Point &p1, const Point &p2)
//Post: return true if p1 and p2 are not identical
Point operator +(const Point &p1, const Point &p2)
//Post: return the sum of p1 and p2
ostream& operator <<(ostream &outs, cost Point &source)
//Post: the x and y coordinate s of source has been written to outs
//. The return value is the ostream outs.
*/
#ifndef POINT_H
#define POINT_H
#include <iostream.h>
#include <stdlib.h>
class Point
{
public:
// CONSTRUCTOR
Point(double initial_x = 0, double initial_y = 0);
// MODIFICATION MEMBER FUNCTIONs for Point class
void shift(double x_amount, double y_amount);
void rotate90();
int rotation_needed(Point p);
void rotation_upper_right(Point &p);
// CONSTANT MEMBER FUNCTIONS
double get_x() const {return x;}
double get_y() const {return y;}
friend istream& operator >>(istream &ins, Point &target);
//the istream CAN NOT become a member function, therefore, using keyword FRIEND
//to access the member variable directly without other mutators.
private:
double x;
double y;
};
//NON-MEMBER FUNCTIONS
double distance(const Point &p1, const Point &p2);
Point mid_point(const Point &p1, const Point &p2);
bool operator ==(const Point &p1, const Point &p2);
bool operator !=(const Point &p1, const Point &p2);
Point operator +(const Point &p1, const Point &p2);
ostream& operator <<(ostream &outs, const Point &source);
#endif // POINT_H
/*
FILE: Point.cxx
CLASS IMPLIMENTATION: Point
*/
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include "point.h"
Point::Point(double initial_x, double initial_y)
{
x = initial_x;
y = initial_y;
}
void Point::shift(double x_amount, double y_amount)
{
x += x_amount;
y += y_amount;
}
void Point::rotate90()
{
double new_x;
double new_y;
new_x = y;
new_y = -x;
x = new_x;
y = new_y;
}
int Point::rotation_needed(Point p)
{
int answer = 0;
while((p.get_x() < 0) || (p.get_y() < 0))
{
p.rotate90();
answer++;
}
return answer;
}
void Point::rotation_upper_right(Point &p)
{
while((p.get_x() < 0) || (p.get_y() < 0))
{
p.rotate90();
}
}
double distance(const Point &p1,const Point &p2)
{
double a, b, c_square;
a = p1.get_x() - p2.get_x();
b = p1.get_y() - p2.get_y();
c_square = a*a + b*b;
return (sqrt(c_square));
}
Point mid_point(const Point& p1, const Point& p2)
{
double x_midpoint, y_midpoint;
x_midpoint = (p1.get_x() + p2.get_x()) / 2;
y_midpoint = (p1.get_y() + p2.get_y()) / 2;
Point midpoint(x_midpoint, y_midpoint);
//construct new object midpoint with values of x_midpoint and y_midpoint
return midpoint;
}
bool operator ==(const Point &p1, const Point &p2)
{
return ((p1.get_x() == p2.get_x()) && (p1.get_y() == p2.get_y()));
}
bool operator !=(const Point &p1, const Point &p2)
{
return (!(p1 == p2));
}
Point operator +(const Point &p1, const Point &p2)
{
double x_sum, y_sum;
x_sum = p1.get_x() + p2.get_x();
y_sum = p1.get_y() + p2.get_y();
Point sum(x_sum, y_sum);
return sum;
}
ostream& operator <<(ostream &outs, const Point &source)
{
outs << source.get_x() << " " << source.get_y();
return outs;
}
istream& operator >>(istream &ins, Point &target)
{
ins >> target.x >> target.y;
return ins;
}
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include "point.h"
#include "point.cpp"
using namespace std;
int main()
{
Point p(1,2);
Point p1(4,3);
cout <<"Constructor test: \n";
cout <<p.get_x() << " " << p.get_y();
cout << endl;
cout <<"shift test: \n";
p.shift(1,2);
cout <<p.get_x() << " " << p.get_y();
cout << endl;
cout <<"rotate90 test: \n";
p.rotate90();
cout <<p.get_x() << " " << p.get_y();
cout << endl;
cout <<"rotate need test: \n";
cout <<"number of turn needed: " << p.rotation_needed(p) << endl;
cout <<"current position: " ;
cout <<p.get_x() << " " << p.get_y();
cout << endl;
cout <<"rotate upper right test: \n";
p.rotation_upper_right(p);
cout <<"current position: " <<p.get_x() << " " << p.get_y();
cout << endl;
cout <<"distance test: \n";
cout <<"The distance between 2 points is: " ;
double d;
d = distance(p, p1);
cout << d << endl;
return 0;
}
I am testing on both Dev-c++ and code::block under windows xp sp2, but they produce the same error message.
|