Question

Program Description You are going to write a C++ program to manage toy salesmen. A salesman's...

Program Description

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

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.

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.

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

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1

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];
};

2

// Initializes the Salesman's name to name.
// Initializes the Salesman's sales and time to 0.0.
void InitSeller ( Seller & s, const char name[])
{
strcpy(s.name, name);
s.time = 0.0;
s.sales = 0.0;
}

// Adds the money and time to the salesman's accumulated sales and time.
void UpdateSales ( Seller & s, float sales, float time )
{
s.sales += sales;
s.time += time;
}

// Returns true if the salesman's name is the same as name; false otherwise.
bool SellerHasName ( const Seller & s, const char name[] )
{
if (!strcmp(s.name, name))
return true;
return false;
}

// 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.
float SalesValue ( Seller & s )
{
float ans = s.sales/s.time;
s.sales = 0;
s.time = 0;
return ans;
}

3

int find(Seller s[], int count, char name[])
{
int i;
  
for(i = 0;i < count;i++)
{
if (!strcmp(s[i].name, name))
return i;
}
return -1;
}

Add a comment
Know the answer?
Add Answer to:
Program Description You are going to write a C++ program to manage toy salesmen. A salesman's...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The task is to write Song.cpp to complete the implementation of the Song class, as defined...

    The task is to write Song.cpp to complete the implementation of the Song class, as defined in the provided header file, Song.h, and then to complete a program (called sales) that makes use of the class. As in Project 1, an input data file will be provided containing the song name and other information in the same format as in Program 1: Artist    Song_Title    Year    Sales    Medium As before, the program (sales) which are individual copies, will use this information to compute the gross...

  • J Inc. has a file with employee details. You are asked to write a C++ program...

    J Inc. has a file with employee details. You are asked to write a C++ program to read the file and display the results with appropriate formatting. Read from the file a person's name, SSN, and hourly wage, the number of hours worked in a week, and his or her status and store it in appropriate vector of obiects. For the output, you must display the person's name, SSN, wage, hours worked, straight time pay, overtime pay, employee status and...

  • C++ Objective: Write a program to read a pre-specified file containing salespersons' names and daily sales...

    C++ Objective: Write a program to read a pre-specified file containing salespersons' names and daily sales for some number of weeks. It will create an output file with a file name you have gotten from the user that will hold a summary of sales data. Specifications: 1. You should do a functional decomposition to identify the functions that you will use in the program. These should include reading and writing the files, tallying and showing statistics, etc. 2. The program...

  • A) One of the problems that have been discussed in the class is to write a simple C++ program to ...

    C++ programming question will upvote A) One of the problems that have been discussed in the class is to write a simple C++ program to determine the area and circumference of a circle of a given radius. In this lab you will be rewriting the program again but this time you will be writing some functions to take care of the user input and math. Specifically, your main function should look like the following int main //the radius of the...

  • Edit a C program based on the surface code(which is after the question's instruction.) that will...

    Edit a C program based on the surface code(which is after the question's instruction.) that will implement a customer waiting list that might be used by a restaurant. Use the base code to finish the project. When people want to be seated in the restaurant, they give their name and group size to the host/hostess and then wait until those in front of them have been seated. The program must use a linked list to implement the queue-like data structure....

  • //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which...

    //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming: 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string...

  • For this computer assignment, you are to write a C++ program to implement a class for...

    For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. The definition of the class for a binary tree (as a template) is given as follows: template < class T > class binTree { public: binTree ( ); // default constructor unsigned height ( ) const; // returns height of tree virtual void insert ( const T& ); //...

  • Salary Lab In this lab you are going to write a time card processor program. Your...

    Salary Lab In this lab you are going to write a time card processor program. Your program will read in a file called salary.txt. This file will include a department name at the top and then a list of names (string) with a set of hours following them. The file I test with could have a different number of employees and a different number of hours. There can be more than 1 department, and at the end of the file...

  • Write a program in C++ that simulates a soft drink machine. The program will need several...

    Write a program in C++ that simulates a soft drink machine. The program will need several classes: DrinkItem, DrinkMachine and Receipt. For each of the classes you must create the constructors and member functions required below. You can, optionally, add additional private member functions that can be used for doing implementation work within the class. DrinkItem class The DrinkItem class will contains the following private data members: name: Drink name (type of drink – read in from a file). Type...

  • CAN SOMEONE COMPLETE THIS CODE PLEASE THNK YOU!! Question - Write a program in c++ that...

    CAN SOMEONE COMPLETE THIS CODE PLEASE THNK YOU!! Question - Write a program in c++ that keeps an appointment book. Make a class Appointment that stores a description of the appointment, the appointment day, the starting time, and the ending time. Your program should keep the appointments in a sorted vector. Users can add appointments and print out all appointments for a given day. When a new appointment is added, use binary search to find where it should be inserted...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT