Ask Question

Write a declaration for a class named City, which has the members cityName, a string, and position, a Location structure (declared above). Then define a variable named destination that is an instance of the City structure, as if it were being used in main.

+4
Answers (1)
  1. 10 April, 02:31
    0
    Following are the statements for the above question in c+ + language:-

    class City / /Class definition.

    {

    string cityName; / /String data type for cityName variable.

    Location position; / /Structure Location data type for position variable.

    };

    City destination; / /class city variable destination.

    Explanation:

    The above question asked to declare a class whose name is the city which contains the two variable cityname of type string and position of type Location structure which is defined above. So the above-defined are the statement which does all task. But before the use of it, any user needs to define the location structure otherwise the statement "Location position; " gives the compile-time error. The syntax to define a class and the instances is defined below : -

    Class class_name

    {

    //datatype variable

    }

    class_name instances_name;
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a declaration for a class named City, which has the members cityName, a string, and position, a Location structure (declared above). ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers