Cplusplus 1 Suppose I set up a two dimensional array to stor

Cplusplus

1. Suppose I set up a two dimensional array to store a street address and apartment number, street name, and city name:

char address[3][128];

How would I pass this to a function? Please write the prototype for a function that receives this array as an argument. You can call the function any reasonable name you want, such as myFunction, setAddress, houseInfo, or whatever.

2. Take a look at these two structs, and the way they are related (one struct as a member of the other struct):

struct address {

   char streetName[128];

   int houseNumber;

   char city[128];

   int zip;

};

struct house {

   address houseAddress;

   int rooms;

   double baths;

   char color[128];

   int floors;

};

Now suppose I create an array of houses:

house neighborhood[10];

I would like to set the house number of the 3rd house in the neighborhood to 123. Remember that the 3rd house will be at index 2 (0 is first, 1 is second, and 2 is third). Please write the code to do that here.

Solution

1)
   char address[3][128];

   passing multidimensional arrays is, first array dimension does not have to be specified. The second (and any subsequent) dimensions must be given

   function prototype:

   void myFunction(char address[][128]);

   or

   void myFunction(char *address[]);

2)

struct address {
char streetName[128];
int houseNumber;
char city[128];
int zip;
};
struct house {
address houseAddress;
int rooms;
double baths;
char color[128];
int floors;
};

house neighborhood[10];

// code to set house number to third house

neighborhood[2].houseAddress.houseNumber = 123

Cplusplus 1. Suppose I set up a two dimensional array to store a street address and apartment number, street name, and city name: char address[3][128]; How woul
Cplusplus 1. Suppose I set up a two dimensional array to store a street address and apartment number, street name, and city name: char address[3][128]; How woul

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site