Question

Please create an array of Leg objects, one constructor that takes three parameters as constant C...

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?

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
c++ C++ CLASSES and objects DO ADD COMMENTS DISPLAY OUTPUT First make three files: episode.cpp, episode.h...
c++ C++ CLASSES and objects DO ADD COMMENTS DISPLAY OUTPUT First make three files: episode.cpp, episode.h andRun.cpp to separate class header and implementation. In this program, we are going to create a small scale Telivision Management System. A) Create a class Episode with following variables: char* episode_name, char* episode_venue, char episode_date[22] and char episode_time[18]. Input format for episode_date: dd-mm-yyyy Input format for episode_time: hh:mm am/pm B) Implement default constructor and overloaded constructor. Print “Default Constructor Called” and “Overloaded Constructor Called”...
JAVA please Arrays are a very powerful data structure with which you must become very familiar....
JAVA please Arrays are a very powerful data structure with which you must become very familiar. Arrays hold more than one object. The objects must be of the same type. If the array is an integer array then all the objects in the array must be integers. The object in the array is associated with an integer index which can be used to locate the object. The first object of the array has index 0. There are many problems where...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the following subsections can all go in one big file called pointerpractice.cpp. 1.1     Basics Write a function, int square 1(int∗ p), that takes a pointer to an int and returns the square of the int that it points to. Write a function, void square 2(int∗ p), that takes a pointer to an int and replaces that int (the one pointed to by p) with its...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT