in the C++ program listed below, use pointer references to access all of the arr
ID: 3637236 • Letter: I
Question
in the C++ program listed below, use pointer references to access all of the array elements enclosed in the program.#include <iostream>
using namespace std;
int main()
{
const int MAXNUMS = 8;
int i, grade[MAXNUMS];
double avg, total = 0.0;
for (i = 0; i < MAXNUMS; i++) // Enter the numbers
{
cout << "Enter a grade: ";
cin >> grade[i];
}
cout << " The average of the grades ";
for (i = 0; i < MAXNUMS; i++) // Display and total the numbers
{
cout << " " << grade[i];
total = total + grade[i];
}
avg = total / MAXNUMS;
cout << " is " << avg << endl;
cin.ignore(2); // this line is optional
return 0;
}
Explanation / Answer
#include
using namespace std;
int main()
{
const int MAXNUMS = 8;
int i, grade[MAXNUMS];
double avg, total = 0.0;
for (i = 0; i < MAXNUMS; i++) // Enter the numbers
{
cout << "Enter a grade: ";
cin >> *(grade+i);
}
cout << " The average of the grades ";
for (i = 0; i < MAXNUMS; i++) // Display and total the numbers
{
cout << " " << *(grade+i);
total = total + *(grade+i);
}
avg = total / MAXNUMS;
cout << " is " << avg << endl;
cin.ignore(2); // this line is optional
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.