Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //name: Your name:
- //date: YY/YY/YYYY //purpose: using classes //assignment: E03 part 3
- //class time: // Header file: ptObj.h
- #include <iostream>
- #include <string>
- using namespace std;
- class ptObj {
- public:
- void init();
- void dispT();
- bool newX(int xIn);
- bool newY(int yIn);
- int getX();
- int getY();
- private:
- int x;
- int y;
- };
- //---------------------------------------------------
- // source code file for the point class:
- // name: ptObj.cpp
- #include <iostream>
- #include <string>
- #include "ptObj.h"
- using namespace std;
- void ptObj::init() {
- x = 0; y = 0;
- }
- void ptObj::dispT()
- {
- cout << "\nPoint contents: x = " << x;
- cout << " y = " << y << endl;
- }
- bool ptObj::newX(int xIn)
- {
- if (xIn >= 0)
- {
- x = xIn;
- return true;
- }
- else
- return false;
- }
- bool ptObj::newY(int yIn)
- {
- if (yIn >= 0)
- {
- y = yIn;
- return true;
- }
- else
- return false;
- }
- int ptObj::getX() { return x; } int ptObj::getY() { return y; }
- //-------------------------------------------------
- // the main program file:
- // theMain.cpp
- #include <iostream>
- #include <string>
- #include "ptObj.h"
- using namespace std;
- int main() { //begin main
- int x = -10; //x is an integer;
- int y = -20; //y is an integer;
- ptObj p1;//p1 is a point object
- ptObj p2;//p2 is a point object
- p1.init();
- p2.init();
- cout << "Displaying p1: \n"; //what values should p1 have?
- p1.dispT();
- cout << "Enter x and y coor: ";
- cin >> x >> y;
- p2.newX(x);
- p2.newY(y);
- cout << "Displaying p2: \n"; //what values should p2 have?
- p2.dispT();
- p1.newX(x);
- p1.newY(y);
- x = p1.getX();
- y = p1.getY();
- //place code to assign the x
- x = p2.getX();
- y = p2.getY();
- // and y values of p2 to the //integer variables x and y.
- //what is this like? assigning
- //p1 to p2? x to x? y to y?
- system("pause");
- return 0;
- }//end main
Advertisement
Add Comment
Please, Sign In to add comment