: Define a class called token number that incorporates a token’s number (could be the last 3 digits of your arid 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<bits/stdc++.h>
using namespace std;
class Angle
{ public:
double latitude,longitude;
};
class TokenNumber
{
private:
int no;
Angle position_variable;
public:
TokenNumber();
TokenNumber(int y)
{
no = y;
}
void display_token()
{
cout<<"The token number is : "<<no;
cout<<"\nLocation of the token is given as:";
cout<<"\nLatitude : "<<position_variable.latitude;
cout<<"\nLatitude : "<<position_variable.longitude;
}
void set_position_function(Angle p)
{
position_variable = p;
}
};
int main()
{
TokenNumber* token_arr[3];
int y,i;
cout<<"Input the information of the 3 tokens\n";
for(i=0;i<3;i++)
{
cout<<"Enter the information of the token "<<i+1;
cout<<"\nProvide the token number ";
cin>>y;
TokenNumber *tk = new TokenNumber(y);
cout<<"\nProvide the position values of the token\n";
double longitude,latitude;
cin>>latitude>>longitude;
Angle Ang;
Ang.latitude = latitude;
Ang.longitude = longitude;
tk->set_position_function(Ang);
token_arr[i]=tk;
}
for(i=0;i<3;i++)
{
token_arr[i]->display_token();
}
}
Comments
Leave a comment