Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Overview This assignment utilizes a class in an application that might be useful in the real world. It requires the sorting of and computation with

Overview

This assignment utilizes a class in an application that might be useful in the real world. It requires the sorting of and computation with data stored in a vector inside of a class. In this assignment, you will design an Object-Oriented program and manipulate data using a vector within the class.

Instructions

You are working for a car dealership and have been tasked to create an application that will maintain a list of sales and some related statistics for a salesperson.

Class and Data members:

Create a class called Salesperson that stores a salespersons sales amounts (integers) in a vector (do not use an array). The class should have data members that store a salespersons name, the dealership name for which the salesperson works, a sales goal, and a commission percentage.

Constructors:

Zero argument that initializes the data members to 0 or as appropriate.

Four argument that receives the salespersons name, the dealership name, the sales goal, and the commission percent as parameters and sets the appropriate data members to these values.

Data Members:

salespersonName string

dealershipName string

salesGoal integer

commissionPercentage double

sales vector of int

Member Functions:

Setters and getters for each of the data members of salespersons name, company name, sales goal, and commission percent variables.

addSalesAmount() that adds a single sale to the vector. Only positive sales are allowed.

sortSalesAmounts() that sorts the vector in ascending order.

calcSalesAverage() that computes the average of the sales amounts in the vector.

The formula for calculating an average is x = xi / n where xi is the value of each sales amount and n is the total number of sales amounts in the vector.

getSmallestSale() that determines the smallest sales amount in the vector

getLargestSale() to determine the largest sales amount in the vector.

Note that to receive credit for these functions, getSmallestSale() and getLargestSale(), they must contain an algorithm to search through the vector to determine the minimum or maximum value. You cannot simply sort the vector and return the first or last data member or use the *min_element or *max_element functions.

getNumberSales() that returns the number of sales amounts that are stored in the vector.

Remember that a vector knows its own size. Therefore, you do not need to keep track of the number of items stored in a vector in a separate data member in the class. You also dont want to make your vector public it should be private. Therefore, you can create a public getNumSales() function that will return the size of the vector.

calcTotalSales() calculates and returns the total of all the sales amounts in the vector.

calcCommissionEarned() calculates and returns the commission earned on Total Sales

displaySalesInfo() displays the salespersons name, company name, sales goal, commission percent, total sales, commission earned, and vector of sorted sales.

Write a program (client) that uses the class by creating a Salesperson object and prompting the user for a file name. Also, the name of the file may contain a space; therefore, be sure to use getline() instead of cin when you prompt the user to enter the name of the file. Note: File Name means the path and name of the file.

The client should read the file contents and store them in the object. The file will be formatted as follows:

1st line Name of sales person

2nd line Name of dealership

3rd line Sales goal

4th line Commission percented (in whole numbers)

5th line through the end of the file, the end of the file Sales (in whole number)

Note: Be sure to end each line ends with the Enter key and leave 1 blank line at the end of the file.

Below is an example of the standard data file. You may use your own data, but be sure the entries match what each line is as defined above. Note the blank line at the end of the example file, and ensure your test data files also has a blank line at the end.

Note that the file may contain any number of sales amounts for a given salesperson. Therefore, you need to read in and store each sales amount until you reach the end of the file.

The client (i.e. main()) should read the contents of the file. After each sales amount is read in, it should call the addSale() function in the Salesperson class to add the new sale (i.e., one sales amount at a time) to the vector.

Note: Do not create a vector in main and pass the entire vector into the addSale() function in the Salesperson class. Pass in only one sales amount at a time and allow the addSale() function to add it to the vector of sales amounts in the class.

The main() should then call the displaySalesInfo() function to produce a report that displays the dealerships name, the salespersons name, sales goal, total sales, commission percentage, the commission earned, smallest sale, largest sale, number of sales made, an average of all sales made, and finally, a listing of all of the sales amounts that were read in. The listing of all of the sales amounts must be displayed in sorted order (ascending from lowest to highest).

All output should be labeled appropriately, and validity checking should be done on the input of the filename and the sales amounts that are read in.

If a non-numeric or negative value is encountered in the file when reading the sales amounts, the program should output an error message indicating that a non-numeric or negative value was found in the file, and the entire program should then terminate. If a non-numeric or negative value is found, consider the entire file to be corrupted, and do not try to produce any calculations, nor display the contents of the vector just end the program with an appropriate error message. [Make sure the error message is displayed long enough for the user to read it before ending the program. you may use the system(pause) command for this. Note that there are several security and performance issues with using system commands, and youll learn more about these later, but for now, feel free to use the system(pause) command.]

In the output example shown above, notice that the average of the sales amounts is displayed with decimal points. Whenever you are calculating a statistic like an average, never truncate the decimal portion unless you are told to do so. Imagine if you were averaging your grades and got 89.9 you definitely do not want your final grade truncated to 89. Therefore, in this assignment, do not truncate the decimal portion of the sales amounts average you calculate. Remember the rules of integer division. That is, an int divided by an int is an int. Therefore, make sure to convert the numerator or denominator to a double before performing the division.

If a negative sales goal, commission percentage, or sales amount is read in, the program output should look something like the screenshot below. Note that the first screenshot shows the full screen, while the rest of the error message screenshots only show the expected message.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions