ok guys need some help, I'm sure the answer is simple but i'm making a program for an assignement that models points in a cartesian plane and prints them out this is what i have so far

in main

#include "point.h"
#include <iostream>
#include <string>
#include <fstream>   //for ifstream,ofstream
#include <iomanip>
#include <stdio.h>  // Need for getchar
using namespace std;



int main()
{

double a, b;
double x1,y1;
	point(); //  default contructor
	point (  a,  b); // contructor
	//points( const points &init):// copy constructor
	//~point(); 

	x1 = getX() const;
	y1 = getY() const;
	cout.setf (ios::showpoint );
	cout.setf( ios::fixed);
	cout << setprecision(2);

	char ch = getchar();
			return 0;
}

.H file

#ifndef POINTS_H
#define POINTS_H
#include <iostream>
#include <fstream> 

using namespace std;




class point
{
private:
	
	double xval;
	double yval;

public:
	
	double getX() const;
	double getY() const;
	point(); //  default contructor
	point ( double x, double y); // contructor
	//point( const point& temp);// copy constructor
	~point(); // destructor
	
	void setX(double x);
	void setY(double y);
	void setPoints( double x, double y);
	friend ostream &operator<<(ostream& outs, const point& P);
	friend istream &operator>>(istream& ins, point &P);
void tostring();

		
		};

.cpp file

#include "point.h"		//obtain prototype definitions
#include <iostream>
#include <fstream>  
#include <string>

using namespace std;




point::point()
{
	double x = 0;
	double y = 0;
	cout << " calling default contructor" << endl;
}
////////////////////////////////////////////////////////////////////////////////////////////////

point::point ( double x, double y)
{ 
	xval=x;
	yval=y;
	cout << "calling contructor" << endl;
}
////////////////////////////////////////////////////////////////////////////////////////////////
point::~point() 
{
	cout << "Calling Destructor" << endl;
}

////////////////////////////////////////////////////////////////////////////////////////////////
double point::getX() 
{
	double x;

cout << " Enter point x: " << endl;
	cin >> x;
	return x;

}
////////////////////////////////////////////////////////////////////////////////////////////////
double point::getY() 
{
double y;
cout << " Enter point y: " << endl;
	cin >> y;
	return y;

}
////////////////////////////////////////////////////////////////////////////////////////////////
void point::setPoints( double x, double y)
{
	setX(x);
	setY(y);
}

void point::setX(double x)
	{ 
		xval=x;
	}
////////////////////////////////////////////////////////////////////////////////////////////////	
void point::setY(double y)
	{
		yval=y;
	}
////////////////////////////////////////////////////////////////////////////////////////////////

any words of wisdom would be great

Dani AI

Generated

Quick diagnosis for : the two immediate problems are (1) calling getX/getY as if they were free functions instead of calling them on a point object, and (2) a mismatch between the function prototypes and their definitions (the header marks the getters const, but the .cpp implementations are not const). Also the default constructor in your implementation creates local double variables instead of initializing the member fields, so your members stay uninitialized.

Fixes to apply

  • Create an instance and call its methods: p.getX() and p.getY(), not getX() by itself.
  • Make the implementation signatures match the header exactly (add const to the definitions if the prototype has const). A mismatch leads to linker errors or unexpected behavior.
  • Initialize members in the constructor (prefer initializer lists). Avoid doing input from inside getters — let callers read input and then call setX/setY or use the parameterized constructor.
  • Avoid using namespace std; in headers and avoid printing from constructors/destructors in production code.

Minimal example showing the intended shape (class and usage):

class Point {
    double x_, y_;
public:
    Point(): x_(0.0), y_(0.0) {}
    Point(double x, double y): x_(x), y_(y) {}
    double getX() const { return x_; }
    double getY() const { return y_; }
    void setX(double v) { x_ = v; }
    void setY(double v) { y_ = v; }
};
int main() {
    Point p;           // default constructed
    Point q(1.0, 2.0); // parameterized
    double x = q.getX(); // call on object q
    double y = q.getY();
    std::cout << x << ", " << y << '\n';
    return 0;
}

Troubleshooting tips

  • If the compiler says an identifier is not found, check whether you forgot to qualify the call with an object.
  • If you get linker errors like “undefined reference” for a member function, check that the implementation signature (including const) exactly matches the declaration.
  • Compile with warnings on: g++ -std=c++11 -Wall -Wextra main.cpp point.cpp to catch mismatches early.

the error i keep getting is that getX and getY in main come up as identifier not found

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.