Project #156671 - C++ programming

Computer Tutors

Subject Computer
Due By (Pacific Time) 11/30/2016 09:00 pm

You are going to write a C++ program to manage toy salesmen A salesman's data is updated periodically with sales and the time over which the money was collected.  When requested, it returns sales per hour.  A salesman can be updated many times before his/her sales per hour are requested, so the data needs to be accumulated.  When the sales per hour are requested, the sales per hour are calculated and the salesman's accumulated data are set back to zero.  You will maintain a list of such salesmen using commands to add, output, and update values in the list.

 

 

 

Requirements

 

 

 

You may lose up to 10 points if you do not adhere to the following, even if your program gives the right answers. 

 

 

 

1. You must use the following declarations:

 

 

 

const int MAX_NAME = 20;

 

const int MAX_SALESMEN = 5;

 

const int NOT_FOUND = -1;

 

 

 

struct Seller

 

{

 

   float sales;               // running total of money he collected

 

   float time;                // running total of time, in hours

 

   char name[MAX_NAME + 1];   // name of the salesman

 

};

 

 

 

struct ListOfSalesmen

 

{

 

   int num;                  // number of salesmen in the list

 

   Seller salesman[MAX_SALESMEN];

 

};

 

 

 

You must use these exactly as is.  You can't change them or add any additional fields.

 

 

 

 

 

 

 

2. You are only allowed to manipulate a Seller's fields via the following 4 functions:

 

 

 

void InitSeller ( Seller & s, const char name[] );

 

// Initializes the Salesman's name to name. 

 

// Initializes the Salesman's sales and time to 0.0.

 

 

 

void UpdateSales ( Seller & s, float sales, float time );

 

// Adds the money and time to the salesman's accumulated sales and time.

 

 

 

bool SellerHasName ( const Seller & s, const char name[] );

 

// Returns true if the salesman's name is the same as name; false otherwise.

 

 

 

float SalesValue ( Seller & s );

 

// Returns sales per hour for the salesman.

 

// Returns 0.0 if the salesman's time is 0.0.

 

// It also zeroes the salesman's sales & time when done calculating.

 

 

 

You must properly write and comment these functions.  None of these functions are allowed to print anything or read anything.  You will lose 3 points each time you access a Seller's fields outside of these functions, up to a maximum of 15 points.  To say this in another way:

 

 

 

Suppose you have a Seller called s.  You cannot say s.sales or s.name or s.time anywhere except in the four functions listed above.

 

 

 

3. You must have a Search or Find function.  

 

 

 

It is passed a ListOfSalesmen and a name.  It determines whether or not a Salesman with the specified name is in the ListOfSalesmen.  If it is, it returns the index of where the salesman is stored.  There is more than one way this can be done.   You will lose 5 points if you do not have this function.

 

 

 

4. You must have several other functions.

 

 

 

Do a good decomposition with several other functions beyond the five required above.

 

 

 

Input and Output Description

 

 

 

You will read and process commands from the standard input, quitting if the Q command is entered.  Commands consist of a single character, possibly followed by parameters.

 

The commands you are to implement are of the form:

 

 

 

        A name

 

        O name

 

        U name sales time

 

        Q

 

 

 

1.      A – Add command. Add a salesman with the given name to the end of the list if a salesman with that name doesn't already exist and the list isn't full. If a salesman with that name already exists or the list is full, still read in the data; however, don't do anything with the data read in (toss it!), and print an error message (check the full condition first). The name will be a contiguous sequence of non-white-space characters.  You can assume that it will be at most MAX_NAME characters in length.  You don't need to check this.

 

 

 

2.      O – Output command.  Output the sales per hour for that salesman.  If the salesman doesn't exist, print an appropriate message.  Calling this command zeroes the salesman's sales and time.

 

 

 

3.      U – Update command. Update the salesman with the given sales and time. If the salesman doesn't exist, print an appropriate message.

 

 

 

4.      Q – Quit command.

 

 

 

You don't need to check for bad commands.  You can assume that the input formats are okay.

 

You don't need to do any special formatting of the floating-point numbers that are output.

 

 

 

See the sample output for the exact wordings of all the messages.

 

 

 

Sample Input and Output

 

 

 

 

 

Sample Input:

 

 

 

A Alice

 

A Bob

 

O Alice

 

U Alice    60 3

 

U Bob      80 2

 

U Bob      46 7

 

O Bob

 

O Charlie

 

A Charlie

 

A Alice

 

A Dave

 

A Edger

 

A Fred

 

U Alice    70 2

 

U Charlie 150 5

 

O Alice

 

O Alice

 

U Bob      95 5

 

U Charlie  16 2

 

O Bob

 

Q

 

Corresponding Sample Output:

 

 

 

Note that for the first "O" for Bob, he had a good day and a bad day of $80 for 2 hours and $46 for 7 hours.  Thus at the time it is output, his sales are 80 + 46 = 126 and his time is 2 + 7 = 9.  So his sales per hour are: 126 / 9 = 14.  The output for the sample run is:

 

 

 

A Alice

 

Alice is salesman 0

 

A Bob

 

Bob is salesman 1

 

O Alice

 

Alice: $0 per hour

 

U Alice    60 3

 

Salesperson Alice sold $60 of toys in 3 Hours

 

U Bob      80 2

 

Salesperson Bob sold $80 of toys in 2 Hours

 

U Bob      46 7

 

Salesperson Bob sold $46 of toys in 7 Hours

 

O Bob

 

Bob: $14 per hour

 

O Charlie

 

Cannot output. Charlie is not in the list.

 

A Charlie

 

Charlie is salesman 2

 

A Alice

 

Alice is already in the list.

 

A Dave

 

Dave is salesman 3

 

A Edger

 

Edger is salesman 4

 

A Fred

 

Fred not added. List is full.

 

U Alice    70 2

 

Salesperson Alice sold $70 of toys in 2 Hours

 

U Charlie 150 5

 

Salesperson Charlie sold $150 of toys in 5 Hours

 

O Alice

 

Alice: $26 per hour

 

O Alice

 

Alice: $0 per hour

 

U Bob      95 5

 

Salesperson Bob sold $95 of toys in 5 Hours

 

U Charlie  16 2

 

Salesperson Charlie sold $16 of toys in 2 Hours

 

O Bob

 

Bob: $19 per hour

 

Q

Normal Termination of Sales Program

TutorRating
pallavi

out of 1971 reviews
amosmm

out of 766 reviews
PhyzKyd

out of 1164 reviews
rajdeep77

out of 721 reviews
sctys

out of 1600 reviews
sharadgreen

out of 770 reviews
topnotcher

out of 766 reviews
XXXIAO

out of 680 reviews