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

Programming Langauge: C++ Read the problem. Write a program that reads sales dat

ID: 3809042 • Letter: P

Question

Programming Langauge: C++

Read the problem.

Write a program that reads sales data from individual sales associates, calculates their standing, determines the associate with the highest sales, and writes the data to a text file.

Sales data should be stored in a struct variable of typeSalesType, which has six components: LastName, FirstName,and Region of type string, MonthlySales of type float, Statusof type string, and HighSales of type boolean.

Input file contains this data

Savoy   Daron   Fairfield   1803.52
Stevenson   Shaniya   Vacaville   1571.06
Langlois   Darin   Fairfield   2012.06
Layne   Casandra   Vacaville   2101.25
Backus   Felipe   Fairfield   3852.00
Anderson   Andrew   Vacaville   2510.75
Brody   Irwin   Vacaville   3299.77
Polanco   Belva   Dixon   2025.00
Cummings   Savanna   Dixon   1906.78
Nevarez   Cecile   Fairfield   1628.47
Winfrey   Humberto   Vacaville   1470.88
Quinn   Shamika   Vallejo   5874.19
Crocker   Leanne   Vacaville   1598.63
Strassberg   Gerson   Vallejo   1835.16
Mcnair   Alena   Fairfield   1250.00
Harper   Brennon   Fairfield   998.09
Tomlin   Ellen   Vallejo   877.25
Zeller   Lavern   Elmira   1103.16
Barnett   Rosalyn   Vallejo   2657.81
Couture   Tremayne   Fairfield   1408.85
Mccool   Deon   Fairfield   1549.13
Powell   Neta   Fairfield   1515.94
Steel   Fletcher   Fairfield   1155.69
Anderson   Valary   Vacaville   2873.75
Brown   Michael   Fairfield   1956.94
Youngblood   Maribeth   Fairfield   1704.55
Cedeno   Dusty   Vallejo   3675.75
Flanagan   Giselle   Fairfield   1512.50
Cosgrove   Mitch   Fairfield   551.25
Lear   Shande   Vallejo   1438.83
Field   Jill   Suisun   1208.22
Ellington   Jame   Fairfield   2656.25
Layman   Lanny   Suisun   4500.00
Mccormick   Sonia   Fairfield   1759.80
Knapp   Zelda   Vacaville   1542.75
Hogg   Darrien   Fairfield   2153.78
Rey   Alvino   Vacaville   2408.25
Ridley   Fannie   Fairfield   1391.50
Wheaton   Ronnie   Fairfield   1776.00
Crandall   Walker   Fairfield   945.56
Garero   Devon   Vacaville   1460.81
Rupert   Barrett   Fairfield   3464.50
Johnsen   Damian   Dixon   2088.28
Wildon   Sarah   Pinole   2420.00
Ruff   Alma   Vallejo   2326.20
Kearns   Ashanti   Fairfield   975.00
Donohue   Brook   Vallejo   1819.13
Lopez   Dudley   Suisun   3506.75
Larue   Emogene   Fairfield   2964.50
Beatty   Jaylene   Fairfield   1956.94
Walsh   Joe   Fairfield   1708.88
Hoyt   Laquita   Vallejo   1917.39
Gaddis   Rand   Vacaville   2370.38
Dillon   Trena   Vallejo   1339.55
Simpson   Ona   Vacaville   1733.44
Conger   Garett   Fairfield   2281.31
Lanham   Malcolm   Vallejo   898.44
Tindall   Jacob   Travis   4800.00
Parkinson   Carl   Pinole   2420.00
Warez   Amber   Fairfield   2468.97

-------------------------------------------------------------------------------------------------------------------------------------------------------

The file contains 60 records. Load the records into an array of type SalesType containing 60 elements.


Your program must contain at least the following functions:

Determine the sales associate's Status using the following table:

The output file should be a text file with the following data:LastName, FirstName, Region, MonthlySales and Status. Each of these items should be separated by 3 spaces. Each sales associate's record should be on a separate line in the file. The sales associate, or associates with the highest monthly sales should have the text "Performer" appended to their record (separated from the Status by 1 space).

Other than declaring the variables and opening the input and output files, the function main should only be a collection of function calls.

1.

Read the problem.

Write a program that reads sales data from individual sales associates, calculates their standing, determines the associate with the highest sales, and writes the data to a text file.

Sales data should be stored in a struct variable of typeSalesType, which has six components: LastName, FirstName,and Region of type string, MonthlySales of type float, Statusof type string, and HighSales of type boolean.

Input file contains this data

