Quick question......srsly

So I typed out this code, but uncertain why the user isn't prompted to enter the values... could anyone help please? I'm sure there's redundant info in here since i'm a noob...there's 3 files... main, xypoint.cpp, and xypoint.h


// main.cpp
#include <iostream>
using namespace std;
#include "xypoint.h"


int main(void)

{

xypoint a1(-5, 7);

xypoint b1(10, 3);

int z=a1.distance(b1);

cout << z << endl;
return 0;

}


// xypoint.h
#ifndef xypoint_H

#define xypoint_H

#include <iostream>

using namespace std;
class xypoint

{

public:
xypoint(float X, float Y);

float a;

float b;

float distance(xypoint point) const;

friend ostream& operator<<(ostream& stream, xypoint& point );

friend istream& operator>>( istream&, xypoint& point );

};

#endif



//xypoint.cpp
#include <iostream>
#include <cmath>
#include "xypoint.h"
xypoint::xypoint(float X, float Y)
{
a=X;
b=Y;
return;
}

float xypoint::distance(xypoint point) const

{
float c;

c= pow((pow((this->a-point.a), 2)+pow((this->b-point.b), 2)),float(.5));
return c;

}

ostream& operator<<( ostream& stream, const xypoint& point)

{
stream << "[" << point.a << "," << point.b << "]";
return stream;

}

istream& operator>>( istream& stream, xypoint& point)

{

float X=0, Y=0;

cout << "Enter x value: ";

stream >> X;

cout << "Enter y value: ";

stream >> Y;

point.a=X;

point.b=Y;

return stream;

}

Last edited on
Quick reply......srsly

Edit you post and put code tags around you code.
Done..... got any tips PanGalactic?
You have to put them like this:

[code]
Your code here
[/code]

Anyway...

1.) Constructors don't return values (at least I've never seen anyone return from a constructor...)
2.) Only the operator >> will prompt for input. You are never using cin >> myxypoint; or anything similar, you are only using the constructors to create the points.
Topic archived. No new replies allowed.