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;
class tokennumber {
private:
double token_num;
double token_lattitude;
double token_longitude;
public:
void getData(double tok_num, double tok_latt, double tok_longi) {
token_num=tok_num;
token_lattitude=tok_latt;
token_longitude=tok_longi;
}
double calculateloc() {
return token_lattitude + token_longitude;
}
};
int main() {
tokennumber tokennumber1;
tokennumber tokennumber2;
tokennumber tokennumber3;
tokennumber1.getData(425, 30.8, 19.2);
tokennumber2.getData(415, 33.8, 11.4);
tokennumber3.getData(315, 23.8, 61.4);
cout << "position of token 1 = " << tokennumber1.calculateloc() << endl;
cout << "position of token 2 = " << tokennumber2.calculateloc() << endl;
cout << "position of token 3 = " << tokennumber3.calculateloc() << endl;
return 0;
}
Comments
Leave a comment