Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Styles Problem Statement You have been asked to write a program for a retail sto

ID: 3601425 • Letter: S

Question

Styles Problem Statement You have been asked to write a program for a retail store that will allow them to calculate discounts for their employees when they buy items. Discounts are based on number of years worked as well as if the employee is a manager or hourly employee. They are also allowed no discount once they have received $200 in discounts for the year. INPU The application must be able to collect the following "required information for each employee: 1. Name (required) 2. Number of years employed (required, numeric, 90) 3. Total amount of previous purchases before discount (required, numeric, 90 4. Employee status (employee or manager) 5. Total of today's purchase (required, numeric, >=0) OUTPUT There are two distinct areas required for output 1. For each employee display the following a Name b. Employee discount percentage C. YTD Amount of discount in dollars d. Total purchase today before discount e Employee discount this purchase £ Total with discount 2. Calculate the total for all employees for today's date a Total before discount for the day b. Total after discounts applied ROCES Employee discount standard Years of Employment 1-3 Years Management 20% Hourly 100% ears 30% 7-10 Years 11-15 Years More than 15 Years 20% 25% 40% YTD discount in dollars = total purchase before today discount

Explanation / Answer

#include<iostream>
#include<string.h>
using namespace std;

// Class Employee definition
class Employee
{
// Private data member to store data
string name;
int numberOfYears;
double previousPurchase;
string empStatus;
double todayPurchase;
double discountPercent;
double discountPrevious;
double discountThisPurchase;
double totalWithDiscount;
double totalBeforeDiscount;
double totalAfterDiscount;
public:
// Prototype of member functions
void acceptData();
void displayData();
void calculateDiscount();
double getTotalBeforeDiscount();
double getTotalAfterDiscount();
};// End of class

// Function to return total before discount
double Employee::getTotalBeforeDiscount()
{
return totalBeforeDiscount;
}// End of function

// Function to return total after discount
double Employee::getTotalAfterDiscount()
{
return totalAfterDiscount;
}// End of function

// Function to accept employee data
void Employee::acceptData()
{
cout<<" Enter employee name: ";
cin>>name;
cout<<" Enter number of years: ";
cin>>numberOfYears;
cout<<" Enter amount previous purchase: ";
cin>>previousPurchase;
cout<<" Enter employee status (employee or manager): ";
cin>>empStatus;
cout<<" Enter today's purchase: ";
cin>>todayPurchase;
}// End of function

// Function to display employee data
void Employee::displayData()
{
cout<<" Name: "<<name;
cout<<" Employee discount percentage: "<<discountPercent;
cout<<" YTD Amount of discount in dollar: "<<discountPrevious;
cout<<" Total purchase today before discount: "<<previousPurchase;
cout<<" Employee discount this purchase: "<<discountThisPurchase;
cout<<" Total with discount: "<<totalWithDiscount;
}// End of function

// Function to calculate discount
void Employee::calculateDiscount()
{
// Initializes the variables
totalBeforeDiscount = 0;
totalAfterDiscount = 0;
// Checks if the employee status is manager
if(empStatus.compare("manager"))
{
// Checks if the number of years between the range of 1 - 3
if(numberOfYears >= 1 && numberOfYears <= 3)
// Stores discount percentage
discountPercent = .2;
// Otherwise checks if the number of years between the range of 4 - 6
else if(numberOfYears >= 4 && numberOfYears <= 6)
// Stores discount percentage
discountPercent = .24;
// Otherwise checks if the number of years between the range of 7 - 10
else if(numberOfYears >= 7 && numberOfYears <= 10)
// Stores discount percentage
discountPercent = .3;
// Otherwise checks if the number of years between the range of 11 - 15
else if(numberOfYears >= 11 && numberOfYears <= 15)
// Stores discount percentage
discountPercent = .35;
// Otherwise
else
// Stores discount percentage
discountPercent = .4;
}// End of if condition
// Otherwise checks if the employee status is manager
else if(empStatus.compare("employee"))
{
// Checks if the number of years between the range of 1 - 3
if(numberOfYears >= 1 && numberOfYears <= 3)
// Stores discount percentage
discountPercent = .1;
// Otherwise checks if the number of years between the range of 4 - 6
else if(numberOfYears >= 4 && numberOfYears <= 6)
// Stores discount percentage
discountPercent = .14;
// Otherwise checks if the number of years between the range of 7 - 10
else if(numberOfYears >= 7 && numberOfYears <= 10)
// Stores discount percentage
discountPercent = .2;
// Otherwise checks if the number of years between the range of 11 - 15
else if(numberOfYears >= 11 && numberOfYears <= 15)
// Stores discount percentage
discountPercent = .25;
// Otherwise
else
// Stores discount percentage
discountPercent = .3;
}// End of else if
// Calculates previous discount
discountPrevious = previousPurchase * discountPercent;
// Checks if previous discount is less than 200 then only calculates todays discount
if(discountPrevious < 200)
{
// Calculates todays discount
discountThisPurchase = todayPurchase * discountPercent;
// Checks if current discount is more than 200 then set the current discount to 200
if(discountThisPurchase > 200)
discountThisPurchase = 200;
}// End of if condition
// Calculates total discount
totalWithDiscount = (previousPurchase + todayPurchase) - (discountPrevious + discountThisPurchase);
// Calculate total before discount
totalBeforeDiscount += (previousPurchase + todayPurchase);
// Calculate total after discount
totalAfterDiscount += totalWithDiscount;
}// End of function

int main()
{
// To store number of employees entered by the user
int no;
// Accepts number of users
cout<<" Enter how many employees: ";
cin>>no;
// Dynamically creates employees class array of objects
Employee *emp = new Employee[no];
// Loops till number of employees entered by the user
for(int x = 0; x < no; x++)
{
// Calls the function to accept employees data for each employee
emp[x].acceptData();
// Calls the function to calculate discount for each employee
emp[x].calculateDiscount();
}// End of for loop
// Loops till number of employees entered by the user
for(int x = 0; x < no; x++)
// Displays each employee data
emp[x].displayData();
// Displays summary
cout<<" Total Before Discount: "<<emp[0].getTotalBeforeDiscount();
cout<<" Total After Discount: "<<emp[0].getTotalAfterDiscount();
}// End of main function

Sample Run:

Enter how many employees: 5

Enter employee name: Pyari

Enter number of years: 5

Enter amount previous purchase: 2000

Enter employee status (employee or manager): manager

Enter today's purchase: 5000

Enter employee name: Mohan

Enter number of years: 12

Enter amount previous purchase: 7000

Enter employee status (employee or manager): manager

Enter today's purchase: 12000

Enter employee name: Sahu

Enter number of years: 2

Enter amount previous purchase: 1000

Enter employee status (employee or manager): employee

Enter today's purchase: 500

Enter employee name: Sasmita

Enter number of years: 8

Enter amount previous purchase: 2000

Enter employee status (employee or manager): employee

Enter today's purchase: 1000

Enter employee name: Panda

Enter number of years: 7

Enter amount previous purchase: 3000

Enter employee status (employee or manager): employee

Enter today's purchase: 1500

Name: Pyari
Employee discount percentage: 0.14
YTD Amount of discount in dollar: 280
Total purchase today before discount: 2000
Employee discount this purchase: 0
Total with discount: 6720
Name: Mohan
Employee discount percentage: 0.25
YTD Amount of discount in dollar: 1750
Total purchase today before discount: 7000
Employee discount this purchase: 0
Total with discount: 17250
Name: Sahu
Employee discount percentage: 0.2
YTD Amount of discount in dollar: 200
Total purchase today before discount: 1000
Employee discount this purchase: 0
Total with discount: 1300
Name: Sasmita
Employee discount percentage: 0.3
YTD Amount of discount in dollar: 600
Total purchase today before discount: 2000
Employee discount this purchase: 0
Total with discount: 2400
Name: Panda
Employee discount percentage: 0.3
YTD Amount of discount in dollar: 900
Total purchase today before discount: 3000
Employee discount this purchase: 0
Total with discount: 3600


Total Before Discount: 7000

Total After Discount: 6720