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

How short can you write this dynamic array program: Write program, which uses dy

ID: 3918686 • Letter: H

Question

How short can you write this dynamic array program:

Write program, which uses dynamic arrays, that allows the user to enter the last names of several salespeople for a local car dealership and the number of monthly car sales made be each salesperson. Before this information is entered, the user is to be prompted for the number of salespeople whose information will be entered.   The program must then output each salesperson’s name, number of car sales, and the percentage of total sales made by the salesperson. Your program must also output the person with the highest sales. A sample output is :

Monthly Sales Report

        Salesperson                      Sales Made            % of Total Sales

            Miller                                   21                             24.14

            Jackson                                17                             19.54

            Sipos                                      5                               5.75

            Mandich                               32                             36.78

            Homer                                  12                             13.79

       Salesperson with highest sales is Mandich.

///////////////////please explain as thorough as possible with as many //comments to fully teach this to a person who has limited knowledge///////////////////////

Explanation / Answer

#include<iostream>
#include<string>
#include<iomanip>

using namespace std;

int main(){
   
   string *name;
   int *sales;
   double *percentsales;
   cout << "Enter number of sales persons:";
   int n;
   cin >> n;
   name = new string[n];
   sales = new int[n];
   percentsales = new double[n];
   double total = 0;
   int max = 0;
   int maxi = 0;
   for (int i = 0; i<n; i++){
      cout << "Enter last name of the sales person:";
      cin >> name[i];
      cout << "Enter number of cars sold:";
      cin >> sales[i];
      total = total + sales[i];
      if (sales[i] > max){
          max = sales[i];
          maxi = i;
      }
   }
   for (int i = 0; i<n; i++){
       percentsales[i] = ((double)sales[i]/(total)) * 100.0;
   }
   cout << "Monthly Sales Report ";
   cout << setw(20) << left << "Salesperson";
   cout << setw(20) << left << "Sales Made";
   cout << setw(20) << left << "% of Total Sales" << endl;
  
   for (int i = 0; i<n; i++){
       cout << setw(20) << left << name[i];
       cout << setw(20) << left << sales[i];
       cout << setw(20) << left << fixed << setprecision(2) << percentsales[i] << endl;
   }
   cout << "Salesperson with highest sales is " << name[maxi] << endl;
   delete [] name;
   delete [] sales;
   delete [] percentsales;
   return 0;
}

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