Question

C++ implement and use the methods for a class called Seller that represents information about a...

C++

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.

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

#include <iostream>

#include<string.h>

using namespace std;

class Seller{

    public:

        Seller();

        Seller(const char[] ,const char[] ,const char[] ,double total );

        void print();

        void setFirstName(const char[]);

        void setLastName(const char[]);

        void setID(const char[]);

        void setSalesTotal(double total);

        double getSalesTotal();

    private:

        char firstName[20];

        char lastName[30];

        char ID[7];

        double salesTotal;

};

Seller::Seller(){

    strcpy(this->firstName,"None");

    strcpy(this->lastName,"None");

    strcpy(this->ID ,"ZZZ999");

    this->salesTotal = 0;

}

Seller::Seller(const char first[],const char last[],const char id[],double total){

    strcpy(this->firstName,first);

    strcpy(this->lastName,last);

    strcpy(this->ID ,id);

    this->salesTotal = total;

}

void Seller::print(){

    cout<<this->firstName<<","<<this->lastName<<"\t\t"<<this->ID<<"\t\t"<<this->salesTotal<<endl;

}

void Seller::setFirstName(const char first[]){

    strcpy(this->firstName,first);

}

void Seller::setLastName(const char last[]){

    strcpy(this->lastName,last);

}

void Seller::setID(const char id[]){

    strcpy(this->ID,id);

}

void Seller::setSalesTotal(double total){

    this->salesTotal = total;

}

double Seller::getSalesTotal(){

    return this->salesTotal;

}

//main function

int main() {

    Seller firstSeller("Jeff","Kendall","CS1240",1234.56);

    cout<<"First Seller: "<<endl;

    firstSeller.print();

    cout<<endl<<"Second Seller is "<<endl;

    Seller secondSeller;

    secondSeller.print();

    cout<<endl;

    secondSeller.setFirstName("Mitchell");

    secondSeller.setLastName("Trubisky");

    secondSeller.setID("QB10");

    secondSeller.setSalesTotal(246.8);

    cout<<endl<<"Second Seller after Modifying is "<<endl;

    secondSeller.print();

    cout<<endl<<"Third Seller is "<<endl;

    Seller thirdSeller("","Robinson","TOOBIG999",-876.34);

    thirdSeller.print();

    cout<<endl;

    thirdSeller.setFirstName("Allen");

    thirdSeller.setID("WIDE12");

    thirdSeller.setSalesTotal(9900000.99);

    cout<<endl<<"Third Seller after Modifying is "<<endl;

    thirdSeller.print();

    Seller fourthSeller("Tarik","Cohen","RUN29",13579.11);

    cout<<endl<<"Fourth Seller sales total: "<<fourthSeller.getSalesTotal()<<endl;

    fourthSeller.print();

    cout<<endl<<"Fifth Seller is "<<endl;

    Seller fifthSeller("Kyle","Long","TACK75",24680.24);

    fifthSeller.print();

    fifthSeller.setFirstName("");

    fifthSeller.setLastName("");

    fifthSeller.setID("");

    fifthSeller.setSalesTotal(-52.96);

    cout<<endl<<"Fifth Seller after Modifying is "<<endl;

    fifthSeller.print();

}

Output:

Add a comment
Know the answer?
Add Answer to:
C++ implement and use the methods for a class called Seller that represents information about a...
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
  • Can you please help me print columns for my C++ project? I'd like the print-out to...

    Can you please help me print columns for my C++ project? I'd like the print-out to have 3 columns to line up with of 1) First Name & Last Name 2) ID # and 3) Sales total I've attached the code below. Thank you in advance for your help. Seller::Seller() { setFirstName("None"); setLastName("None"); setID("ZZZ000"); setSalesTotal(0); }Seller::Seller(char first[],char last[],char id[],double sales) { setFirstName(first); setLastName(last); setID(id); setSalesTotal(sales); } /* Method: void setSalesTotal( double newSalesTotal ) Use: Changes a Seller's sales total Arguments:...

  • C++ Please Provide .cpp Overview For this assignment, implement and use the methods for a class...

    C++ Please Provide .cpp Overview For this assignment, implement and use the methods for a class called Player that represents a player in the National Hockey League. Player class Use the following class definition: class Player { public: Player(); Player( const char [], int, int, int ); void printPlayer(); void setName( const char [] ); void setNumber( int ); void changeGoals( int ); void changeAssists( int ); int getNumber(); int getGoals(); int getAssists(); private: char name[50]; int number; int goals;...

  • Code should be in C# Create a class called SavingsAccount.  Use a static variable called annualInterestRate to...

    Code should be in C# Create a class called SavingsAccount.  Use a static variable called annualInterestRate to store the annual interest rate for all account holders.  Each object of the class contains a private instance variable savingsBalance, indicating the amount the saver currently has on deposit. Provide method CalculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12 – this interest should be added to savingsBalance.  Provide static method setAnnualInterestRate to set the annualInterestRate to a new value....

  • implement a class called PiggyBank that will be used to represent a collection of coins. Functionality...

    implement a class called PiggyBank that will be used to represent a collection of coins. Functionality will be added to the class so that coins can be added to the bank and output operations can be performed. A driver program is provided to test the methods. class PiggyBank The PiggyBank class definition and symbolic constants should be placed at the top of the driver program source code file while the method implementation should be done after the closing curly brace...

  • Please implement the following problem in basic C++ code and include detailed comments so that I...

    Please implement the following problem in basic C++ code and include detailed comments so that I am able to understand the processes for the solution. Thanks in advance. // personType.h #include <string> using namespace std; class personType { public: virtual void print() const; void setName(string first, string last); string getFirstName() const; string getLastName() const; personType(string first = "", string last = ""); protected: string firstName; string lastName; }; // personTypeImp.cpp #include <iostream> #include <string> #include "personType.h" using namespace std; void...

  • Part (A) Note: This class must be created in a separate cpp file Create a class...

    Part (A) Note: This class must be created in a separate cpp file Create a class Employee with the following attributes and operations: Attributes (Data members): i. An array to store the employee name. The length of this array is 256 bytes. ii. An array to store the company name. The length of this array is 256 bytes. iii. An array to store the department name. The length of this array is 256 bytes. iv. An unsigned integer to store...

  • Application should be in C# programming language Create a class called SavingsAccount.  ...

    Application should be in C# programming language Create a class called SavingsAccount.  Use a static variable called annualInterestRate to store the annual interest rate for all account holders.  Each object of the class contains a private instance variable savingsBalance, indicating the amount the saver currently has on deposit. Provide method CalculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12 – this interest should be added to savingsBalance.  Provide static method setAnnualInterestRate to set the...

  • In C++, Step 1: Implement the Student Class and write a simple main() driver program to...

    In C++, Step 1: Implement the Student Class and write a simple main() driver program to instantiate several objects of this class, populate each object, and display the information for each object. The defintion of the student class should be written in an individual header (i.e. student.h) file and the implementation of the methods of the student class should be written in a corresponding source (i.e. student.cpp) file. Student class - The name of the class should be Student. -...

  • In C++ format: Define a function called DisplayMax. It will have 3 parameters of two different...

    In C++ format: Define a function called DisplayMax. It will have 3 parameters of two different types of known parameter lists which are either void DisplayMax(string idI, double value[], int size) or void DisplayMax(int idn, short value几int size). The first and second parameters are parallel arrays. (Parallel Arrays are two arrays whose data is related by a common index. For example: with the string array and double array, index 5 of the string array would have some name, and index...

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