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

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...
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
C++ ONLY WITH COMMENTS Question: Producer / Consumer Create a program where the application accepts 2...
C++ ONLY WITH COMMENTS Question: Producer / Consumer Create a program where the application accepts 2 arguments form the command line. The first one is a number where it is a producer of threads and the second one is number of consumer threads. You are allowed to use vector as a buffer and if so then please consider it as the buffer infinite. The producers will create the widgets and will put them on the buffer however the consumer will...
Source code with comments explaining your code in C# Program 2: Buh-RING IT! For this assignment,...
Source code with comments explaining your code in C# Program 2: Buh-RING IT! For this assignment, you’re going to simulate a text-based Role-Playing Game (RPG). Design (pseudocode) and implement (source) for a program that reads in 1) the hero’s Hit Points (HP – or health), 2) the maximum damage the hero does per attack, 3) the monster’s HP and 4) the maximum monster’s damage per attack. When the player attacks, it will pick a random number between 0 and the...
Card Shuffling and Dealing (C++) All in one file with comments explaining please! Create a program...
Card Shuffling and Dealing (C++) All in one file with comments explaining please! Create a program to shuffle and deal a deck of cards. The program should consist of a class Card, class DeckOfCards and a driver program. Class Card should provide: a)      Data members face and suit of type int. b)      A constructor that receives two ints representing the face and suit and uses them to initialize the data members. c)      Two static arrays of strings representing the faces...
hi,I have this C++ program,can someone add few comments with explanation what is the logic and...
hi,I have this C++ program,can someone add few comments with explanation what is the logic and what is what?thank you I m total beginner #include <iostream> using namespace std; int ArraySum(int MyArray[], int size){ int* p = MyArray; int sum = 0; while(p<MyArray+size){ sum += *p; p++; } return sum; } int main() { int MyArray[10] = {4, 0, 453, 1029, 44, 67, 111, 887, 4003, 1002}; cout<<ArraySum(MyArray,10); return 0; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT