Programming Challenges Visit b.com to complete many of these Programming Challen
ID: 3808620 • Letter: P
Question
Programming Challenges Visit b.com to complete many of these Programming Challen online and get instant feedback 1. Employee and Produ Design a class Employee. Classes keep the following information in field named The class should name Employee number in the format where each X is a digit within the and the L is a letter within the range A-M. Hire date tat Write one or more constructors and the appropriate accessor and mutator methods the Next, write a class named for daw class should have fields to hold the following the Employee class. The Shift (an integer) information: Hourly pay rate (a double) The workday is divided into two shifts: day and night. The shift field will be an integer value representing the shift that the employee works. The day shift is shift 1 and the night shift is shift 2. Write one or more constructors and the appropriate accessor and mutator methods for the class. Demonstrate the classes by writing a program a Productionworker object. that uses 2. upervisor Class In a particular factory, a shift supervisor is a salaried employee who supervises a shift. In addi tion to a salary, the shift supervisor earns a yearly bonus when his or her shift meets produc- tion goals. Design a shiftsupervisor class that extends the Employee class you created in Programming Challenge 1. The shiftsupervisor class should have a field that holds the annual salary and a field that holds the annual production bonus that a shift supervisor has earned. Write one or more constructors and the appropriate accessor and mutator methods for the class. Demonstrate the class by writing a program that uses a obiecExplanation / Answer
main.cpp
//Library includes
#include <iostream>
#include <string>
using namespace std;
//User Libraries
#include "ShiftSupervisor.h"
#include "CustomerData.h"
#include "PersonData.h"
#include "PreferredCustomer.h"
//Global Constants
//Function Prototypes
void Menu();
int getN();
void def(int);
void problem1();
void problem2();
void problem3();
void problem4();
//Begin Execution Here!!!
int main(int argv,char *argc[]){
int inN;
do{
Menu();
inN=getN();
switch(inN){
case 1: problem1();break;
case 2: problem2();break;
case 3: problem3();break;
case 4: problem4();break;
default: def(inN);}
}while(inN>=1&&inN<=4);
return 0;
}
void Menu(){
cout<<"Menu for the Assignment 5"<<endl;
cout<<"Type 1 for problem 15.1"<<endl;
cout<<"Type 2 for problem 15.2"<<endl;
cout<<"Type 3 for problem 15.7"<<endl;
cout<<"Type 4 for problem 15.8"<<endl;
cout<<"Type anything else to exit"<<endl;
}
int getN(){
int inN;
cin>>inN;
cin.ignore();
return inN;
}
void def(int inN){
cout<<"You typed "<<inN<<" to exit the program"<<endl;
}
void problem1(){
cout<<"In problem # 1"<<endl<<endl;
//Declare Variables
string name;
string number;
string hireD;
int shift;
float rate;
//Get inputs
cout<<"Input the Employee's name ";
cout<<"Name: ";
getline(cin,name);
cout<<"Input the Employee's number ";
cout<<"Employee number: ";
getline(cin,number);
cout<<"Input the Employee's hire date ";
cout<<"Hire date: ";
getline(cin,hireD);
cout<<"Input the Employee's shift 1.Day 2.Night ";
cout<<"Shift: ";
cin>>shift;
cout<<"Input the Employee's Hourly Pay Rate ";
cout<<"Pay Rate: ";
cin>>rate;
ProductionWorker work(name,number,hireD,shift,rate);
work.print();
work.display();
cout<<endl;
}
void problem2(){
cout<<"In problem # 2"<<endl<<endl;
float annual;//annual salary
float bonus; //annual production bonus
string name; //Employee name
string number; //Employee number
string hireD; //Employee hire date
int shift; //Day shift or night shift
float rate; //Hourly pay rate
//Get inputs
cout<<"Input the Employee's name ";
cout<<"Name: ";
getline(cin,name);
cout<<"Input the Employee's number ";
cout<<"Employee number: ";
getline(cin,number);
cout<<"Input the Employee's hire date ";
cout<<"Hire date: ";
getline(cin,hireD);
cout<<"Input the Employee's shift 1.Day 2.Night ";
cout<<"Shift: ";
cin>>shift;
cout<<"Input the Employee's Hourly Pay Rate ";
cout<<"Pay Rate: ";
cin>>rate;
cout<<"Input the Supervisor's annual Salary ";
cout<<"Salary: $";
cin>>annual;
cout<<"Input the Supervisor's annual production bonus ";
cout<<"Bonus: $";
cin>>bonus;
ShiftSupervisor work(name,number,hireD,shift,rate,annual,bonus);
cout<<" ";
cout<<"******************************************** ";
work.print();
work.display();
work.printS();
cout<<endl<<endl;
}
void problem3(){
cout<<"In problem # 3"<<endl<<endl;
string last;
string first;
string address;
string city;
string state;
string zip;
string phone;
cout<<"Input the Customer's Last Name ";
cout<<"Last Name: ";
getline(cin,last);
cout<<"Input the Customer's First Name ";
cout<<"First Name: ";
getline(cin,first);
cout<<"Input the Customer's Address ";
cout<<"Address: ";
getline(cin,address);
cout<<"Input the Customer's City ";
cout<<"City: ";
getline(cin,city);
cout<<"Input the Customer's State ";
cout<<"State: ";
getline(cin,state);
cout<<"Input the Customer's Zip ";
cout<<"Zip: ";
getline(cin,zip);
bool valid;
do{
valid=true;
for(int i=0;i<zip.length();i++){
if(!isdigit(zip[i])){
valid=false;
cout<<"ERROR: You did not enter a correct Zip code. Check to make sure they are all digits ";
break;
}
}
if(!valid){
cout<<"Input the Customer's Zip ";
cout<<"Zip: ";
getline(cin,zip);
}
}while(!valid);
cout<<"Input the Customer's Phone number ";
cout<<"Phone: ";
getline(cin,phone);
do{
valid=true;
for(int i=0;i<phone.length();i++){
if(!isdigit(phone[i])){
valid=false;
cout<<"ERROR: You did not enter a correct Phone number. Check to make sure they are all digits ";
break;
}
}
if(!valid){
cout<<"Input the Customer's Phone number ";
cout<<"Phone: ";
getline(cin,phone);
}
}while(!valid);
int num;
bool mail;
char ans;
cout<<"Input the Customer's unique number ";
cout<<"Customer Number: ";
cin>>num;
do{
cout<<"Does the Customer want to be on the mailing list?[Y]/[N] ";
cin>>ans;
if(ans!='y' && ans!='Y' && ans!='n' && ans !='Y'){
cout<<"ERROR: Invalid Input ";
}
}while(ans!='y' && ans!='Y' && ans!='n' && ans !='Y');
switch(ans){
case 'Y':
case 'y':{
cout<<"Customer "<<num<<" is now on the mailing list ";
mail=true;
break;
}
default:{
mail=false;
break;
}
}
CustomerData data(last,first,address,city,state,zip,phone,num,mail);
cout<<" ******************************************** ";
data.getName();
cout<<"'s Information: ";
data.print();
data.display();
cout<<endl;
}
void problem4(){
cout<<"In problem # 4"<<endl<<endl;
//FOR THE PERSON DATA CLASS
string last;
string first;
string address;
string city;
string state;
string zip;
string phone;
//FOR THE CUSTOMER DATA CLASS
int num;
bool mail;
char ans;
//FOR THE PREFERRED CUSTOMER CLASS
float buy;
float perc;
//Get inputs
cout<<"Input the Customer's Last Name ";
cout<<"Last Name: ";
getline(cin,last);
cout<<"Input the Customer's First Name ";
cout<<"First Name: ";
getline(cin,first);
cout<<"Input the Customer's Address ";
cout<<"Address: ";
getline(cin,address);
cout<<"Input the Customer's City ";
cout<<"City: ";
getline(cin,city);
cout<<"Input the Customer's State ";
cout<<"State: ";
getline(cin,state);
cout<<"Input the Customer's Zip ";
cout<<"Zip: ";
getline(cin,zip);
bool valid;
do{
valid=true;
for(int i=0;i<zip.length();i++){
if(!isdigit(zip[i])){
valid=false;
cout<<"ERROR: You did not enter a correct Zip code. Check to make sure they are all digits ";
break;
}
}
if(!valid){
cout<<"Input the Customer's Zip ";
cout<<"Zip: ";
getline(cin,zip);
}
}while(!valid);
cout<<"Input the Customer's Phone number ";
cout<<"Phone: ";
getline(cin,phone);
do{
valid=true;
for(int i=0;i<phone.length();i++){
if(!isdigit(phone[i])){
valid=false;
cout<<"ERROR: You did not enter a correct Phone number. Check to make sure they are all digits ";
break;
}
}
if(!valid){
cout<<"Input the Customer's Phone number ";
cout<<"Phone: ";
getline(cin,phone);
}
}while(!valid);
//used for the customerdata class
cout<<"Input the Customer's unique number ";
cout<<"Customer Number: ";
cin>>num;
do{
cout<<"Does the Customer want to be on the mailing list?[Y]/[N] ";
cin>>ans;
if(ans!='y' && ans!='Y' && ans!='n' && ans !='Y'){
cout<<"ERROR: Invalid Input ";
}
}while(ans!='y' && ans!='Y' && ans!='n' && ans !='Y');
//Sets the bool to be on mail list to true or false
switch(ans){
case 'Y':
case 'y':{
cout<<"Customer "<<num<<" is now on the mailing list ";
mail=true;
break;
}
default:{
mail=false;
break;
}
}
//Used for the preferedCustomer class
do{
cout<<"Input how much the customer spent ";
cout<<"Spent: $";
cin>>buy;
if(buy<0){
cout<<"ERROR: Invalid Input the spent amount can't be less than 0";
}
}while(buy<0);
PreferredCustomer customer(last,first,address,city,state,zip,phone,num,mail,buy);
cout<<" ******************************************** ";
customer.getName();
cout<<"'s Information: ";
customer.print();
customer.display();
customer.printing();
cout<<endl;
}
CustomerData.cpp
#include "CustomerData.h"
CustomerData::CustomerData() : PersonData(){
custNum = 0;
mail = false;
}
CustomerData::CustomerData(string l, string f, string a, string c, string s, string z, string p, int num, bool mai) : PersonData(l,f,a,c,s,z,p){
set_num(num);
set_mail(mai);
}
void CustomerData::set_num(int num){
custNum = num;
}
void CustomerData::set_mail(bool mai){
mail = mai;
}
void CustomerData::display(){
cout<<"The customer's Number is "<<custNum<<endl;
if(mail == true){
cout<<"The customer wishes to be on a mailing list ";
}else if(mail == false){
cout<<"The customer does not wish to be on a mailing list ";
}
}
CustomerData.h
#ifndef CUSTOMERDATA_H
#define CUSTOMERDATA_H
#include "PersonData.h"
class CustomerData : public PersonData{
private:
int custNum;//customerNumber
bool mail; //mailingList
void set_num(int);
void set_mail(bool);
public:
CustomerData();
CustomerData(string,string,string,string,string,string,string,int,bool);
void display();
};
#endif /* CUSTOMERDATA_H */
Employee.cpp
#include "Employee.h"
#include <iostream>
void Employee::set_name(string n){
bool valid;
do{
valid=true;
if(n==""){
valid=false;
}
if(!valid){
cout<<"Input your name ";
cout<<"Name: ";
getline(cin,n);
}
}while(!valid);
name = n;
}
void Employee::set_number(string num){
bool valid;
do{
valid=true;
if(valid){
for(int i=0;i<num.length();i++){
if(!isdigit(num[i])){
valid=false;
cout<<"ERROR: You did not enter a number. Check to make sure they are all digits ";
break;
}
}
}
if(!valid){
cout<<"Input the Employee's number ";
cout<<"Number: ";
getline(cin,num);
}
}while(!valid);
number = num;
}
void Employee::set_hireD(string h){
hire = h;
}
Employee::Employee(){
name;
number;
hire;
}
Employee::Employee(string name,string number,string hire){
set_name(name);
set_number(number);
set_hireD(hire);
}
string Employee::getName() const{
return name;
}
string Employee::getNum() const{
return number;
}
string Employee::getDate() const{
return hire;
}
void Employee::print(){
cout<<"Name: "<<name;
cout<<" Number: "<<number;
cout<<" Hire: "<<hire<<endl;
}
Employee.h
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string>
using namespace std;
class Employee {
protected:
string name;
string number;
string hire;
void set_name(string);
void set_number(string);
void set_hireD(string);
public:
Employee();
Employee(string,string,string);
string getName()const;
string getNum()const;
string getDate()const;
void print();
};
#endif /* EMPLOYEE_H */
PersonData.cpp
#include "PersonData.h"
PersonData::PersonData(){
}
PersonData::PersonData(string l, string f, string a, string c, string s, string z, string p){
set_name(l,f);
set_home(a,c,s,z);
set_phone(p);
}
void PersonData::set_name(string l, string f){
last = l;
first = f;
}
void PersonData::set_home(string a, string c, string s, string z){
city = c;
state =address = a;
city = c;
state = s;
zip = z;
}
void PersonData::set_phone(string p){
phone = p;
}
void PersonData::getName(){
cout<<last<<", "<<first;
}
void PersonData::print(){
cout<<"******************************************** ";
cout<<"Last Name: "<<last<<endl;
cout<<"First Name: "<<first<<endl;
cout<<"Address: "<<address<<endl;
cout<<"City: "<<city<<endl;
cout<<"State: "<<state<<endl;
cout<<"Zip: "<<zip<<endl;
cout<<"Phone Number: "<<phone<<endl;
}
PersonData.h
#ifndef PERSONDATA_H
#define PERSONDATA_H
#include <iostream>
#include <string>
using namespace std;
class PersonData {
protected:
string last;
string first;
string address;
string city;
string state;
string zip;
string phone;
void set_name(string,string);
void set_home(string,string,string,string);
void set_phone(string);
public:
PersonData();
PersonData(string,string,string,string,string,string,string);
void getName();
void print();
};
#endif /* PERSONDATA_H */
PreferredCustomer.cpp
#include "PreferredCustomer.h"
#include <iomanip>
PreferredCustomer::PreferredCustomer(){
buy=0.0f;
disc=0.0f;
}
PreferredCustomer::PreferredCustomer
(string l, string f, string a, string c, string s, string z, string p,
int num, bool mai, float by) : CustomerData(l,f,a,c,s,z,p,num,mai){
set_values(by);
}
void PreferredCustomer::set_values(float by){
buy = by;
if(buy>=500){
disc=.05;
}
if(buy>=1000){
disc=.06;
}
if(buy>=1500){
disc=.07;
}
if(buy>=2000){
disc=.1;
}
}
void PreferredCustomer::printing(){
cout<<fixed<<setprecision(2);
cout<<"The Customer spent: $"<<buy<<endl;
cout<<"The customer now gets a "<<disc<<" discount on all future purchases."<<endl;
}
PreferredCustomer.h
#ifndef PREFERREDCUSTOMER_H
#define PREFERREDCUSTOMER_H
#include "CustomerData.h"
class PreferredCustomer : public CustomerData{
private:
float buy;//purchasesAmount
float disc;//discountLevel
void set_values(float);
public:
PreferredCustomer();
PreferredCustomer(string,string,string,string,string,string,string,int,bool,float);
void printing();
};
#endif /* PREFERREDCUSTOMER_H */
ProductionWorker.cpp
#include "ProductionWorker.h"
#include <iostream>
#include <iomanip>
using namespace std;
ProductionWorker::ProductionWorker() : Employee(){
shift =0;
rate=0.0f;
}
ProductionWorker::ProductionWorker(string n, string num, string d,int s, float r) : Employee(n,num,d){
set_shift(s);
set_rate(r);
}
void ProductionWorker::set_rate(float r){
bool valid;
do{
valid=true;
if(r<0){
cout<<"ERROR: Rate can't be less than 0 ";
valid=false;
}
if(!valid){
cout<<"Input the Hourly Pay Rate ";
cout<<"Pay Rate: ";
cin>>r;
}
}while(!valid);
rate=r;
}
void ProductionWorker::set_shift(int s){
bool valid;
do{
valid=true;
if(s !=1 && s!=2){
cout<<"ERROR: Shift must be 1 or 2 ";
valid=false;
}
if(!valid){
cout<<"Input the shift 1. Day 2. Night ";
cout<<"Shift: ";
cin>>s;
}
}while(!valid);
shift = s;
}
void ProductionWorker::display(){
cout<<"Shift: ";
switch(shift){
case 1:{
cout<<"Day Shift ";
break;
}
case 2:{
cout<<"Night Shift ";
break;
}
default:{
cout<<"Bad switch statement ";
break;
}
}
cout<< fixed << setprecision(2);
cout<<"Hourly Pay Rate: "<<rate<<endl;
}
ProductionWorker.h
#ifndef PRODUCTIONWORKER_H
#define PRODUCTIONWORKER_H
#include "Employee.h"
class ProductionWorker : public Employee {
private:
int shift;
float rate;
void set_shift(int);
void set_rate(float);
public:
ProductionWorker();
ProductionWorker(string,string,string,int,float);
int getshift()const {return shift;}
float getrate()const {return rate;}
void display();
};
#endif /* PRODUCTIONWORKER_H */
ShiftSupervisor.cpp
#include "ProductionWorker.h"
#include "ShiftSupervisor.h"
#include <iostream>
using namespace std;
ShiftSupervisor::ShiftSupervisor() : ProductionWorker(){
annual = 0.0f;
bonus = 0.0f;
}
ShiftSupervisor::ShiftSupervisor(string n, string num, string d, int s,
float r, float an, float bon)
: ProductionWorker(n,num,d,s,r){
set_annual(an);
set_bonus(bon);
}
void ShiftSupervisor::set_annual(float a){
bool valid;
do{
valid=true;
if(a<0){
cout<<"ERROR: Annual can't be less than 0 ";
valid=false;
}
if(!valid){
cout<<"Input the Supervisor's annual Salary ";
cout<<"Salary: ";
cin>>a;
}
}while(!valid);
annual = a;
}
void ShiftSupervisor::set_bonus(float b){
bool valid;
do{
valid=true;
if(b<0){
cout<<"ERROR: Bonus can't be less than 0 ";
valid=false;
}
if(!valid){
cout<<"Input the Supervisor's annual production bonus ";
cout<<"Bonus: ";
cin>>b;
}
}while(!valid);
bonus = b;
}
void ShiftSupervisor::printS(){
cout<<endl;
cout<<"******************************************"<<endl;
cout<<"Supervisor's annual Salary: $"<<annual<<endl;
cout<<"Supervisor's annual Bonus: $"<<bonus<<endl;
}
ShiftSupervisor.h
#ifndef SHIFTSUPERVISOR_H
#define SHIFTSUPERVISOR_H
#include "ProductionWorker.h"
class ShiftSupervisor : public ProductionWorker{
private:
float annual;
float bonus;
void set_annual(float);
void set_bonus(float);
public:
ShiftSupervisor();
ShiftSupervisor(string,string,string,int,float,float,float);
float getAnnual()const { return annual;}
float getBonus()const { return bonus;}
void printS();
};
#endif /* SHIFTSUPERVISOR_H */
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.