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

Q1 c++ Write a program that declares three one dimensional arrays named price, q

ID: 3686647 • Letter: Q

Question

Q1 c++

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>
#include <iomanip>

using namespace std;

void extend(double *price, int *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};
   int quantity[10] = {4, 8, 17, 2, 94, 65, 20, 78, 55, 41};
   double amount[10];
  
   //calling extend functio
   extend(price, quantity, amount);
  
   cout<<setprecision(2)<<fixed;
   for(int i=0; i<10; i++){
       cout<<"Amount of "<<quantity[i]<<" and price "<<price[i]<<" is: "<<amount[i]<<endl;
       }
   return 0;
}

void extend(double *price, int *quantity, double *amount){
  
   for(int i=0; i<10; i++){
       *(amount+i) = *(quantity+i)*(*(price+i));
   }
}

/*

sample run:

Amount of 4 and price 10.64 is: 42.56
Amount of 8 and price 14.89 is: 119.12
Amount of 17 and price 15.21 is: 258.57
Amount of 2 and price 77.21 is: 154.42
Amount of 94 and price 23.80 is: 2237.20
Amount of 65 and price 61.26 is: 3981.90
Amount of 20 and price 92.37 is: 1847.40
Amount of 78 and price 12.73 is: 992.94
Amount of 55 and price 2.99 is: 164.45
Amount of 41 and price 58.16 is: 2384.56

*/