Answer to Question #185808 in C++ for muhammad

Question #185808

: 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-26T16:18:00-0400
#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();
    }


}

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