Extra Credit: (15 pts) Do it in C+ t Select only one from the following (5a or 5
ID: 3919435 • Letter: E
Question
Extra Credit: (15 pts) Do it in C+ t Select only one from the following (5a or 5b): 5a- Write a program that stores the following numbers in the array named rates: 6.25,6.50,6.8,7.2,7.35,7.5,7.65,7.8,8.2,8.4,8.6,8.8, and 9.0. Display the values in the array by changing the address in a pointer called disptr. Use for statement in your program. 5b-Write a C++ program that adds equivalent elements of the two dimensional arrays named first and second. Both arrays should have two rows and three columns. For example, element [1][2] of the resulting array should be the sum of first[1]12] and second[1][2] The first and second arrays should be initialized as follows: First 16 54 18 91 Second 52 19 23 24 16 59Explanation / Answer
5a)
#include <iostream>
using namespace std;
int main() {
double rates[] = {6.25, 6.50, 6.8, 7.2, 7.35, 7.5, 7.65, 7.8, 8.2, 8.4, 8.6, 8.8, 9.0};
for(double *disptr = rates; disptr < rates+13; disptr++) {
cout << *disptr << endl;
}
return 0;
}
5b)
#include <iostream>
using namespace std;
int main() {
int first[2][3] = {{16, 18, 23}, {54, 91, 11}};
int second[2][3] = {{24, 52, 77}, {16, 19, 59}};
for(int i = 0; i < 2; ++i) {
for(int j = 0; j < 3; ++j) {
cout << first[i][j] + second[i][j] << " ";
}
cout << endl;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.