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

Create a program using C++(microsoft visual studios 2013) with comments (//comme

ID: 3811930 • Letter: C

Question

Create a program using C++(microsoft visual studios 2013) with comments (//comments) using the following instruction:

Populate a two-dimensional array with the following prices in this table order:

22.33      68.30      36.99    43.94     63.67    55.89

13.77      87.13      54.99    87.78     18.42    21.60

66.03      41.38     74.48     24.21    67.10    61.23

Write a method/function which uses loops and is called from main() that increases the prices by 4% and stores the new price in the same array. All changes to the array must be made inside the method/function. Please display the original array in table form as well as the new array with the 4% price increase.

Explanation / Answer

#include <iostream>
#include <cstdlib>   
#include <ctime>
using namespace std;
void raisePriceBy4(double prices[], int n){
for(int i=0; i<n; i++){
prices[i] =prices[i]+ (prices[i] * 4 )/100;
}
}

int main()
{
double prices[] = {22.33,68.30,36.99,43.94,63.67,55.89,
13.77,87.13,54.99,87.78,18.42,21.60,
66.03,41.38,74.48,24.21,67.10,61.23};
cout<<"Original array prices are "<<endl;

for(int i=0; i<18; i++){
if(i % 6 == 0){
cout<<endl;
}
cout<<prices[i]<<" ";
}

cout<<endl;
raisePriceBy4(prices, 18);
cout<<"New array prices are "<<endl;

for(int i=0; i<18; i++){
if(i % 6 == 0){
cout<<endl;
}
cout<<prices[i]<<" ";
}

cout<<endl;

return 0;
}

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                                                                                                                                                                

sh-4.2$ main                                                                                                                                                                                                                                                             

Original array prices are                                                                                                                                                                                                                                                

                                                                                                                                                                                                                                                                         

22.33 68.3 36.99 43.94 63.67 55.89                                                                                                                                                                                                                                       

13.77 87.13 54.99 87.78 18.42 21.6                                                                                                                                                                                                                                       

66.03 41.38 74.48 24.21 67.1 61.23                                                                                                                                                                                                                                       

New array prices are                                                                                                                                                                                                                                                     

                                                                                                                                                                                                                                                                         

23.2232 71.032 38.4696 45.6976 66.2168 58.1256                                                                                                                                                                                                                           

14.3208 90.6152 57.1896 91.2912 19.1568 22.464                                                                                                                                                                                                                           

68.6712 43.0352 77.4592 25.1784 69.784 63.6792

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