Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help with c++ please Write a program that declares three one dimensional arrays

ID: 3686936 • Letter: H

Question

Help with c++ please Write a program that declares three one dimensional arrays named price, quantity, and amount. Each array should be declared in main () and should be capable of holding ten double-precision numbers. The numbers that should be stored in price are 10.64, 14.89, 15.21,77.21, 23.8,61.26,92.37, 12.73, 2.99, 58.16. The numbers should be stored in quantity are 4, 8,17,2,94,65,20,78,55,41. You program should pass these three arrays to a function named extend (), which should calculate the elements in the amount array as the product of the corresponding elements in the price and quantity arrays (for example, amount [1] = price [1] * quantity [1]). After extend () have put values into the amount array, the array should be display from within main (). Write the extend () function using pointers.

Explanation / Answer

#include <iostream>

using namespace std;

void extend(double *price, double *quantity, double *amount);

int main()
{
   double price[10] = {10.64, 14.89, 15.21, 77.21, 23.8, 61.26, 92.37, 12.73, 2.99, 58.16};
   double quantity[10] = {4, 8,17, 2, 94, 65, 20, 78, 55, 41};
   double amount[10];

   extend(price, quantity, amount);

   cout << "Amount [0] = " << amount[0] << endl << "Amount [1] = " << amount[1] << endl;
   cout << "Amount [2] = " << amount[2] << endl << "Amount [3] = " << amount[3] << endl;
   cout << "Amount [4] = " << amount[4] << endl << "Amount [5] = " << amount[5] << endl;
   cout << "Amount [6] = " << amount[6] << endl << "Amount [7] = " << amount[7] << endl;
   cout << "Amount [8] = " << amount[8] << endl << "Amount [9] = " << amount[9] << endl;


   return 0;

}

void extend(double *price, double *quantity, double *amount)
{

   amount[0] = price[0] * quantity[0];
   amount[1] = price[1] * quantity[1];
   amount[2] = price[2] * quantity[2];
   amount[3] = price[3] * quantity[3];
   amount[4] = price[4] * quantity[4];
   amount[5] = price[5] * quantity[5];
   amount[6] = price[6] * quantity[6];
   amount[7] = price[7] * quantity[7];
   amount[8] = price[8] * quantity[8];
   amount[9] = price[9] * quantity[9];
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote