Ask Question
23 October, 06:45

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.

+5
Answers (1)
  1. 23 October, 07:06
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers