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.

Respuesta :

Answer:

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;