Question

In: Computer Science

For this assignment, implement and use the methods for a class called Seller that represents information about a salesperson.


For this assignment, implement and use the methods for a class called Seller that represents information about a salesperson.

The Seller class

Use the following class definition:

class Seller
{
public:
  Seller();
  Seller( const char [], const char[], const char [], double );
    
  void print();

  void setFirstName( const char [] );
  void setLastName( const char [] );
  void setID( const char [] );
  void setSalesTotal( double );

  double getSalesTotal();

private:
  char firstName[20];
  char lastName[30];
  char ID[7];
  double salesTotal;
};

Data Members

The data members for the class are:

  • firstName holds the Seller's first name

  • lastName holds the Seller's last name

  • ID holds the Seller's id number

  • salesTotal holds the Seller's sales total

Constructors

This class has two constructors. The default constructor (the one that takes no arguments) should initialize the first and last names to "None", the seller ID to "ZZZ999", and the sales total to 0.

The other constructor for the class should initialize the data members using the passed in arguments. It takes 4 arguments: a character array with a Seller's first name, a character array with a Seller's last name, a character array with a Seller's id number, and a double that holds the Seller's sales total. The data members should be initialized by calling the various set methods.

Methods

void print()

This method displays the Seller information. It takes no arguments and returns nothing.

The information should be displayed as follows:

Giant, Andre               BIG357               678.53

void setFirstName( const char [] )

This method changes a Seller's first name. It takes one argument: an array of characters that represents the Seller's first name. It returns nothing.

If the length of the passed in argument is greater than 0, it should be used to initialize the firstName data member. Otherwise, the firstName data member should be set to "None".

void setLastName( const char [] )

This method changes a Seller's last name. It takes one argument: an array of characters that represents the Seller's last name. It returns nothing.

If the length of the passed in argument is greater than 0, it should be used to initialize the lastName data member. Otherwise, the lastName data member should be set to "None".

void setID( const char [] )

This method changes a Seller's id number. It takes one argument: an array of characters that represents the Seller's id number. It returns nothing.

If the length of the passed in argument is greater than 0 and less than 7, it should be used to initialize the ID data member. Otherwise, the ID data member should be set to "ZZZ999".

void setSalesTotal( double )

This method changes a Seller's sales total. It takes one argument: a double that represents the Seller's sales total. It returns nothing.

If the passed in argument is greater than or equal to 0, it should be used to initialize the salesTotal data member. Otherwise, the salesTotal data member should be set to 0.

double getSalesTotal()

This method returns a Seller's sales total data member. It takes no arguments.

main()

In main(), create 5 Seller objects. They should contain the values:

  • The first Seller should have your name, an id of "CSI240", and a sales total of 1234.56. Note: if you're pair programming, set the first name to the first name of both you and your partner: "Jane/John" and the last name to the last name of both you and your partner: "Doe/Doe".

  • The second Seller should be created using the default constructor (the one that doesn't take any arguments)

  • The third Seller should have the first name of an empty string (""), a last name of "Robinson", an id of "TOOBIG999", and a sales total of -876.34.

  • The fourth Seller should have the name "Tarik Cohen", an id of "RUN29", and a sales total of 13579.11

  • The fifth Seller should have the name "Kyle Long", an id of "TACK75", and a sales total of 24680.24

The rest of main() will include using the various methods on each of the 5 Seller objects. Display a label similar to "The first Seller" before anything is outputted for each of the objects.

For the first Seller, display the Seller information.

For the second Seller, display the Seller information, set the Seller name to "Mitchell Trubisky", set the id number to "QB10", set the sales total to 246.80, and then display the Seller information once again.

For the third Seller, display the Seller's information, set the Seller's first name to "Allen", set the id number to "WIDE12", set the sales total to 9900000.99, and then display the Seller information once again.

For the fourth Seller, display only the Seller's sales total.

For the fifth Seller, display the Seller's information, set the first name to an empty string (""), set the last name to an empty string, set the id number to an empty string, set the sales total to -52.96, and then display the Seller information once again.

Programming Notes

  1. Each method must have a documentation box like a function.

  2. Hand in a copy of the source code using Blackboard.

Output

Note: The information for the first Seller object will have your name.

The First Seller
Da Bear, Staley                 CSI240        1234.56

The Second Seller
None, None                      ZZZ999           0.00
Trubisky, Mitchell                QB10         246.80

The Third Seller
Robinson, None                  ZZZ999           0.00
Robinson, Allen                 WIDE12     9900000.99

The Fourth Seller
The sales total is $13579.11

The Fifth Seller
Long, Kyle                      TACK75       24680.24
None, None                      ZZZ999           0.00

Solutions

Expert Solution

Program

#include
#include
#include

using namespace std;
class Seller
{
private:
char firstName[20];
char lastName[30];
char ID[7];
double salesTotal;
public:
Seller() //default constructor
{
strcpy(this->firstName,"None");
strcpy(this->lastName,"None");
strcpy(this->ID,"ZZZ999");
this->salesTotal=0;
  
}
Seller( const char first[], const char last[], const char Id[], double salesTotal ) //parameterised constructor
{
if(strlen(first)>0)
strcpy(this->firstName,first);
else
strcpy(this->firstName,"None");
if(strlen(last)>0)
strcpy(this->lastName,last);
else
strcpy(this->lastName,"None");
  
if(strlen(Id)>0 && strlen(Id)<7 )
strcpy(this->ID,Id);
else
strcpy(this->ID,"ZZZ999");
if(salesTotal>=0)
this->salesTotal=salesTotal;
else
this->salesTotal=0;
}
  
void print() //function to print details
{
cout< }

void setFirstName( const char first[] ) //function to setFirstName
{
if(strlen(first)>0)
strcpy(this->firstName,first);
else
strcpy(this->firstName,"None");
}
void setLastName(const char last[] ) //function to setLastName
{
if(strlen(last)>0)
strcpy(this->lastName,last);
else
strcpy(this->lastName,"None");
}
void setID( const char Id[] ) //function to setID
{   
if(strlen(Id)>0 && strlen(Id)<7 )
strcpy(this->ID,Id);
else
strcpy(this->ID,"ZZZ999");

}
void setSalesTotal( double salesTotal ) //funtion to setSalesTotal
{
if(salesTotal>=0)
this->salesTotal=salesTotal;
else
this->salesTotal=0;

}

double getSalesTotal() //funtion to getSalesTotal
{
return salesTotal;
}


};

int main()
{
Seller firstSeller;
firstSeller.setFirstName("Jhon");
firstSeller.setLastName("Doe");
firstSeller.setID("CSI240");
firstSeller.setSalesTotal(1234.56);
  
Seller secondSeller; //secondSeller is created using default constructor
  
Seller thirdSeller("","Robinson","TOOBIG999",-876.34); //thirdSeller is created using parameterised constructor
  
Seller fourthSeller("Tarik","Cohen","RUN29",13579.11); //fourthSeller is created using parameterised constructor
  
Seller fifthSeller("Kyle","Long","TACK75",24680.24); // fifthSeller is also created using parameterised constructor

cout<<"First seller\n";
firstSeller.print(); //printing firstSeller details
cout<<"\n\nSecond seller\n";
  
secondSeller.print(); //printing secondSeller details
secondSeller.setFirstName("Mitchell");
secondSeller.setLastName("Trubisky");
secondSeller.setID("QB10");
secondSeller.setSalesTotal(246.80);
cout<<"\n";
secondSeller.print(); //printing secondSeller details
  
cout<<"\n\nThird seller\n";
thirdSeller.print(); //printing thirdSeller details
thirdSeller.setFirstName("Allen");
thirdSeller.setID("WIDE12");
thirdSeller.setSalesTotal(9900000.99);
cout<<"\n";
thirdSeller.print(); //printing thirdSeller details
  
cout<<"\n\nFourth seller\n";
cout<<"Sales total : "<   
cout<<"\n\nFifth seller\n";
fifthSeller.print(); //printing fifthSeller details
fifthSeller.setFirstName("");
fifthSeller.setLastName("");
fifthSeller.setID("");
fifthSeller.setSalesTotal(-52.96);
cout<<"\n";
fifthSeller.print(); //printing fifthSeller details
  
return 0;
}

Screenshot

Output


Related Solutions

Overview For this assignment, implement and use the methods for a class called Seller that represents...
Overview For this assignment, implement and use the methods for a class called Seller that represents information about a salesperson. The Seller class Use the following class definition: class Seller { public: Seller(); Seller( const char [], const char[], const char [], double ); void print(); void setFirstName( const char [] ); void setLastName( const char [] ); void setID( const char [] ); void setSalesTotal( double ); double getSalesTotal(); private: char firstName[20]; char lastName[30]; char ID[7]; double salesTotal; };...
Overview For this assignment, implement and use the methods for a class called Seller that represents...
Overview For this assignment, implement and use the methods for a class called Seller that represents information about a salesperson. The Seller class Use the following class definition: class Seller { public: Seller(); Seller( const char [], const char[], const char [], double ); void print(); void setFirstName( const char [] ); void setLastName( const char [] ); void setID( const char [] ); void setSalesTotal( double ); double getSalesTotal(); private: char firstName[20]; char lastName[30]; char ID[7]; double salesTotal; };...
Overview For this assignment, design and implement the methods for a class that can be used...
Overview For this assignment, design and implement the methods for a class that can be used to represent a quadratic equation. int main() has already been written for this assignment. It is available for download from Blackboard or by using the following link: http://faculty.cs.niu.edu/~byrnes/csci240/pgms/240pgm8.cpp All that needs to be done for this assignment is to add the class definition and method implementation to the above CPP file. The Quadratic class Data Members The class contains three data members: an integer...
JAVA - Design and implement a class called Flight that represents an airline flight. It should...
JAVA - Design and implement a class called Flight that represents an airline flight. It should contain instance data that represent the airline name, the flight number, and the flight’s origin and destination cities. Define the Flight constructor to accept and initialize all instance data. Include getter and setter methods for all instance data. Include a toString method that returns a one-line description of the flight. Create a driver class called FlightTest, whose main method instantiates and updates several Flight...
For this assignment you will implement a dynamic array. You are to build a class called...
For this assignment you will implement a dynamic array. You are to build a class called MyDynamicArray. Your dynamic array class should manage the storage of an array that can grow and shrink. The public methods of your class should be the following: MyDynamicArray(); Default Constructor. The array should be of size 2. MyDynamicArray(int s); For this constructor the array should be of size s. ~MyDynamicArray(); Destructor for the class. int& operator[](int i); Traditional [] operator. Should print a message...
Use Java programming to implement the following: Implement the following methods in the UnorderedList class for...
Use Java programming to implement the following: Implement the following methods in the UnorderedList class for managing a singly linked list that cannot contain duplicates. Default constructor Create an empty list i.e., head is null. boolean insert(int data) Insert the given data into the end of the list. If the insertion is successful, the function returns true; otherwise, returns false. boolean delete(int data) Delete the node that contains the given data from the list. If the deletion is successful, the...
Please Use C++ to finish as the requirements. Implement a class called SinglyLinkedList. In the main...
Please Use C++ to finish as the requirements. Implement a class called SinglyLinkedList. In the main function, instantiate the SinglyLinkedList class. Your program should provide a user loop and a menu so that the user can access all the operators provided by the SinglyLinkedList class. DestroyList InitializeList GetFirst InsertFirst, InsertLast, Insert DeleteFirst, DeleteLast, Delete IsEmpty Length Print, ReversePrint
Please use C++ to complete this question follow the requirement. Question: Implement a class called DoublyLinkedList....
Please use C++ to complete this question follow the requirement. Question: Implement a class called DoublyLinkedList. In the main function, instantiate the DoublyLinkedList class and make sure that there is a user loop and a menu so that the user can access all the list operators. You should implement the following operators, and any others that you may deem best. DestroyList InitializeList GetFirst InsertFirst, InsertLast, Insert DeleteFirst, DeleteLast, Delete IsEmpty Length Print, ReversePrint
Class AssignmentResult An object that represents the result of an assignment. __init__(self, id:int, assignment: Assignment, grade:...
Class AssignmentResult An object that represents the result of an assignment. __init__(self, id:int, assignment: Assignment, grade: float): """ This will contain the ID of the student, the assignment that the student worked on and the grade the student received on the assignment. :param id: The ID of the student that created this Assignment result :param assignment: The Assignment that the student worked on. :param grade: A number between 0-1 representing the numerical grade the student received """ id(self) -> int:...
Write a Java class called CityDistances in a class file called CityDistances.java.    1. Your methods...
Write a Java class called CityDistances in a class file called CityDistances.java.    1. Your methods will make use of two text files. a. The first text file contains the names of cities. However, the first line of the file is a number specifying how many city names are contained within the file. For example, 5 Dallas Houston Austin Nacogdoches El Paso b. The second text file contains the distances between the cities in the file described above. This file...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT