Question

In: Computer Science

In C++ fill in the comments the easiest to get the program work and get this...

In C++ fill in the comments the easiest to get the program work and get this output.

Sample Output

Please input the x: 2.5

Please input the y: -5

Please input the x: 3

Please input the y: 7.5

You entered: ( 2.5, -5 ) and ( 3, 7.5 )

point3 is ( 2.5, -5 )

Press any key to continue . . .

#include <iostream>   // For cout and cin
#include <iomanip>    // For formatting output, e.g. setprecision
#include <string>     // For using string data type

using namespace std; // Avoid need to use std:: qualification on cout and other things

class Point {

private:
    // WRITE declarations of x and y as doubles
    // x and y coordinates of the point

public:
    // WRITE declaration of getX, getY, setX, setY, readCoords, and printCoords
    // WRITE definitions of these member functions after definition of main().

    // getX - Get the value of the x member variable
        
    // getY - Get the value of the y member variable

    // setX - Set the value of the x member variable

    // setY - Set the value of the y member variable
       
    // readCoords - Fill in the x, y values with user input

    // printCoords - Display in format ( x, y )
  
    // For Future Lab:
    // double getSlope( Point );      // Determine slope between this point and another point

    // For Future Lab:
    // Point getMidpoint( Point );    // Determine midpoint between this point and another point

};

int main()
{
    // Do "Press any key to continue..." on exit
    atexit([] {system("pause"); });

    Point point1; // Two points for testing methods
    Point point2; //
  
    // Obtain values for points from user.
    point1.readCoords();
    point2.readCoords();

    // Show the values on the console.
    cout << "You entered: ";
    point1.printCoords();
    cout << " and ";
    point2.printCoords();
    cout << endl;

    // Create a point3 that is a pointer to a Point object.
    // Initialize point3 to a Point object that you allocate using the new operator.
    // Set its x and y from point1, and print its coords.
    // Finally, delete the object.
    // WRITE code for point3 here.
  
  
    // For future lab: Report the slope of the line connecting the points.
    //cout << "The slope between them is " << point1.getSlope(point2) << endl;

    // For future lab: Report the midpoint of the line connecting the points.
    //cout << "The midpoint between them is ";
    //point1.getMidpoint(point2).printCoords();
    //cout << endl;

    return 0;
}

// =================================================================
// getX()
//    return the value of the x attribute
//
// Purpose: Provide the user with access to the x value
// Input:   none
// Output: returns the value of the objects x data member
//
// YOU WRITE THIS
}

// =================================================================
// getY()
//    return the value of the y attribute
//
// Purpose: Provide the user with access to the y value
// Input:   none
// Output: returns the value of the objects y data member
//
// YOU WRITE THIS


// =================================================================
// setX()
//    sets the value of the x attribute
//
// Purpose: Allows the user to change the x value
// Input:   the new x value
// Output: none
//
// YOU WRITE THIS


// =================================================================
// setY()
//    sets the value of the y attribute
//
// Purpose: Allows the user to change the y value
// Input:   the new y value
// Output: none
//
// YOU WRITE THIS

// =================================================================
// readCoords()
//    fill in the x,y with user input.
//
// Purpose: Asks the user for the x,y coordinates and
//            sets the values into the object.
// Input:   none
// Output: none
//
void Point::readCoords {
    // YOU WRITE THIS
} // end readCoords()


// =================================================================
// printCoords()
//    display in format (x,y))
//
// Purpose: Display the x and y attributes on the console in the format ( x, y )).
// Assume: x,y have been initialized.
// Input:   none
// Output: none
//
void Point:: printCoords() {
    // YOU WRITE THIS
} // end printCoords())


/*
// =================================================================
// getSlope()
// Calculate the slope between two points
//
// Purpose: Given a second point, calculates and returns the
// value of the slope between those two points as defined by
//        m = ( y2 - y1 ) / ( x2 - x1 )
// Assume: This point, and the other point, have both been initialized.
// Input:   A second point object
// Output: Returns the slope of the line segment between them.
//
double Point::getSlope( Point other ) {
// YOU WRITE THIS (for future lab)
// Note: x1 and y1 are the x and y in this object
//       while x2 and y2 are the x and y in the parameter other.
    return 0.0;
} // end getSlope()

// =================================================================
// getMidpoint())
// Determine midpoint between two points
//
// Purpose: Calculate the midpoint between points in 2 point objects.
//   The midpoint is defined by ( (x1+x2)/2.0, (y1+y2)/2.0 ).
// Assume: This point, and the other point, have both been initialized.
// Input:   A second point object
// Output: Returns the point that is the midpoint between them.

Point Point::getMidpoint( Point other ) {
    Point midpoint; // between this point and 'other'

    // Initialize midpoint so that code compiles without errors before
    // implementing this function.
    midpoint.x = 0.0;
    midpoint.y = 0.0;
  
    // YOU WRITE THIS (for future lab)
    // Note: x1 and y1 are the x and y in this object
    //       while x2 and y2 are the x and y in the parameter other.
    return midpoint;
  
} // end getMidpoint()
*/

Solutions

Expert Solution

I have done the required work and this program will give the given output with the given output:

#include <iostream> // For cout and cin
#include <iomanip> // For formatting output, e.g. setprecision
#include <string> // For using string data type

using namespace std; // Avoid need to use std:: qualification on cout and other things

class Point {

private:
// WRITE declarations of x and y as doubles
// x and y coordinates of the point
double x, y;

public:
// WRITE declaration of getX, getY, setX, setY, readCoords, and printCoords
// WRITE definitions of these member functions after definition of main().

// getX - Get the value of the x member variable
double getX();
  
// getY - Get the value of the y member variable
double getY();

// setX - Set the value of the x member variable
void setX(double);

// setY - Set the value of the y member variable
void setY(double);
  
// readCoords - Fill in the x, y values with user input
void readCoords();

// printCoords - Display in format ( x, y )
void printCoords();
  
// For Future Lab:
// double getSlope( Point ); // Determine slope between this point and another point

// For Future Lab:
// Point getMidpoint( Point ); // Determine midpoint between this point and another point

};

int main()
{
// Do "Press any key to continue..." on exit
atexit([] {system("pause"); });

Point point1; // Two points for testing methods
Point point2; //
  
// Obtain values for points from user.
point1.readCoords();
point2.readCoords();

// Show the values on the console.
cout << "You entered: ";
point1.printCoords();
cout << " and ";
point2.printCoords();
cout << endl;

// Create a point3 that is a pointer to a Point object.
// Initialize point3 to a Point object that you allocate using the new operator.
// Set its x and y from point1, and print its coords.
// Finally, delete the object.
// WRITE code for point3 here.
    Point *point3;
point3 = new Point;
*point3 = point1;
cout << "Third Point is: ";
point3->printCoords();
delete point3;
  
cout << endl;
  
// For future lab: Report the slope of the line connecting the points.
//cout << "The slope between them is " << point1.getSlope(point2) << endl;

// For future lab: Report the midpoint of the line connecting the points.
//cout << "The midpoint between them is ";
//point1.getMidpoint(point2).printCoords();
//cout << endl;

return 0;
}

// =================================================================
// getX()
// return the value of the x attribute
//
// Purpose: Provide the user with access to the x value
// Input: none
// Output: returns the value of the objects x data member
//
// YOU WRITE THIS
double Point::getX() {
   return x;
}

// =================================================================
// getY()
// return the value of the y attribute
//
// Purpose: Provide the user with access to the y value
// Input: none
// Output: returns the value of the objects y data member
//
// YOU WRITE THIS
double Point::getY() {
   return y;
}

// =================================================================
// setX()
// sets the value of the x attribute
//
// Purpose: Allows the user to change the x value
// Input: the new x value
// Output: none
//
// YOU WRITE THIS
void Point::setX(double a) {
   x = a;
}

// =================================================================
// setY()
// sets the value of the y attribute
//
// Purpose: Allows the user to change the y value
// Input: the new y value
// Output: none
//
// YOU WRITE THIS
void Point::setY(double a) {
   y = a;
}

// =================================================================
// readCoords()
// fill in the x,y with user input.
//
// Purpose: Asks the user for the x,y coordinates and
// sets the values into the object.
// Input: none
// Output: none
//
void Point::readCoords() {
cout << "Please input the x: ";
cin >> x;
cout << "Please input the y: ";
cin >> y;
} // end readCoords()


// =================================================================
// printCoords()
// display in format (x,y))
//
// Purpose: Display the x and y attributes on the console in the format ( x, y )).
// Assume: x,y have been initialized.
// Input: none
// Output: none
//
void Point:: printCoords() {
cout << "(" << x << ", " << y << ")";
} // end printCoords())

