SlideShare ist ein Scribd-Unternehmen logo
1 von 16
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)
// 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
// 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
//-------------------------------------------------------------------------
-------------------------------------
// 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()
// 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)
//
// 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
//-------------------------------------------------------------------------
-------------------------------------
???
//-------------------------------------------------------------------------
-------------------------------------
// 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); --
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
//
// 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
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:
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
//***************************************************
*****************************************************
******
#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.
//-------------------------------------------------------------------------
-------------------------------------
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
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
//
// 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
Lab08Lab08.cppLab08Lab08.cpp.docx

Weitere ähnliche Inhalte

Ähnlich wie Lab08Lab08.cppLab08Lab08.cpp.docx

6Modify the bfs.java program (Listing A) to find the minimu.docx
6Modify the bfs.java program (Listing  A) to find the minimu.docx6Modify the bfs.java program (Listing  A) to find the minimu.docx
6Modify the bfs.java program (Listing A) to find the minimu.docx
evonnehoggarth79783
 
PQTimer.java A simple driver program to run timing t.docx
  PQTimer.java     A simple driver program to run timing t.docx  PQTimer.java     A simple driver program to run timing t.docx
PQTimer.java A simple driver program to run timing t.docx
joyjonna282
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
ARCHANASTOREKOTA
 

Ähnlich wie Lab08Lab08.cppLab08Lab08.cpp.docx (7)

6Modify the bfs.java program (Listing A) to find the minimu.docx
6Modify the bfs.java program (Listing  A) to find the minimu.docx6Modify the bfs.java program (Listing  A) to find the minimu.docx
6Modify the bfs.java program (Listing A) to find the minimu.docx
 
Casnewb
CasnewbCasnewb
Casnewb
 
Quiz using C++
Quiz using C++Quiz using C++
Quiz using C++
 
Stack, queue and hashing
Stack, queue and hashingStack, queue and hashing
Stack, queue and hashing
 
PQTimer.java A simple driver program to run timing t.docx
  PQTimer.java     A simple driver program to run timing t.docx  PQTimer.java     A simple driver program to run timing t.docx
PQTimer.java A simple driver program to run timing t.docx
 
STACK IMPLEMENTATION USING SINGLY LINKED LIST
STACK IMPLEMENTATION USING SINGLY LINKED LISTSTACK IMPLEMENTATION USING SINGLY LINKED LIST
STACK IMPLEMENTATION USING SINGLY LINKED LIST
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
 

Mehr von DIPESH30

Please submit a minimum of five (5) detailed and discussion-provokin.docx
Please submit a minimum of five (5) detailed and discussion-provokin.docxPlease submit a minimum of five (5) detailed and discussion-provokin.docx
Please submit a minimum of five (5) detailed and discussion-provokin.docx
DIPESH30
 
Please use the following technique-Outline the legal issues t.docx
Please use the following technique-Outline the legal issues t.docxPlease use the following technique-Outline the legal issues t.docx
Please use the following technique-Outline the legal issues t.docx
DIPESH30
 
Please share your thoughts about how well your employer, military .docx
Please share your thoughts about how well your employer, military .docxPlease share your thoughts about how well your employer, military .docx
Please share your thoughts about how well your employer, military .docx
DIPESH30
 
Please see the attachment for the actual work that is require.  This.docx
Please see the attachment for the actual work that is require.  This.docxPlease see the attachment for the actual work that is require.  This.docx
Please see the attachment for the actual work that is require.  This.docx
DIPESH30
 

Mehr von DIPESH30 (20)

please write a short essay to address the following questions. Lengt.docx
please write a short essay to address the following questions. Lengt.docxplease write a short essay to address the following questions. Lengt.docx
please write a short essay to address the following questions. Lengt.docx
 
please write a diary entry from the perspective of a French Revoluti.docx
please write a diary entry from the perspective of a French Revoluti.docxplease write a diary entry from the perspective of a French Revoluti.docx
please write a diary entry from the perspective of a French Revoluti.docx
 
Please write the definition for these words and provide .docx
Please write the definition for these words and provide .docxPlease write the definition for these words and provide .docx
Please write the definition for these words and provide .docx
 
Please view the filmThomas A. Edison Father of Invention, A .docx
Please view the filmThomas A. Edison Father of Invention, A .docxPlease view the filmThomas A. Edison Father of Invention, A .docx
Please view the filmThomas A. Edison Father of Invention, A .docx
 
Please watch the clip from the movie The Break Up.  Then reflect w.docx
Please watch the clip from the movie The Break Up.  Then reflect w.docxPlease watch the clip from the movie The Break Up.  Then reflect w.docx
Please watch the clip from the movie The Break Up.  Then reflect w.docx
 
please write a report on Social Media and ERP SystemReport should.docx
please write a report on Social Media and ERP SystemReport should.docxplease write a report on Social Media and ERP SystemReport should.docx
please write a report on Social Media and ERP SystemReport should.docx
 
Please write 200 wordsHow has the healthcare delivery system chang.docx
Please write 200 wordsHow has the healthcare delivery system chang.docxPlease write 200 wordsHow has the healthcare delivery system chang.docx
Please write 200 wordsHow has the healthcare delivery system chang.docx
 
Please view the documentary on Typhoid Mary at httpswww..docx
Please view the documentary on Typhoid Mary at httpswww..docxPlease view the documentary on Typhoid Mary at httpswww..docx
Please view the documentary on Typhoid Mary at httpswww..docx
 
Please use the two attachments posted to complete work.  Detailed in.docx
Please use the two attachments posted to complete work.  Detailed in.docxPlease use the two attachments posted to complete work.  Detailed in.docx
Please use the two attachments posted to complete work.  Detailed in.docx
 
Please use the sources in the outline (see photos)The research.docx
Please use the sources in the outline (see photos)The research.docxPlease use the sources in the outline (see photos)The research.docx
Please use the sources in the outline (see photos)The research.docx
 
Please submit a minimum of five (5) detailed and discussion-provokin.docx
Please submit a minimum of five (5) detailed and discussion-provokin.docxPlease submit a minimum of five (5) detailed and discussion-provokin.docx
Please submit a minimum of five (5) detailed and discussion-provokin.docx
 
Please think about the various learning activities you engaged in du.docx
Please think about the various learning activities you engaged in du.docxPlease think about the various learning activities you engaged in du.docx
Please think about the various learning activities you engaged in du.docx
 
Please type out the question and answer it underneath. Each question.docx
Please type out the question and answer it underneath. Each question.docxPlease type out the question and answer it underneath. Each question.docx
Please type out the question and answer it underneath. Each question.docx
 
Please use the following technique-Outline the legal issues t.docx
Please use the following technique-Outline the legal issues t.docxPlease use the following technique-Outline the legal issues t.docx
Please use the following technique-Outline the legal issues t.docx
 
Please use from these stratagies This homework will be to copyies .docx
Please use from these stratagies This homework will be to copyies .docxPlease use from these stratagies This homework will be to copyies .docx
Please use from these stratagies This homework will be to copyies .docx
 
PLEASE THOROUGHLY ANSWER THE FOLLOWING FIVE QUESTIONS BELOW IN.docx
PLEASE THOROUGHLY ANSWER THE FOLLOWING FIVE QUESTIONS BELOW IN.docxPLEASE THOROUGHLY ANSWER THE FOLLOWING FIVE QUESTIONS BELOW IN.docx
PLEASE THOROUGHLY ANSWER THE FOLLOWING FIVE QUESTIONS BELOW IN.docx
 
Please share your thoughts about how well your employer, military .docx
Please share your thoughts about how well your employer, military .docxPlease share your thoughts about how well your employer, military .docx
Please share your thoughts about how well your employer, military .docx
 
Please select and answer one of the following topics in a well-org.docx
Please select and answer one of the following topics in a well-org.docxPlease select and answer one of the following topics in a well-org.docx
Please select and answer one of the following topics in a well-org.docx
 
Please see the attachment for the actual work that is require.  This.docx
Please see the attachment for the actual work that is require.  This.docxPlease see the attachment for the actual work that is require.  This.docx
Please see the attachment for the actual work that is require.  This.docx
 
Please see the attachment and look over the LOOK HERE FIRST file b.docx
Please see the attachment and look over the LOOK HERE FIRST file b.docxPlease see the attachment and look over the LOOK HERE FIRST file b.docx
Please see the attachment and look over the LOOK HERE FIRST file b.docx
 

Kürzlich hochgeladen

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Kürzlich hochgeladen (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 

Lab08Lab08.cppLab08Lab08.cpp.docx

  • 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