Savoy   Daron   Fairfield   1803.52
Stevenson   Shaniya   Vacaville   1571.06
Langlois   Darin   Fairfield   2012.06
Layne   Casandra   Vacaville   2101.25
Backus   Felipe   Fairfield   3852.00
Anderson   Andrew   Vacaville   2510.75
Brody   Irwin   Vacaville   3299.77
Polanco   Belva   Dixon   2025.00
Cummings   Savanna   Dixon   1906.78
Nevarez   Cecile   Fairfield   1628.47
Winfrey   Humberto   Vacaville   1470.88
Quinn   Shamika   Vallejo   5874.19
Crocker   Leanne   Vacaville   1598.63
Strassberg   Gerson   Vallejo   1835.16
Mcnair   Alena   Fairfield   1250.00
Harper   Brennon   Fairfield   998.09
Tomlin   Ellen   Vallejo   877.25
Zeller   Lavern   Elmira   1103.16
Barnett   Rosalyn   Vallejo   2657.81
Couture   Tremayne   Fairfield   1408.85
Mccool   Deon   Fairfield   1549.13
Powell   Neta   Fairfield   1515.94
Steel   Fletcher   Fairfield   1155.69
Anderson   Valary   Vacaville   2873.75
Brown   Michael   Fairfield   1956.94
Youngblood   Maribeth   Fairfield   1704.55
Cedeno   Dusty   Vallejo   3675.75
Flanagan   Giselle   Fairfield   1512.50
Cosgrove   Mitch   Fairfield   551.25
Lear   Shande   Vallejo   1438.83
Field   Jill   Suisun   1208.22
Ellington   Jame   Fairfield   2656.25
Layman   Lanny   Suisun   4500.00
Mccormick   Sonia   Fairfield   1759.80
Knapp   Zelda   Vacaville   1542.75
Hogg   Darrien   Fairfield   2153.78
Rey   Alvino   Vacaville   2408.25
Ridley   Fannie   Fairfield   1391.50
Wheaton   Ronnie   Fairfield   1776.00
Crandall   Walker   Fairfield   945.56
Garero   Devon   Vacaville   1460.81
Rupert   Barrett   Fairfield   3464.50
Johnsen   Damian   Dixon   2088.28
Wildon   Sarah   Pinole   2420.00
Ruff   Alma   Vallejo   2326.20
Kearns   Ashanti   Fairfield   975.00
Donohue   Brook   Vallejo   1819.13
Lopez   Dudley   Suisun   3506.75
Larue   Emogene   Fairfield   2964.50
Beatty   Jaylene   Fairfield   1956.94
Walsh   Joe   Fairfield   1708.88
Hoyt   Laquita   Vallejo   1917.39
Gaddis   Rand   Vacaville   2370.38
Dillon   Trena   Vallejo   1339.55
Simpson   Ona   Vacaville   1733.44
Conger   Garett   Fairfield   2281.31
Lanham   Malcolm   Vallejo   898.44
Tindall   Jacob   Travis   4800.00
Parkinson   Carl   Pinole   2420.00
Warez   Amber   Fairfield   2468.97

-------------------------------------------------------------------------------------------------------------------------------------------------------

The file contains 60 records. Load the records into an array of type SalesType containing 60 elements.


Your program must contain at least the following functions:

a. A function to read the sales data into the array. b. A function to assign the relevant Status to each sales associate. c. A function to find the highest sales. d. A function to print the sales data.

Determine the sales associate's Status using the following table:

$0 - 999.99 Unacceptable $1000.00 - 1999.99 Poor $2000.00 - 2999.99 Good $3000.00 - 3999.99 Excellent $4000.00 - above Outstanding

The output file should be a text file with the following data:LastName, FirstName, Region, MonthlySales and Status. Each of these items should be separated by 3 spaces. Each sales associate's record should be on a separate line in the file. The sales associate, or associates with the highest monthly sales should have the text "Performer" appended to their record (separated from the Status by 1 space).

Other than declaring the variables and opening the input and output files, the function main should only be a collection of function calls.

Explanation / Answer

#include <iostream>

#include <fstream>

#include <string.h>

using namespace std;

struct SalesType
{
   string LastName;
   string FirstName;
   string Region;
   float MonthlySales;
   string Status;
   bool HighSales;
};

void ReadData(SalesType salesdata[], ifstream& fin)
{
   int i=0;
   while( !fin.eof() )
   {
       fin >> salesdata[i].LastName;
       fin >> salesdata[i].FirstName;
       fin >> salesdata[i].Region;
       fin >> salesdata[i].MonthlySales;
       i++;
   }
}

void AssignStatus(SalesType salesdata[], int size)
{
   for(int i=0; i<size; i++)
   {
       if(salesdata[i].MonthlySales < 1000)
           (salesdata[i].Status).assign("Unacceptable");
       else if(salesdata[i].MonthlySales < 2000)
           (salesdata[i].Status).assign("Poor");
       else if(salesdata[i].MonthlySales < 3000)
           (salesdata[i].Status).assign("Good");
       else if(salesdata[i].MonthlySales < 4000)
           (salesdata[i].Status).assign("Excellent");
       else if(salesdata[i].MonthlySales >= 4000)
           (salesdata[i].Status).assign("Outstanding");
   }
}

void FindHighestSales(SalesType salesdata[], int size)
{
   float max = 0;
   int index = 0;

   for (int i=0; i<size; i++)
   {
       salesdata[i].HighSales = false;
       if(salesdata[i].MonthlySales>max)
       {
           max = salesdata[i].MonthlySales;
           index = i;
       }
   }

   salesdata[index].HighSales = true;
}

void PrintData(SalesType salesdata[], int size, ofstream& fout)
{
   for(int i=0; i<size; i++)
   {
       fout << salesdata[i].LastName << "   ";
       fout << salesdata[i].FirstName << "   ";
       fout << salesdata[i].Region << "   ";
       fout << salesdata[i].MonthlySales << " ";

       if(salesdata[i].HighSales == true)
           fout << "Performer";
       fout << endl;
   }
}

int main()
{
   SalesType salesdata[60];
   ifstream fin;
   fin.open("InputData.txt");            //The input file containing the Associates' data

   ReadData(salesdata, fin);

   AssignStatus(salesdata, 60);

   FindHighestSales(salesdata, 60);

   ofstream fout;
   fout.open("OutputData.txt");
   PrintData(salesdata, 60, fout);

   fin.close();
   fout.close();
}