Write C++ statements to accomplish each of the following:
a) Display the value of element 6 of character array alphabet.
b) Input a value into element 4 of one-dimensional floating-point array grades.
c) Initialize each of the 5 elements of one-dimensional integer array values to 8.
d) Total and display the elements of floating-point array temperatures of 100 elements.
e) Copy array a into the first portion of array b. Assume that both arrays contain doubles and that arrays a and b have 11 and 34 elements, respectively.
f) Determine and display the smallest and largest values contained in 99-element floating- point array w.
```
a) cout << alphabet[6] << '\n';
b) cin >> grades[4];
c) array
d) double total{0.0};
for (int k{0}; k < 100; ++k) {
total += temperatures[k];
cout << temperatures[k] << '\n';
}
or
double total{0.0};
for (int temp : temperatures) {
total += temp;
cout << temp << '\n';
}
e) for (int i{0}; i < 11; ++i) {
b[i] = a[i];
}
f) double smallest{w[0]};
double largest{w[0]};
for (int j{1}; j < 99; ++j) {
if (w[j] < smallest) {
smallest = w[j];
}
else if (w[j] > largest) {
largest = w[j];
}
}
cout << smallest << ' ' << largest;
or you could write the loop as
for (double element : w) {
if (element < smallest) {
smallest = element;
}
else if (element > largest) {
largest = element;
}
} // end for
```
You might also like to view...
What operation does the ADT List have that an array does not?
a. identify their items by number b. getLength() c. insertItem() d. isEmpty()
Protocol analyzers can help solve problems from the Data Link layer up to the Application layer.
Answer the following statement true (T) or false (F)