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

This is C++. The purpose of this assignment is to demonstrates the use of dynami

ID: 3731069 • Letter: T

Question

This is C++.

The purpose of this assignment is to demonstrates the use of dynamic arrays using pointers.

Create a C++ program that will declare a pointer used to point to an array holding monthly sales ( with a dynamic size)

The program should read the monthly sales values then calculate and display the total of all sales and average of monthly sales.

Could you please be kind enough and show me the screeshot by uisng the Visual Studio and type the code?

Thank you so much for reading this and have a good one!

Explanation / Answer

PROGRAM

#include<iostream>

using namespace std;

int main()

{

double *msales=NULL; // create double pointer msales and initialize null value

int n; // declare integer variable for size of an array

double tot=0; // declare and initialize of tot is 0

cout<<"Enter How Many Months: ";

cin>>n; // read size

msales=new double[n]; // dynamic memory allocation of type double msales

cout<<" Enter Monthly Sales ";

for(int i=0;i<n;i++) // create for loop until the size of an array n

{

cout<<" Enter "<<i+1<<" Month: ";

cin>>msales[i]; // read the monthly sales

tot+=msales[i]; // calculate total monthly sales

}

cout<<"==============================";

cout<<" Total Sales: "<<tot<<endl; // display total sales

cout<<" Average Sales: "<<(float)tot/n<<endl; // calculate average monthly sales and display

cout<<"==============================";

return 0;

}

OUTPUT-1

Enter How Many Months: 5

Enter Monthly Sales

Enter 1 Month: 1235.25

Enter 2 Month: 4563.99

Enter 3 Month: 926.36

Enter 4 Month: 4576.25

Enter 5 Month: 5864.36
==============================
Total Sales: 17166.2

Average Sales: 3433.24
==============================

OUTPUT-2

Enter How Many Months: 7

Enter Monthly Sales

Enter 1 Month: 1564.56

Enter 2 Month: 8643.56

Enter 3 Month: 2365.44

Enter 4 Month: 6852.48

Enter 5 Month: 7893.55

Enter 6 Month: 4125.96

Enter 7 Month: 9999.85
==============================
Total Sales: 41445.4

Average Sales: 5920.77
==============================

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