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.