for sales data. Other than declaring the variables and opening the input and out
ID: 3686522 • Letter: F
Question
for sales data.
Other than declaring the variables and opening the input and output files, the function mainshould only be a collection of function calls.
The contents of CIS022_S2016_Lab9.txt in the proper order are
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 type SalesType, which has six components:LastName, FirstName, and Region of type string, MonthlySales of type float, Status of typestring, and HighSales of type boolean. Use this file:CIS022_S2016_Lab9.txt
for sales data.
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 mainshould only be a collection of function calls.
The contents of CIS022_S2016_Lab9.txt in the proper order are
Savoy Daron Fairfield 1,803.52 Stevenson Shaniya Vacaville 1,571.06 Langlois Darin Fairfield 2,012.06 Layne Casandra Vacaville 2,101.25 Backus Felipe Fairfield 3,852.00 Anderson Andrew Vacaville 2,510.75 Brody Irwin Vacaville 3,299.77 Polanco Belva Dixon 2,025.00 Cummings Savanna Dixon 1,906.78 Nevarez Cecile Fairfield 1,628.47 Winfrey Humberto Vacaville 1,470.88 Quinn Shamika Vallejo 5,874.19 Crocker Leanne Vacaville 1,598.63 Strassberg Gerson Vallejo 1,835.16 Mcnair Alena Fairfield 1,250.00 Harper Brennon Fairfield 998.09 Tomlin Ellen Vallejo 877.25 Zeller Lavern Elmira 1,103.16 Barnett Rosalyn Vallejo 2,657.81 Couture Tremayne Fairfield 1,408.85 Mccool Deon Fairfield 1,549.13 Powell Neta Fairfield 1,515.94 Steel Fletcher Fairfield 1,155.69 Anderson Valary Vacaville 2,873.75 Brown Michael Fairfield 1,956.94 Youngblood Maribeth Fairfield 1,704.55 Cedeno Dusty Vallejo 3,675.75 Flanagan Giselle Fairfield 1,512.50 Cosgrove Mitch Fairfield 551.25 Lear Shande Vallejo 1,438.83 Field Jill Suisun 1,208.22 Ellington Jame Fairfield 2,656.25 Layman Lanny Suisun 4,500.00 Mccormick Sonia Fairfield 1,759.80 Knapp Zelda Vacaville 1,542.75 Hogg Darrien Fairfield 2,153.78 Rey Alvino Vacaville 2,408.25 Ridley Fannie Fairfield 1,391.50 Wheaton Ronnie Fairfield 1,776.00 Crandall Walker Fairfield 945.56 Garero Devon Vacaville 1,460.81 Rupert Barrett Fairfield 3,464.50 Johnsen Damian Dixon 2,088.28 Wildon Sarah Pinole 2,420.00 Ruff Alma Vallejo 2,326.20 Kearns Ashanti Fairfield 975.00 Donohue Brook Vallejo 1,819.13 Lopez Dudley Suisun 3,506.75 Larue Emogene Fairfield 2,964.50 Beatty Jaylene Fairfield 1,956.94 Walsh Joe Fairfield 1,708.88 Hoyt Laquita Vallejo 1,917.39 Gaddis Rand Vacaville 2,370.38 Dillon Trena Vallejo 1,339.55 Simpson Ona Rio Vista 1,733.44 Conger Garett Fairfield 2,281.31 Lanham Malcolm Vallejo 898.44 Tindall Jacob Travis 4,800.00 Parkinson Carl Pinole 2,420.00 Warez Amber Fairfield 2,468.97
Explanation / Answer
The data you have posted: In MonthlySale data ',' (comma) is included.
Please remove comma and save in file. Then My program will work fine.
#include <iostream>
#include <cstdlib>
#include<cstring>
#include<fstream>
using namespace std;
/*
Structure to store students data
*/
struct SalesType
{
string LastName;
string FirstName;
string Region;
float MonthlySales;
string Status;
int HighSales;
};
struct SalesType* readSalesData();
void assignStatus(struct SalesType sales[], int n);
void higestSale(struct SalesType sales[], int n);
void print(struct SalesType sales[], int n);
/*
* Entry point
*/
int main()
{
int n = 60;
struct SalesType *sales;
sales = readSalesData();
assignStatus(sales, n);
higestSale(sales, n);
print(sales, n);
return 0;
}
struct SalesType* readSalesData()
{
struct SalesType *sales;
ifstream read("CIS022_S2016_Lab9.txt");
int i=0;
sales = new SalesType[60];
while(read>>sales[i].LastName>>sales[i].FirstName>>sales[i].Region>>sales[i].MonthlySales)
{
i++;
}
read.close();
return sales;
}
void assignStatus(struct SalesType sales[], int n){
int i;
for (i = 0; i < n; i++){
if(sales[i].MonthlySales >= 4000)
sales[i].Status = "Outstanding";
else if(sales[i].MonthlySales >= 3000)
sales[i].Status = "Excellent";
else if(sales[i].MonthlySales >= 2000)
sales[i].Status = "Good";
else if(sales[i].MonthlySales >= 1000)
sales[i].Status = "Poor";
else
sales[i].Status = "Unacceptable";
}
}
void higestSale(struct SalesType sales[], int n){
float higest = sales[0].MonthlySales;
int i;
for(i=1; i<n; i++){
if(higest < sales[i].MonthlySales)
higest = sales[i].MonthlySales;
}
for(i=0; i<n; i++){
if(higest == sales[i].MonthlySales)
sales[i].HighSales = 1; // true
else
sales[i].HighSales = 0; // false
}
}
void print(struct SalesType sales[], int n){
int i = 0;
while(i<n)
{
cout<<sales[i].LastName<<" "<<sales[i].FirstName<<" "<<
sales[i].Region<<" "<<sales[i].MonthlySales<<" "<<sales[i].Status<<" "<<sales[i].HighSales<<endl;
i++;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.