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.
#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;
}
Comments
Leave a comment