In: Computer Science
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?
Solution:
PLEASE GIVE IT A ATHUMBS UP, I SERIOUSLY NEED ONE
using namespace std; 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 class Leg{ const char* const startCity; const char* const endCity;
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;
}
Code screenshot:
#hope u got the answer please give me a like...thank u...