Answer to Question #185947 in C++ for ismail khan

Question #185947

Define a class called ‘token number’ that incorporates a token’s number and its location. Number each token object as it is created. Use two variables of the angle class to represent the token’s latitude and longitude. A member function of the token class should get a position from the user and store it in the object; another should report the serial number and position. Design a main() program that creates three token, asks the user to input the position of each, and then displays each token’s number and position.



1
Expert's answer
2021-04-27T20:33:45-0400
#include <iostream>
using namespace std;
int tokens = 0;
class Angle{
    float degrees;
    public:
    Angle(){}
    Angle(float x): degrees(x){}
    float deg(){return degrees;}
};
class TokenNumber{
    int number;
    Angle longitude, latitude;
    public:
    TokenNumber(){
        tokens++;
        number = tokens;
        }
    void getPosition(){
        float x, y;
        cout<<"Input longitude: ";
        cin>>x;
        cout<<"Input latitude: ";
        cin>>y;
        cout<<endl;
        longitude = Angle(x);
        latitude = Angle(y);
    }
    void display(){
        cout<<"\nToken number: "<<number;
        cout<<"\nLongitude: "<<longitude.deg();
        cout<<"\nLatitude: "<<latitude.deg()<<endl;
    }
};
int main(){
    TokenNumber t1, t2, t3;
    t1.getPosition();
    t2.getPosition();
    t3.getPosition();


    t1.display();
    t2.display();
    t3.display();
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS