Good Afternoon,

I'm having problems with a program that I have to do for school. It deals with pointType class and the main program section.

The details of what the program should do are the following:

Define and implement a class poinType that implements a point (x,y). The class pointType should have two data
members to store the x- and y-coordinates, as well as the following function members:
a) Function setPoint, to set the x- and y-coordinates.
b) Function print, to print the x- and y-coordinate.
c) Functions getX and getY, to get the values of the x- and y-coordinates.
d) Default constructor and constructor with parameters.
(These functions and constructors must all have the appropriate parameters.)

So far I have this information of the class in the header file

class pointType
{
public:
    void setPoint(double xcord, double ycord);
    void print ();
    double getX (double, double);
    double getY (double, double);
    pointType ();                                       // Default constructor
    pointType (double xcord = 0, double ycord = 0);     // Constructor with parameters

private:
    double x;
    double y;
};

In the cpp file I have this information

#include <iostream>
#include "ass1.h"

using namespace std;

pointType::pointType(double xCord, double yCord)
{
    setPoint(xCord, yCord);
}

pointType::pointType()
{
    x = 0;
    y = 0;
}
int main()
{

    pointType   p1(3.1,5.2); // Declaring point 1
    pointType   p2(0,0);    //Declaring point 2
    double      x, y;

    //printing coordinates of point 1
    cout<<"Coordinates of point 1 are: ";
    p1.print();

    //printing coordinates of point 2
    cout<<"Coordinates of point 2 are: ";
    p2.print();

    //requesting new coordinates for point 2
    cout<<"Enter new coordinates for point 2\n";
    cout<<"x-coordinate: ";
    cin >> x;
    cout<<"\ny-coordinate: ";
    cin >> y;
    cout <<endl;

    //assign new coordinates to point 2
    p2.setPoint(x,y);

    //printing coordinates of point 2 using getX and getY functions
    cout<<"Coordinates of point 2 are: ";
    cout <<"(" << p2.getX() <<"," << p2.getY() << ")\n";

    cout<<"Good bye." << endl;

    return 0;
}

void pointType::setPoint(double x, double y)
{
    cout << "Enter the x coordinate of point 1: " << endl;
    cin >> x;
    cout << "Enter the y coordinate of point 1: " << endl;
    cin >> y;
    cout << "Enter the x coordinate of point 2: " << endl;
    cin >> x;
    cout << "Enter the y coordinate of point 2: " << endl;
    cin >> y;
}
void pointType::print()
{

    cout << "The coordinates of point 1 are: ";
    cin >> x >> y;
    cout << endl;
    cout << "The coordinates fo point 2 are: ";
    cin >> x >> y;
}

 double pointType::getX(double p1, double p2)
{
    cout << "The x coordinate for point 1 is: ";
    cin >> x;
    cout << "The x coordinate for point 2 is: ";
    cin >> x;
}

double pointType::getY(double p1, double p2)
{
    cout << "The y coordinate for point 1 is: ";
    cin >> y;
    cout << "The y coordinate for point 2 is: ";
    cin >> y;
}

I would really appreciate if someone could give me some guidance in the project, I'm taking computer science for the first time, so I'm not highly incline in programming.

Hi,

It looks ok, a few minor things I don´t understand - like why do you ask for coordinates of two different points in the setPoint function?

Do you´ve any specific questions?

Cheers,
Erik

erikandr you are right, the setPoint function should onlu ask for 1 point coordinates which would be (x, y) coordinates for the point. In the header file I get the warning ass1.h(14): warning C4520: 'pointType' : multiple default constructors specified
and in the cpp file get the following warnings:
error C2660: 'pointType::getX' : function does not take 0 arguments
error C2660: 'pointType::getY' : function does not take 0 arguments

I really appreciate your help.

thank you

Please post your modified code (since we don't know what changes you made in the interim) with code tags [code] //code goes here [/code]

Bear in mind that what your have specified in the class declaration (up at the top) must match the method definitions (the functions below).

just like my prog.in my case study/

thanks everybody for the help, now the program runs correctly

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.