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

Exercises 1: 1. Create a new project on Visual Studio 2. Copy dArray.cpp below i

ID: 3543663 • Letter: E

Question

Exercises 1:

1.       Create a new project on Visual Studio

2.      Copy dArray.cpp below into a .cpp file in your project

======================================= DArray.cpp ======================================

#include <iostream>

#include <iomanip>

using namespace std;

void GetSales(float *, int);

int main()

{

       float *monthSales; // a pointer used to point to an array holding monthly sales

       float average; // average of monthly sales

       int numOfSales; // number of sales to be processed

       float total = 0; // total of all sales

       float average; // average of monthly sales

       cout << fixed << showpoint << setprecision(2);

       cout << "How many monthly sales will be processed? ";

       cin >> numOfSales;

       //******** Fill in the code to allocate memory for the array pointed to by monthSales.

       if ( /********Fill in the condition to determine if memory has been allocated */ )

       {

              cout << "Error allocating memory! ";

              return 1;

       }

       

       //***** write code to call function to read sales data from stdin into the dynamically allocated array

       for (int count = 0; count < numOfSales; count++)

       {

              total = total + monthSales[count];

       }

       average = //**** Fill in code to find the average;

       cout << "Average Monthly sale is $" << average << endl;

       //****** Fill in the code to deallocate memory assigned to the array.

       return 0;

}

void GetSales(float *dataPtr, int numOfSales)

{

       cout << "Enter the sales below ";

       for (int count = 0; count < numOfSales; count++)

       {

              

              cout << "Sales for Month number "  << //******* Fill in code to show the number of the month

              << ":";

              

              //****** Fill in code to read and store sales into an element of the array

       }

}

=====================================================================================

3.       The file has a program that read a list of sales data from the standard input device and computes and outputs their average. The user is prompted to input the number of sales data items.  Complete the missing code in the program and in function GetSales.  The missing code is indicated with comment statements preceded with /********.

4.      Once competed demo your program to your instructor.  Turn-in a copy of your program.

Exercises 2:

5.       Repeat the same steps as above but with file dArray2.cpp below.

=========================== dArray2.cpp ============================================

#include <iostream>

#include <iomanip>

using namespace std;

float * GetSales(int numOfSales);

int main()

{

       float *monthSales; // a pointer used to point to an array holding monthly sales float total = 0;

       float average; // average of monthly sales

       int numOfSales; // number of sales to be processed

       float total = 0; // total of all sales

       float average; // average of monthly sales

       cout << fixed << showpoint << setprecision(2);

       //***** write code to call function to read sales data from stdin into the dynamically allocated array

       for (int count = 0; count < numOfSales; count++)

       {

              total = total + monthSales[count];

       }

       average = //**** Fill in code to find the average;

       cout << "Average Monthly sale is $" << average << endl;

       //****** Fill in the code to deallocate memory assigned to the array.

       return 0;

}

float * GetSales(int numOfSales)

{

       float *dataPtr;

       cout << "How many monthly sales will be processed? ";

       cin >> numOfSales;

       //******** Fill in the code to allocate memory for the array pointed to by monthSales.

       if ( /********Fill in the condition to determine if memory has been allocated */ )

       {

              cout << "Error allocating memory! ";

              return NULL;

       }

       cout << "Enter the sales below ";

       for (int count = 0; count < numOfSales; count++)

       {

              

              cout << "Sales for Month number "  << //******* Fill in code to show the number of the month

              << ":";

              

              //****** Fill in code to read and store sales into an element of the array

       }

       return dataPtr;

}

Explanation / Answer

//this is your first code

#include <iostream>

#include <iomanip>

using namespace std;

void GetSales(float *, int);

int main()

{

float *monthSales; // a pointer used to point to an array holding monthly sales

float average; // average of monthly sales

int numOfSales; // number of sales to be processed

float total = 0; // total of all sales

cout << fixed << showpoint << setprecision(2);

cout << "How many monthly sales will be processed? ";

cin >> numOfSales;

//******** Fill in the code to allocate memory for the array pointed to by monthSales.

monthSales = new float[numOfSales];

if (monthSales==NULL)

{

cout << "Error allocating memory! ";

return 1;

}

//***** write code to call function to read sales data from stdin into the dynamically allocated array

GetSales(monthSales,numOfSales);


for (int count = 0; count < numOfSales; count++)

{

total = total + monthSales[count];

}

average = total/numOfSales;

cout << "Average Monthly sale is $" << average << endl;

//****** Fill in the code to deallocate memory assigned to the array.

free(monthSales);

return 0;

}



void GetSales(float *dataPtr, int numOfSales)

{

cout << "Enter the sales below ";

for (int count = 0; count < numOfSales; count++)

{

cout << "Sales for Month number "<<count+1<<":";

//****** Fill in code to read and store sales into an element of the array

cin>>dataPtr[count];

}

}

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