Q1. How would you declare each of the following?
a. actors is an array of 30 char.
b. betsie is an array of 100 short.
c. chuck is an array of 13 float.
d. dipsea is an array of 64 long double.
A:
char actors[30];
shrt betsie[100];
float chuck[13];
long double dipsea[64];
Q2. Does Chapter Review Question 1 use the array template class instead of built-in arrays.
A:
array<char, 30>actors;
array<short, 100>betsie;
array<float, 13>chuck;
array<long double, 64>dipsea;
A:
int oddly[5] = {1, 3, 5, 7, 9};
Q4. Write a statement that assigns the sum of the first and last elements of the array in Question 3 to the variable even.
A:
int even = oddly[o] + oddly[4];
Q5. Write a statement that displays the value of the second element in the float array ideas.
A:
cout << ideas[1] << endl;
Q6. Declare an array of char and initialize it to the string "cheeseburger".
A:
char lunch[13] = "cheeseburger";
// number of characters + 1
or
char lunch[] = "cheeseburger";
// let the compiler count elements
Q7. Declare a string object and initialize it to the string "Waldorf Salad".
A:
string lunch = " Waldorf Salad";
or, if you don't have a using directive,
std::string lunch = "Waldorf Salad";
Q8. Devise a structure declaration that describes a fish. The structure should include the kind, the weight in whole ounces, and the length in fractional inches.
A:
structure fish
{
char kind[20];
int weight;
float length;
};
Q9. Declare a variable of the type defined in Question 8 and initialize it.
A:
fish petes =
{
"trout".
12,
26.25
};