Define an array of 10 pointers to floating point numbers. Usefor loop: Initializ
ID: 3616050 • Letter: D
Question
Define an array of 10 pointers to floating point numbers. Usefor loop: Initializing and allocating spaces for thosepointers. Then use loop to read (ask the user to input) 10 numbersinto the individual locations referenced by the pointers. Remembereach array cell is a pointer. You cannot directly assign thevalue to the array cell. Use pointer dereference assignment. Addall of the values those pointers are pointing to and store theresult in a pointer - referenced location (create another pointerfor total). Use for loop again to display the contents which thepointers in the array are pointing to.
Explanation / Answer
#include <iostream>using namespace std;
int main(){ float *pointers[10]; float *sum = new float; for (short a=0; a<10; a++){ pointers[a] = new float; float temp; cin >> temp; *sum += temp; *pointers[a] = temp; }/*for*/ cout << " "; for (short a=0; a<10; a++){ cout << *pointers[a] << " "; }/*for*/ cout << " " << *sum << " "; system("pause"); return 0; }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.