Soulsurv

Untitled

May 9th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. //name: Your name:
  2. //date: YY/YY/YYYY //purpose: using classes //assignment: E03 part 3
  3. //class time: // Header file: ptObj.h
  4. #include <iostream>
  5. #include <string>
  6. using namespace std;
  7.  
  8. class ptObj {
  9. public:
  10. void init();
  11. void dispT();
  12. bool newX(int xIn);
  13. bool newY(int yIn);
  14. int getX();
  15. int getY();
  16. private:
  17. int x;
  18. int y;
  19. };
  20.  
  21. //---------------------------------------------------
  22. // source code file for the point class:
  23. // name: ptObj.cpp
  24. #include <iostream>
  25. #include <string>
  26. #include "ptObj.h"
  27. using namespace std;
  28.  
  29. void ptObj::init() {
  30. x = 0; y = 0;
  31. }
  32.  
  33. void ptObj::dispT()
  34. {
  35. cout << "\nPoint contents: x = " << x;
  36. cout << " y = " << y << endl;
  37. }
  38. bool ptObj::newX(int xIn)
  39. {
  40. if (xIn >= 0)
  41. {
  42. x = xIn;
  43. return true;
  44. }
  45. else
  46. return false;
  47. }
  48. bool ptObj::newY(int yIn)
  49. {
  50. if (yIn >= 0)
  51. {
  52. y = yIn;
  53. return true;
  54. }
  55. else
  56. return false;
  57. }
  58.  
  59. int ptObj::getX() { return x; } int ptObj::getY() { return y; }
  60.  
  61. //-------------------------------------------------
  62. // the main program file:
  63. // theMain.cpp
  64. #include <iostream>
  65. #include <string>
  66. #include "ptObj.h"
  67. using namespace std;
  68.  
  69. int main() { //begin main
  70. int x = -10; //x is an integer;
  71. int y = -20; //y is an integer;
  72. ptObj p1;//p1 is a point object
  73. ptObj p2;//p2 is a point object
  74.  
  75. p1.init();
  76. p2.init();
  77.  
  78. cout << "Displaying p1: \n"; //what values should p1 have?
  79. p1.dispT();
  80.  
  81. cout << "Enter x and y coor: ";
  82. cin >> x >> y;
  83. p2.newX(x);
  84. p2.newY(y);
  85.  
  86.  
  87. cout << "Displaying p2: \n"; //what values should p2 have?
  88. p2.dispT();
  89.  
  90. p1.newX(x);
  91. p1.newY(y);
  92.  
  93. x = p1.getX();
  94. y = p1.getY();
  95.  
  96. //place code to assign the x
  97. x = p2.getX();
  98. y = p2.getY();
  99. // and y values of p2 to the //integer variables x and y.
  100. //what is this like? assigning
  101. //p1 to p2? x to x? y to y?
  102.  
  103. system("pause");
  104. return 0;
  105. }//end main
Advertisement
Add Comment
Please, Sign In to add comment