The purpose of this C programming project is to provide more

The purpose of this C++ programming project is to provide more practice in defining classes and to familiarize students with inheritance. In this project we create a new class that inherits the SalesPerson class. The base class will be SalesPerson, and it will be used to get and validate the id, firstname, lastname. The derived class, SalesInfo, will inherit SalesPerson, and add the functionally of getting and validating the bonus rate and quantity.

UML - Inheritance Diagram:
Use the suggested variable and function names so the code provided will work without any changes.

Symbol definitions:
- private
+ public
# protected

Create Project P13.

Add the text file P13.txt to the project. Do not enter anything into this file.

Add the text file output.txt to the project.

Add the source file P13.cpp to the project.

Copy-and-paste the following lines of code into P13.cpp.

Copy-and-paste the class definition for SalesPerson from the top of your P12.
To allow for inheritance, change private: to protected:. The outline is listed below.

After the SalesPerson class definition add the SalesInfo class definition with the required inheritance code. This code needs to be developed by the student. Use the UML provided above and the outline listed below.

After the SalesInfo class definition, Copy-and-paste the following application code to use as the driver to test the inheritance.

After the application code, Copy-and-paste the function definitions for SalesPerson from the bottom of your P12. The functions should include the following.

Scroll down to the end of the file and copy-and-paste the following function definitions for SalesInfo. All of the function headers are provided below, but some of the function bodies need to be defined by the student.

Compile and Build the project. Be sure to correct all errors reported by the compiler.

Execute the program to generate output. If correct, copy-and-paste into output.txt.

Double click on P13.txt to see the data saved to the file.
A message may be displayed informing you that the file has been modified. Click on yes to have the updated file reloaded into memory.

Study the two class definitions and the inheritance. Be sure you understand how main is able to use SalesInfo to access members defined in two separate classes (inheritance).

Submit P13.cpp, P13.txt, and output.txt.

SalesPerson <-- Inherits -- SalesInfo
# int salesPersonId
# string firstName
# string lastName
- - double rate
- int qty
+ SalesPerson ( ) //default constructor doesn\'t have parameters
+ SalesPerson(int id, string fn, string ln) //overloaded constructor;
//parameter names in overloaded constructors should be different
//from the class variable names, because the parameter values
//are going to be assigned to the class variables.

+ ~SalesPerson ( ) //destructor

//Set accessors do NOT return a value (void) because they are used
//to assign a value to a private variable. The value to assign is
//passed through the parameter.
+ void setSalesPersonId(int id)
+ void setFirstName(string fn)
+ void setLastName(string ln)

//Get accessors are used to return the value stored in a private
//variable, so a parameter is not passed.
+ int getSalesPersonId( )
+ string getFirstName( )
+ string getLastName( )

//Input accessors prompt for, get, and store a value in a private
//variable. A value is not returned and a parameter is not passed.
+ void inputSalesPersonId( )
+ void inputFirstName( )
+ void inputLastName( )
- + SalesInfo ( ) //default constructor doesn\'t have parameters
+ SalesInfo (int id, string fn, string ln, double rt, int qt) //overloaded
//Since SalesInfo inherits SalesPerson, the overloaded constructor
//must also list the variables from the base class. The values
//will be passed to the constructor in the base class.

+ ~SalesInfo ( ) //destructor

//Set accessors do NOT return a value (void) because they are used
//to assign a value to a private variable. The value to assign is
//passed through the parameter.
+ void setRate(double rt)
+ void setQty(int qt)

//Get accessors are used to return the value stored in a private
//variable, so a parameter is not passed.
+ double getRate( )
+ int getQty( )

//Input accessors prompt for, get, and store a value in a private
//variable. A value is not returned and a parameter is not passed.
+ void inputRate( )
+ void inputQty( )

Solution

//P13 Inheritance - Your Name
/*
This program is a driver to test SalesInfo class, which inherits SalesPerson.
It is used to create 2 objects, which test the constructors and accessors.
The objects created are saved to P13.txt
*/
#include <fstream>    // file processing
#include <iostream>   // cout and cin
#include <iomanip>    // setw
#include <string>     // string class

using namespace std;

class SalesPerson
{
protected:
   int salesPersonId;
   string firstName;
   string lastName;
public:
   SalesPerson ( );
   SalesPerson(int id, string fn, string ln);
   ~SalesPerson ( );
   void setSalesPersonId(int id) ;
   void setFirstName(string fn) ;
   void setLastName(string ln) ;
   int getSalesPersonId( ) ;
   string getFirstName( ) ;
   string getLastName( );
   void inputSalesPersonId( );
   void inputFirstName( ) ;
   void inputLastName( );
};

class SalesInfo : public SalesPerson
{
private:
   double rate;
   int    qty;

public:
   SalesInfo ( );
   SalesInfo (int id, string fn, string ln, double rt, int qt) ;
   ~SalesInfo ( );
   void setRate(double rt) ;
   void setQty(int qt) ;
   double getRate( ) ;
   int getQty( ) ;
   void inputRate( ) ;
   void inputQty( );

};

//This function saves sales info to a file or displays to screen (cout)
void outputSalesInfo(ostream& target, SalesInfo& salesInfoObj);


void main()
{
   //Open the file for output

   ofstream outFile;
   outFile.open(\"P13.txt\");
   if (outFile.fail())
   {
       cout << \"Error opening output file for sales information.\ \"
           << \"Exiting program \ \ \";
       return;
   }

   cout << \"\ P13     Your Name \ \ \";


   //1001 Joe Smith 5.00, 25 - use default constructors and input functions
   SalesInfo salesInfoObj;

   //Save the validated sales info data as a record to the file.
   outputSalesInfo(outFile, salesInfoObj);
   //display the record on the screen
   outputSalesInfo(cout, salesInfoObj);


   //1002 Larry Jones - use set methods to change values.
   salesInfoObj.setSalesPersonId(1002);
   salesInfoObj.setFirstName(\"Larry\");
   salesInfoObj.setLastName(\"Jones\");
   salesInfoObj.setRate(10.00);
   salesInfoObj.setQty(50);

   //Save the sales info data as a record to the file.
   outputSalesInfo(outFile, salesInfoObj);
   //display the record on the screen
   outputSalesInfo(cout, salesInfoObj);


   //1003 Paul Sailor - use overloaded constructors
   SalesInfo salesInfoObj2(1003, \"Paul\", \"Sailor\", 15.00, 150);

   //Save the sales info data as a record to the file.
   outputSalesInfo(outFile, salesInfoObj2);
   //display the record on the screen
   outputSalesInfo(cout, salesInfoObj2);


   // Close the output file and exit program
   outFile.close();
   return;
}//end of main


//save the order information to a file or display on screen
void outputSalesInfo(ostream& target, SalesInfo& salesInfoObj)
{
   //declare local variables
   int    salesPersonId;
   string lastName, firstName;
   double rate;
   int    qty;

   //set the precision for rate
   target.setf(ios::fixed);
   target.setf(ios::showpoint);
   target.precision(2);

   //Have the class return the private values to the local variables.
   //Then store them in the file.
   salesPersonId = salesInfoObj.getSalesPersonId();
   firstName     = salesInfoObj.getFirstName();
   lastName      = salesInfoObj.getLastName();
   rate          = salesInfoObj.getRate();
   qty           = salesInfoObj.getQty();

   if(target == cout)
       target << \"\ \ SalesPerson\'s Information Saved! \ \";

   target.setf(ios::left);
   target << setw(6) << salesPersonId
       << setw(18) << firstName
       << setw(18) << lastName;
   target.unsetf(ios::left);

   target << setw(6) << rate;
   target << setw(4) << qty;
   target << endl;

   return;
}

//end of application code

SalesPerson::SalesPerson(){
   inputSalesPersonId();
   inputFirstName();
   inputLastName();
}

SalesPerson::SalesPerson(int id, string fn, string ln){
   salesPersonId = id;
   firstName = fn;
   lastName = ln;
}

SalesPerson::~SalesPerson(){
   cout << \"SalesPerson Object going out of scope. Id = \" << salesPersonId << endl;
}


void SalesPerson::setSalesPersonId(int id){
   salesPersonId = id;
}

void SalesPerson::setFirstName(string fn){
   firstName = fn;
}

void SalesPerson::setLastName(string ln){
   lastName = ln;
}


int    SalesPerson::getSalesPersonId(){
   return salesPersonId;
}

string SalesPerson::getFirstName(){
   return firstName;
}

string SalesPerson::getLastName(){
   return lastName;
}


void SalesPerson::inputSalesPersonId(){
   cout << \"Enter sales person id: \";
   cin >> salesPersonId;
}

void SalesPerson::inputFirstName(){
   cout << \"Enter First name: \";
   cin >> firstName;
}

void SalesPerson::inputLastName(){
   cout << \"Enter Last name: \";
   cin >> lastName;
}

//default constructor- the input functions should be called from here
SalesInfo::SalesInfo()
    : SalesPerson()        //call constructor in base class
{
    inputRate();
    inputQty();
}

//overloaded constructor - arguments assigned to members
//use base initialize list to call constructor in base class
SalesInfo::SalesInfo(int id, string fn, string ln,
                               double rt, int qt)
    : SalesPerson(id, fn, ln)
{
    rate = rt;
    qty = qt;
}

//destructor
SalesInfo::~SalesInfo()
{
    cout << \"SalesInfo   Object going out of scope. Id = \"
         << salesPersonId << endl;
}

//Student needs to complete the next 4 functions.
//Accessors to set values in private variables
void SalesInfo::setRate(double rt)
{
   rate = rt;
}


void SalesInfo::setQty(int qt)
{
   qty = qt;
}


//Accessors to return values in private variables
double SalesInfo::getRate()
{
   return rate;
}

int SalesInfo::getQty()
{
   return qty;
}


void SalesInfo::inputRate()
{//Normally set and input functions would include validation and would throw an exception if an error was found.
    do
    {
        cout << \"Enter a bonus rate between $5.00 and $10: \";
        cin >> rate;

        if (rate < 5.0 || rate > 10.00)
            cout << \"Error: The rate must be between $5.00 and $10.00. \"
                 << \"Try again...\ \ \";

    } while (rate < 5.0 || rate > 10.00);
    return;
}


void SalesInfo::inputQty()
{
    do
    {
        cout << \"Enter a quantity between 0 and 200:       \";

        cin >> qty;
          
        if (qty < 0 || qty > 200)
            cout << \"Error: The quantity must be between 0 and 200. \"
                 << \" Try again...\ \ \";

    }while (qty < 0 || qty > 200);
    return;
}

The purpose of this C++ programming project is to provide more practice in defining classes and to familiarize students with inheritance. In this project we cre
The purpose of this C++ programming project is to provide more practice in defining classes and to familiarize students with inheritance. In this project we cre
The purpose of this C++ programming project is to provide more practice in defining classes and to familiarize students with inheritance. In this project we cre
The purpose of this C++ programming project is to provide more practice in defining classes and to familiarize students with inheritance. In this project we cre
The purpose of this C++ programming project is to provide more practice in defining classes and to familiarize students with inheritance. In this project we cre
The purpose of this C++ programming project is to provide more practice in defining classes and to familiarize students with inheritance. In this project we cre
The purpose of this C++ programming project is to provide more practice in defining classes and to familiarize students with inheritance. In this project we cre

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site