Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a definition of a class named Point that might be used to store and manipu

ID: 2990530 • Letter: W

Question

Write a definition of a class named Point that might be used to store and manipulate the location of a point in the plane. This program should present a menu with the following options. It should accept both upper and lower case letters for the options, and if what is entered is not one of the options it should print 'That is not a valid option' and display the menu again. The options are as follows:
s: set the coordinated of point
m: move a point
r: rotate a point
q: quit
PLEASE read the entire instructions. This program is different than the others posted on here.

Write a definition of a class named Point that might be used to store and manipulate the location of a point in the plane. This program should present a menu with the following options. It should accept both upper and lower case letters for the options, and if what is entered is not one of the options it should print 'That is not a valid option' and display the menu again. The options are as follows: s: set the coordinated of point m: move a point r: rotate a point q: quit PLEASE read the entire instructions. This program is different than the others posted on here. Programming Project 3 from Chapter 6 of Absolute C++ 5th ed. (Sawitch). pg. 271: The type Point is a fairly simple data type. but under another name (the template class pair) this data type is defined and used in the C++ Standard Template Library. although you need not know anything about the Standard Template Library to do this exercise. Write a definition of a class named Point that might be used to store and manipulate the location of a point in the plane. You will need to declare and implement the following member functions: a. A member function set that sets the private data alter an object of this class is created. b. A member function to move the point by an amount along the vertical and horizontal directions specified by the first and second arguments. c. A member function to rotate the point by 90 degrees clockwise around the origin. d. Two const inspector functions to retrieve the current coordinates of the point.

Explanation / Answer

DO RATE if satisfied

/*
* Point_test.cpp
*
* Created on: Oct 31, 2014
*      Author: Sivanag
*/

#include <iostream>
using namespace std;

#include <math.h>
/*
*
*/
class Point {
private:
    float x, y;
public:
    Point(){
           x = 0;
           y = 0;
    }
    void set(float x, float y){
        this->x = x;
        this->y = y;
    }
    void move(float x, float y){
        this->x += x;
        this->y += y;
    }
    void rotate(float degree){
        float tx = x, ty = y;
        float angle = 3.141592654*degree/180.0;
        x = tx*cos(-angle) - ty*sin(-angle);
        y = tx*sin(-angle) + ty*cos(-angle);
    }

    float getX() const {
        return x;
    }

    void setX(float x) {
        this->x = x;
    }

    float getY() const {
        return y;
    }

    void setY(float y) {
        this->y = y;
    }
};

int requestPoint(){
    int ch = 0;

    do{
        cout << "Which point would you like to select (1-3): " << endl;
        cin >> ch;
         if(ch >=1 && ch<=3)
             return ch;
         else
             cout<<"Invalid selection of point." <<endl;
    }while(1);
    return 0;
}

int main(){

    Point points[3];
    bool exit = false;
    char choice;
    float x, y, angle;
    int pi;

    while( !exit ){
        cout << "s: set the coordinate of point" << endl;
        cout << "m: move point" << endl;
        cout << "r: rotate point" << endl;
        cout << "q: quit" << endl;
        cout << "Select an option: " << endl;

        cin >> choice;

        switch( choice ){

            case 's' :
            case 'S' :
                pi = requestPoint();
                cout << "Enter X, Y seperated by space: ";
                cin >> x >> y;
                points[pi].set(x, y);
                cout << "Point " << pi << " set to ("
                        << points[pi].getX() << ", "
                        << points[pi].getY() << ")" << endl;
                break;
            case 'm' :
            case 'M' :
                pi = requestPoint();
                cout << "Point " << pi << " current value = ("
                        << points[pi].getX() << ", "
                        << points[pi].getY() << ")" << endl;
                cout << "Enter X, Y values of movement "
                        "seperated by space: ";
                cin >> x >> y;
                points[pi].move(x, y);
                cout << "Point " << pi << " moved to ("
                        << points[pi].getX() << ", "
                        << points[pi].getY() << ")" << endl;
                break;

            case 'r' :
            case 'R' :
                pi = requestPoint();
                cout << "Point " << pi << " current value = ("
                        << points[pi].getX() << ", "
                        << points[pi].getY() << ")" << endl;
                cout << "Enter angle of rotation:";
                cin >> angle;
                points[pi].rotate(angle);
                cout << "Point " << pi << " moved to ("
                        << points[pi].getX() << ", "
                        << points[pi].getY() << ")" << endl;
                break;
            case 'q' :
            case 'Q' :
                exit = true;
                break;
            default : cout << "This is not a valid option"<<endl;
        }
    }

    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote