Q.No.3: 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;
// it is used to store the location of the token
class Angle
{
public:
double lati;
double longi;
};
// Token_number class have two private member variables token number, position
class Token_number
{
private:
int token_number;
Angle position;
public:
Token_number(){}
Token_number(int x)
{token_number = x;}
void set_position(Angle posi)
{
position = posi;
}
//Show the token information
void display_token_information()
{
cout<<"-------------------------\n";
cout<<"token number is : "<<token_number<<"\n";
cout<<"Location of the token is given as:\n";
cout<<"Latitude : "<<position.lati<<"\n";
cout<<"Latitude : "<<position.longi<<"\n";
}
};
int main()
{
vector<Token_number*> vec;
cout<<"Information of the 3 toeken\n";
for(int i=0;i<3;i++)
{
cout<<"ENTER THE TOKEN INFORMATION "<<i+1<<"\n";
int x;
cout<<"Enter the token number\n";
cin>>x;
Token_number *t=new Token_number(x);
cout<<"Enter the position of token (latitude and longitude position)\n";
double longi,lati;
cin>>lati>>longi;
Angle a;
a.lati = lati;
a.longi = longi;
t->set_position(a);
vec.push_back(t);
}
for(int i=0;i<3;i++)
{
vec[i]->display_token_information();
}
}
Comments
Leave a comment