Answer to Question #185836 in C++ for usman

Question #185836

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.



1
Expert's answer
2021-04-27T13:12:53-0400
#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();
    }

}

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