Please create an array of Leg objects, one constructor that takes three parameters as constant C string, and one number representing the distance in miles between the two cities
Write a code block to create a static array (that is, not dynamic and not a vector) of 3 Leg objects using city names of your choosing. That's THREE objects, each created using THREE parameters. For example, the Leg class declaration looked like,
class Leg { const char* const startCity; const char* const endCity; const double distance; public: Leg(const char* const, const char* const, const double); };
HINT: "constant C strings" as parameters and as constant data members are const char* const constant read-only pointers. Do NOT use char arrays for this (that is, no square brackets).
I am not sure how can we create an array without square brackets?
int main(int argc, char const *argv[])
{
char *s = "Dehradun";
char *e = "Delhi";
char *s1 = "Jalandar";
char *e1 = "Amritsar";
char *s2 = "Chandigarh";
char *e2 = "Shimla";
Leg l[3] = {Leg(s,e,5),Leg(s1,e1,15),Leg(s2,e2,35) };
return 0;
}
THANK YOU!! PLEASE VOTE
Get Answers For Free
Most questions answered within 1 hours.