Hope this helps. If you have any queries or suggestions regarding the answers please leave them in the comments section so I can update and improve the answer. Thank you.


Related Solutions

The program should be written in C++ with comments Write a program that takes graduation rates...
The program should be written in C++ with comments Write a program that takes graduation rates (per 1000 of the population) for North, South, East, West and Central United States. Input the number from each of the regions in a function returning an int with the graduation rate to the main program. Also figure out which region has the highest graduation rate in another function and display the result from inside that particular function. So your function prototypes should be...
i need C++ program with possible comments what is going on,(a) Write a program that reads...
i need C++ program with possible comments what is going on,(a) Write a program that reads a char as input, and determines if it is a lowercase letter, uppercase letter, a digit or something else (call the last one a special character).
Please write a complete C coding program (NOT C++) that has the following: (including comments) -...
Please write a complete C coding program (NOT C++) that has the following: (including comments) - declares two local integers x and y - defines a global structure containing two pointers (xptr, yptr) and an integer (z) - declares a variable (mst) by the type of previous structure - requests the values of x and y from the user using only one scanf statement - sets the first pointer in the struct to point to x - sets the second...
I need to complete this C++ program. The instructions are in the comments inside the code...
I need to complete this C++ program. The instructions are in the comments inside the code below: ------------------------------------------------------------------------- Original string is: this is a secret! Encypted string is: uijt!jt!b!tfdsfu" Decrypted string is: this is a secret! //Encoding program //Pre-_____? //other necessary stuff here int main() { //create a string to encrypt using a char array cout<< "Original string is: "<<string<<endl; encrypt(string); cout<< "Encrypted string is: "<<string<<endl; decrypt(string); cout<<"Decrypted string is: "<<string<<endl; return 0; } void encrypt(char e[]) { //Write implementation...
If answer can be shown using a c++ program and leave comments it will be very...
If answer can be shown using a c++ program and leave comments it will be very appreciated!!! A bank charges $10 per month plus the following check fees for a commercial checking account: $0.10 each for fewer than 20 checks $0.08 each for 20-39 checks $0.06 each for 40-59 checks $0.04 each for 60 or more checks The bank also charges an extra $15.00 if the balance of the account falls below $400 (before any check fees are applied). Write...
C++ program to read line comments. This assignment will give you a little bit of practice...
C++ program to read line comments. This assignment will give you a little bit of practice with string parsing. Your task is to write a program that reads in a .cpp file line-by-line, and prints out only the text that's after the // characters that indicate a single-line comment. You do not have to worry about /* multiline comments */ though there will be a small amount of extra credit for programs that correctly extract these comments as well.
PLEASE PROVIDE COMMENTS ON STEPS Write a C++ program that modifies a string (null terminated) as...
PLEASE PROVIDE COMMENTS ON STEPS Write a C++ program that modifies a string (null terminated) as follows: Consonants are positioned at the beginning of the string and vowels are moved to the end of the string. Example : Original string : washer New string : wshrae Note: The library string functions cannot be used. You must use pointers and the switch statement to execute this program. Assume that the vowels are a, e, i, o, and u. The modification has...
C++ Download the attached program and complete the functions. (Refer to comments) main.cpp ~ #include #include...
C++ Download the attached program and complete the functions. (Refer to comments) main.cpp ~ #include #include #define END_OF_LIST -999 using namespace std; /* * */ int exercise_1() { int x = 100; int *ptr; // Assign the pointer variable, ptr, to the address of x. Then print out // the 'value' of x and the 'address' of x. (See Program 10-2) return 0; } int exercise_2() { int x = 100; int *ptr; // Assign ptr to the address of...
write a simple program to explain vector type in c++... use comments to explain plz
write a simple program to explain vector type in c++... use comments to explain plz
Complete the program used on the instructions given in the comments: C++ lang #include <string> #include...
Complete the program used on the instructions given in the comments: C++ lang #include <string> #include <vector> #include <iostream> #include <fstream> using namespace std; vector<float>GetTheVector(); void main() { vector<int> V; V = GetTheVector(); //reads some lost numbers from the file “data.txt" and places it in //the Vector V Vector<int>W = getAverageOfEveryTwo(V); int printTheNumberOfValues(W) //This should print the number of divisible values by 7 //but not divisible by 3. PrintIntoFile(W); //This prints the values of vector W into an output file...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT