Lab08/Lab08.cppLab08/Lab08.cpp//**************************************************************************************************************
// FILE: Lab08.cpp
//
// DESCRIPTION: Contains the main() function. Instantiates a PointTest object which tests the Point class.
//
// AUTHORS: your-name (your-email-address)
// your-partner's-name (your-partners-email-address)
//
// COURSE: CSE100 Principles of Programming with C++, Fall 2015
//
// LAB INFO: Lab 8 Date/Time: your-lab-date-and-time TA: your-lab-ta
//--------------------------------------------------------------------------------------------------------------
// TESTING:
//
// TEST CASE 1:
// ------------
// TEST CASE INPUT DATA:
// Point p1 x = 11
// Point p1 y = 22
// Point p2 x = -33
// Point p2 y = -44
//
// EXPECTED OUTPUT GIVEN THE INPUT:
// The point p1 is (11, 22)
// The point p2 is (-33, -44)
// The distance between the points is 79.322
// Moving point p1...The point p1 is now at (100, 200)
// The distance between the points is 277.894
// Moving point p2...The point p2 is now at (300, 400)
// The distance between the points is 282.843
//
// OBSERVED OUTPUT:
// Document the output from your program when you perform this test case
//
// TEST CASE RESULT: Document PASS or FAIL
//
// TEST CASE 2:
// ------------
// TEST CASE INPUT DATA:
// Point p1 x = ???
// Point p1 y = ???
// Point p2 x = ???
// Point p2 y = ???
//
// EXPECTED OUTPUT GIVEN THE INPUT:
// ??? Document the expected output ???
//
// OBSERVED OUTPUT:
// ??? Document the output from your program when you perform this test case ???
//
// TEST CASE RESULT: ??? Document PASS or FAIL ???
//**************************************************************************************************************
#include"PointTest.hpp"
//--------------------------------------------------------------------------------------------------------------
// FUNCTION: main()
//
// DESCRIPTION
// Starting point for the program.
//
// PSEUDOCODE
// Define a PointTest object named pointTest calling the default ctor.
// Call run() on the pointTest object.
// Return 0.
//--------------------------------------------------------------------------------------------------------------
???
Lab08/Point.cppLab08/Point.cpp//**************************************************************************************************************
// FILE: Point.cpp
//
// DESCRIPTION: Implementation of the Point class. See Point.hpp for the class declaration.
//
// AUTHORS: your-name (your-email-address)
// your-partner's-name (your-partners-email-address)
//
// COURSE: CSE100 Principles of Programming with C++, Fall 2015
//
// LAB INFO: Lab 8 Date/Time: your-lab-date-and-time TA: your-lab-ta
//**************************************************************************************************************
#include<cmath>// For sqrt()
#include<sstream>// For stringstre ...
1. Lab08/Lab08.cppLab08/Lab08.cpp//***********************
*****************************************************
**********************************
// FILE: Lab08.cpp
//
// DESCRIPTION: Contains the main() function. Instantiates a P
ointTest object which tests the Point class.
//
// AUTHORS: your-name (your-email-address)
// your-partner's-name (your-partners-email-address)
//
// COURSE: CSE100 Principles of Programming with C++, F
all 2015
//
// LAB INFO: Lab 8 Date/Time: your-lab-date-and-
time TA: your-lab-ta
//-------------------------------------------------------------------------
-------------------------------------
// TESTING:
//
// TEST CASE 1:
// ------------
// TEST CASE INPUT DATA:
// Point p1 x = 11
// Point p1 y = 22
// Point p2 x = -33
// Point p2 y = -44
//
// EXPECTED OUTPUT GIVEN THE INPUT:
// The point p1 is (11, 22)
// The point p2 is (-33, -44)
// The distance between the points is 79.322
// Moving point p1...The point p1 is now at (100, 200)
2. // The distance between the points is 277.894
// Moving point p2...The point p2 is now at (300, 400)
// The distance between the points is 282.843
//
// OBSERVED OUTPUT:
// Document the output from your program when you perform th
is test case
//
// TEST CASE RESULT: Document PASS or FAIL
//
// TEST CASE 2:
// ------------
// TEST CASE INPUT DATA:
// Point p1 x = ???
// Point p1 y = ???
// Point p2 x = ???
// Point p2 y = ???
//
// EXPECTED OUTPUT GIVEN THE INPUT:
// ??? Document the expected output ???
//
// OBSERVED OUTPUT:
// ??? Document the output from your program when you perfor
m this test case ???
//
// TEST CASE RESULT: ??? Document PASS or FAIL ???
//***************************************************
*****************************************************
******
#include"PointTest.hpp"
//-------------------------------------------------------------------------
-------------------------------------
// FUNCTION: main()
//
// DESCRIPTION
3. // Starting point for the program.
//
// PSEUDOCODE
// Define a PointTest object named pointTest calling the default
ctor.
// Call run() on the pointTest object.
// Return 0.
//-------------------------------------------------------------------------
-------------------------------------
???
Lab08/Point.cppLab08/Point.cpp//************************
*****************************************************
*********************************
// FILE: Point.cpp
//
// DESCRIPTION: Implementation of the Point class. See Point.
hpp for the class declaration.
//
// AUTHORS: your-name (your-email-address)
// your-partner's-name (your-partners-email-address)
//
// COURSE: CSE100 Principles of Programming with C++, F
all 2015
//
// LAB INFO: Lab 8 Date/Time: your-lab-date-and-
time TA: your-lab-ta
//***************************************************
*****************************************************
******
#include<cmath>// For sqrt()
#include<sstream>// For stringstream class
#include"Point.hpp"// For Point class declaration
//-------------------------------------------------------------------------
4. -------------------------------------
// CTOR: Point()
//
// DESCRIPTION
// Default constructor. Initializes the point to be at the origin (0,
0).
//
// PSEUDOCODE
// Call init() and pass 0 and 0 as the parameters.
//-------------------------------------------------------------------------
-------------------------------------
???
//-------------------------------------------------------------------------
-------------------------------------
// CTOR: Point(int, int)
//
// DESCRIPTION
// Secondary constructor. Initializes the mX and mY data memb
ers to the input params.
//
// PSEUDOCODE
// Call init() and pass pInitX and pInitY as the params.
//-------------------------------------------------------------------------
-------------------------------------
???
//-------------------------------------------------------------------------
-------------------------------------
// FUNCTION: distance(Point)
//
// DESCRIPTION
// Calculates distance from this Point to pAnotherPoint.
//
// PSEUDOCODE
// deltaX <- GetX() - pAnotherPoint.GetX()
5. // deltaY <- GetY() - pAnotherPoint.GetY()
// Return the square root of deltaX * deltaX + deltaY * deltaY
//-------------------------------------------------------------------------
-------------------------------------
???
//-------------------------------------------------------------------------
-------------------------------------
// FUNCTION: getX()
//
// DESCRIPTION
// Accessor function for the mX data member.
//
// PSEUDOCODE
// Return mX.
//-------------------------------------------------------------------------
-------------------------------------
???
//-------------------------------------------------------------------------
-------------------------------------
// FUNCTION: getY()
//
// DESCRIPTION
// Accessor function for the mY data member.
//
// PSEUDOCODE
// Return mY
//-------------------------------------------------------------------------
-------------------------------------
???
//-------------------------------------------------------------------------
-------------------------------------
// FUNCTION: init(int, int)
//
6. // DESCRIPTION
// Initializes mX and mY to pInitX and pInitY.
//
// PSEUDOCODE
// Call setX() and pass pInitX as the parameter
// Call setY() and pass pInitY as the parameter
//-------------------------------------------------------------------------
-------------------------------------
???
//-------------------------------------------------------------------------
-------------------------------------
// FUNCTION: move(int, int)
//
// DESCRIPTIONm
// Moves the point to the new (x, y) coordinates specified by the
input params.
//
// PSEUDOCODE
// Call init() passing pNewX and pNewY as the params
//-------------------------------------------------------------------------
-------------------------------------
???
//-------------------------------------------------------------------------
-------------------------------------
// FUNCTION: setX(int)
//
// DESCRIPTION
// Mutator function for the mX data member.
//
// PSEUDOCODE
// mX <- pNewX
//-------------------------------------------------------------------------
-------------------------------------
???
7. //-------------------------------------------------------------------------
-------------------------------------
// FUNCTION: setY(int)
//
// DESCRIPTION
// Mutator function for the mY data member.
//
// PSEUDOCODE
// mY <- pNewY
//-------------------------------------------------------------------------
-------------------------------------
???
//-------------------------------------------------------------------------
-------------------------------------
// FUNCTION: toString()
//
// DESCRIPTION
// Returns a string representation of the Point, e.g., if mX is 10
and mY is -130, then this function will
// return the string "(10, -130)".
//
// REMARKS
// The C++ Standard Library stringstream class is a stream class
which is similar in functionality to the
// ostream class (the class of the cout object that we use to send
output to the output window). The difference
// between a stringstream object and cout is that for the stringstr
eam object, the "output" is sent to a string
// object which is encapsulated within the stringstream object. F
or example,
//
// stringstream sout; --
sout is a stringstream object which encapsulates a string.
// sout << fixed << setprecision(3); --
8. sout is configured so real numbers will be formatted in fixed no
tation
// with 3 digits after the decimal pt.
// sout << "Fred"; --
The string in sout now contains "Fred".
// int x = 123;
// sout << ' ' << x; --
The string in sout now contains "Fred 123".
// double y = 3.14159265828;
// sout << endl << y; --
The string in sout now contains "Fred 123n3.142".
// cout << sout.str(); --
The str() function returns the string, i.e., "Fred 123n3.142".
//
// Ref: http://cplusplus.com/reference/sstream/stringstream
//
// PSEUDOCODE
// Define a stringstream object named sout calling the default ct
or.
// Send to sout "(" followed by the return value from getX() foll
owed by ", " followed by getY() followed by ")".
// Return sout.str().
//-------------------------------------------------------------------------
-------------------------------------
???
Lab08/Point.hpp
//***************************************************
*****************************************************
******
// FILE: Point.hpp
//
9. // DESCRIPTION: Declares a class to represent a point in the
Cartesian plane. A point is represented by an
// (x, y) coordinate, where both x and y are integers.
//
// AUTHORS: your-name (your-email-address)
// your-partner's-name (your-partners-email-address)
//
// COURSE: CSE100 Principles of Programming with C++,
Fall 2015
//
// LAB INFO: Lab 8 Date/Time: your-lab-date-and-time
TA: your-lab-ta
//***************************************************
*****************************************************
******
#ifndef POINT_HPP // This line, the line below it, and the
#endif form what is called a preprocessor guard.
#define POINT_HPP // Preprocessor guards are a hack to
ensure a header file is not included multiple times.
#include <string> // For string class
10. using namespace std;
class Point {
public:
Point(); // Default constructor
Point(int pInitX, int pInitY); // Second constructor
double distance(Point pAnotherPoint); // Calculates
distance from this Point to pAnotherPoint
int getX(); // Accessor function for mX
data member
int getY(); // Accessor function for mY
data member
void move(int pNewX, int pNewY); // Moves the point
to a new coordinate
void setX(int pNewX); // Mutator function for
mX data member
void setY(int pNewY); // Mutator function for
mY data member
string toString(); // Returns a string
representation of the Point
private:
11. void init(int pInitX, int pInitY); // Initializes mX and
mY to the params pInitX and pInitY
int mX; // The x coordinate of the
Point
int mY; // The y coordinate of the
Point
};
#endif // POINT_HPP
Lab08/PointTest.cppLab08/PointTest.cpp//*****************
*****************************************************
****************************************
// FILE: PointTest.cpp
//
// DESCRIPTION: Implementation of the PointTest class. See P
ointTest.hpp for more info.
//
// AUTHORS: your-name (your-email-address)
// your-partner's-name (your-partners-email-address)
//
// COURSE: CSE100 Principles of Programming with C++, F
all 2015
//
// LAB INFO: Lab 8 Date/Time: your-lab-date-and-
time TA: your-lab-ta
//***************************************************
*****************************************************
******
12. #include<iomanip>// For setprecision()
#include<iostream>// For cout, endl, fixed
#include"PointTest.hpp"// For the PointTest class declaration
#include"Point.hpp"// For the Point class declaration
usingnamespace std;
//-------------------------------------------------------------------------
-------------------------------------
// FUNCTION: getInt()
//
// DESCRIPTION
// Display a prompt and read a number (as an int) from the keyb
oard. Return the number.
//-------------------------------------------------------------------------
-------------------------------------
int getInt(string pPrompt)
{
cout << pPrompt;
int n;
cin >> n;
return n;
}
//-------------------------------------------------------------------------
-------------------------------------
// CTOR: PointTest()
//
// DESCRIPTION
// Default constructor. Does nothing.
//
// REMARKS
// Every class must have at least one ctor, because when an obje
ct is instantiated, a ctor must be called. If
// there are no data members to initialize, then we just provide a
default ctor that does nothing.
13. //-------------------------------------------------------------------------
-------------------------------------
PointTest::PointTest()
{
}
//-------------------------------------------------------------------------
-------------------------------------
// FUNCTION: run()
//
// DESCRIPTION
// Tests the implementation of the Point class.
//
// PSEUDOCODE
// Define x and y as int variables.
// Configure cout so real numbers are displayed in fixed notatio
n with 3 digits after the decimal pt.
// x <- getInt("Enter point p1 x? ").
// y <- getInt("Enter point p1 y? ").
// Define and instantiate a Point object named p1 passing x and
y as the params to the ctor.
// x <- getInt("Enter point p2 x? ").
// y <- getInt("Enter point p2 y? ").
// Define and instantiate a Point object named p2 passing x and
y as the params to the ctor.
// Send to cout "The point p1 is " followed by p1.toString() foll
owed by endl.
// Send to cout "The point p2 is " followed by p2.toString() foll
owed by endl.
// Send to cout "The distance between the points is " followed b
y p1.distance(p2) followed by endl.
// Send to cout "Moving point p1...".
// Call p1.move(100, 200).
// Send to cout "The point p1 is now at " followed by p1.toStrin
g() followed by endl.
// Send to cout "The distance between the points is " followed b
14. y p2.distance(p1) followed by endl.
// Send to cout "Moving point p2...".
// Call p2.move(300, 400).
// Send to cout "The point p2 is now at " followed by p2.toStrin
g() followed by endl.
// Send to cout "The distance between the points is " followed b
y p1.distance(p2) followed by endl.
//-------------------------------------------------------------------------
-------------------------------------
???
Lab08/PointTest.hpp
//***************************************************
*****************************************************
******
// FILE: PointTest.hpp
//
// DESCRIPTION: Declares a class that will be used to test the
Point class.
//
// AUTHORS: your-name (your-email-address)
// your-partner's-name (your-partners-email-address)
//
// COURSE: CSE100 Principles of Programming with C++,
Fall 2015
//
15. // LAB INFO: Lab 8 Date/Time: your-lab-date-and-time
TA: your-lab-ta
//***************************************************
*****************************************************
******
#ifndef POINTTEST_HPP
#define POINTTEST_HPP
// Class declaration for a class named PointTest. The class only
has one constructor, the default constructor.
// The run() function is called to perform the testing of the Point
class.
// See the PointTest UML class diagram in the lab project
document.
???
#endif