The purpose of this C programming project is to familiarize

The purpose of this C++ programming project is to familiarize the student with class definitions and usage, as well as with saving data to a file. A driver program to test the student\'s class interface and implementation is provided. The student must copy-and-paste the source code listed below and then complete the class definition and the functions to implement the class.

UML - Class Diagram:
Symbol definitions:
- private
+ public
# protected

SalesPerson
- int salesPersonId
- string firstName
- string lastName
+ 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( )

Solution

#include <fstream> // file processing
#include <iostream> // cin and cout
#include <iomanip> // setw
#include <string> // string class
using namespace std;


//Copy-and-paste your class definition from P11.cpp.

//Class definition - the interface for the class

class SalesPerson
{
private:
int salesPersonId;
string firstName;
string lastName;


public:
SalesPerson()
{
salesPersonId=1001;
firstName=\"Joe\";
lastName=\"Smit\";
}
SalesPerson(int id, string fn, string ln)
{
salesPersonId=id;
firstName=fn;
lastName=ln;
}
~SalesPerson ( )
{
}
void setSalesPersonId(int id)
{
salesPersonId=id;
}
void setFirstName(string fn)
{
firstName=fn;
}
void setLastName(string ln)
{
lastName=ln;
}

int getSalesPersonId( )
{
return salesPersonId;
}
string getFirstName( )
{
return firstName;
}
string getLastName( )
{
return lastName;
}

void inputSalesPersonId( )
{
cout<<\"enter ID\ \";
cin>>salesPersonId;
}
void inputFirstName( )
{
cout<<\"enter First name\ \";
cin>>firstName;
}
void inputLastName( )
{
cout<<\"enter Last name\ \";
cin>>lastName;
}


};


//Application Starts here (prototypes, main(), and definitions for application)

//saves info to a file or displays to screen (cout) through ostream& parameter
void outputSalesInfo(ostream& target, SalesPerson& salesPersonObj);

//main driver to test SalesPerson class
int main()
{
//Open the file for output; if there are any errors, we need to
//display an error message.

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

cout << \"\ P12 Your Name Here \ \ \";


//1001 Joe Smith - use default constructor and input functions
SalesPerson salesPersonObj;

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


//1002 Larry Jones - use set functions to change values.
salesPersonObj.setSalesPersonId(1002);
salesPersonObj.setFirstName(\"Larry\");
salesPersonObj.setLastName(\"Jones\");

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

//1003 Paul Sailor - use overloaded constructor
SalesPerson salesPersonObj2(1003, \"Paul\", \"Sailor\");

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

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


//save the order information to a file or display to screen.
//target can be either cout or outFile because ofstream inherits ostream.
//ofstream objects are also ostream objects.
//also, must be ostream because cout is already declared as an ostream.

void outputSalesInfo(ostream& target, SalesPerson& salesPersonObj)
{
//declare local variables
int salesPersonId;
string lastName, firstName;

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

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

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

return;
}

==============================================================================

Output:

akshay@akshay-Inspiron-3537:~/Chegg$ g++ sales.cpp
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out

P12 Your Name Here

Sales Person\'s Information Saved!
1001 Joe Smit


Sales Person\'s Information Saved!
1002 Larry Jones   


Sales Person\'s Information Saved!
1003 Paul Sailor   

The purpose of this C++ programming project is to familiarize the student with class definitions and usage, as well as with saving data to a file. A driver prog
The purpose of this C++ programming project is to familiarize the student with class definitions and usage, as well as with saving data to a file. A driver prog
The purpose of this C++ programming project is to familiarize the student with class definitions and usage, as well as with saving data to a file. A driver prog
The purpose of this C++ programming project is to familiarize the student with class definitions and usage, as well as with saving data to a file. A driver prog

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site