Last active
May 4, 2018 00:23
-
-
Save jesuyedavid/da62cee37567f295c7bdc356cbc728f8 to your computer and use it in GitHub Desktop.
For each used car a salesperson sells, the commission is paid as follows: $20 plus 30% of the selling price in excess of the cost of the car. Typically, the minimum selling price of the car is the cost of the car plus $200 and the maximum selling price of the car is the cost of the car and $2,000. Write a program that prompts the user to enter t…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <assert.h> | |
using namespace std; | |
struct result{ | |
double maxiSelPrice; | |
double miniSelPrice; | |
double comRangeL; | |
double comRangeU; | |
}; | |
//declarations | |
/**********************************************************************************************************/ | |
bool welcomeUser(double& fixCom, double& perCom, double& purCost, double& minToCost, double& maxToCost); | |
bool collectUserInput(double& fixCom, double& perCom, double& purCost, double& minToCost, double& maxToCost); | |
result calculateValues(double& fixCom, double& perCom, double& purCost, double& minToCost, double& maxToCost); | |
bool checkUserInput(double& numCheck); | |
void blackBoxTest(); | |
/**********************************************************************************************************/ | |
int main() { | |
double fixCom=0.0; | |
double perCom=0.0; | |
double purCost=0.0; | |
double minToCost=0.0; | |
double maxToCost=0.0; | |
welcomeUser(fixCom, perCom, purCost, minToCost, maxToCost); | |
//dblackBoxTest(); | |
} | |
bool welcomeUser(double& fixCom, double& perCom, double& purCost, double& minToCost, double& maxToCost){ | |
char choice='y'; | |
cout<<"Welcome!"<<endl<<"Would you like to calculate commissions?"<<endl; | |
cin>>choice; | |
if (choice=='n'){ | |
cout<<"Ok goodbye"; | |
return false; | |
exit(1); | |
}else{ | |
collectUserInput(fixCom, perCom, purCost, minToCost, maxToCost); | |
} | |
} | |
//collects user input and checks for invalid inputs | |
bool collectUserInput(double& fixCom, double& perCom, double& purCost, double& minToCost, double& maxToCost){ | |
char again; | |
cout<<"Enter the salesperson fixed commision"<<endl; | |
checkUserInput(fixCom); | |
cout<<"Enter the percentage of the commision"<<endl; | |
checkUserInput(perCom); | |
cout<<"Enter the purchasing cost of the car"<<endl; | |
checkUserInput(purCost); | |
cout<<"Enter the minimum amount to be added to the purchasing cost"<<endl; | |
checkUserInput(minToCost); | |
cout<<"Enter the maximim amount to be added to the purchasing cost"<<endl; | |
checkUserInput(maxToCost); | |
calculateValues(fixCom, perCom, purCost, minToCost, maxToCost); | |
//calculate another commision | |
cout<<"Would you like to calculate another commission"<<endl; | |
cin>>again; | |
if (again=='y'){ | |
collectUserInput(fixCom, perCom, purCost, minToCost, maxToCost); | |
return true; | |
}else{ | |
cout<<"Ok goodbye. See you later"<<endl; | |
exit(1); | |
return false; | |
} | |
} | |
//calculate commision range and max and min selling price of car | |
result calculateValues(double& fixCom, double& perCom, double& purCost, double& minToCost, double& maxToCost){ | |
result result; | |
if (minToCost<200) | |
minToCost=200; | |
if (maxToCost<2000) | |
maxToCost=2000; | |
result.miniSelPrice=purCost+200; | |
result.maxiSelPrice=purCost+2000; | |
cout<<"The minimum selling price of this car is: $"<<result.miniSelPrice<<endl; | |
cout<<"The maximum selling price of this car is: $"<<result.maxiSelPrice<<endl; | |
if (fixCom<20) | |
fixCom=20; | |
if (perCom<30) | |
perCom=30; | |
result.comRangeL=(perCom*0.01*(result.miniSelPrice-purCost))+fixCom; | |
result.comRangeU=(perCom*0.01*(result.maxiSelPrice-purCost))+fixCom; | |
cout<<"The commision range is: $"<<result.comRangeL<<" - $"<<result.comRangeU<<endl; | |
return result; | |
} | |
//makes sure user enters valid inputs | |
//if not, asks user to reenter values | |
bool checkUserInput(double& numCheck){ | |
bool correct=false; | |
while (!correct) | |
{ | |
cin >> numCheck; | |
if((cin.fail()) || (numCheck<0)) | |
{ | |
cin.clear(); | |
while(cin.get() != '\n'); | |
cout << "Please enter a valid value. "<< endl; | |
correct = false; | |
} | |
else | |
{ | |
cin.ignore(); | |
correct =true; | |
} | |
} | |
} | |
//white box testing | |
//black box testing | |
void blackBoxTest(){ | |
double fixComTest=20; | |
double perComTest=30; | |
double purCostTest=5000; | |
double minToCostTest=200; | |
double maxToCostTest=2000; | |
result testResult; | |
testResult.comRangeL=80; | |
testResult.comRangeU=620; | |
testResult.maxiSelPrice=7000; | |
testResult.miniSelPrice=5200; | |
assert(testResult.comRangeL==calculateValues(fixComTest, perComTest, purCostTest, minToCostTest, maxToCostTest).comRangeL); | |
assert(testResult.comRangeU==calculateValues(fixComTest, perComTest, purCostTest, minToCostTest, maxToCostTest).comRangeU); | |
assert(testResult.maxiSelPrice==calculateValues(fixComTest, perComTest, purCostTest, minToCostTest, maxToCostTest).maxiSelPrice); | |
assert(testResult.miniSelPrice==calculateValues(fixComTest, perComTest, purCostTest, minToCostTest, maxToCostTest).miniSelPrice); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For each used car a salesperson sells, the commission is paid as follows: $20 plus 30% of the selling price in excess of the cost of the car. Typically, the minimum selling price of the car is the cost of the car plus $200 and the maximum selling price of the car is the cost of the car and $2,000. Write a program that prompts the user to enter the salesperson’s fixed commission, the percentage of the commission, the purchasing cost of the car, the minimum and maximum amount to be added to the purchasing cost to determine the minimum and maximum selling price, and outputs minimum and maximum selling price of the car and the salesperson’s commission range.