Skip to content

Instantly share code, notes, and snippets.

@juliosandino
Last active October 27, 2017 04:25
Show Gist options
  • Save juliosandino/2b8d77d6474df94d4db12719911b308c to your computer and use it in GitHub Desktop.
Save juliosandino/2b8d77d6474df94d4db12719911b308c to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <iomanip>
using std::cout;
using std::string;
const string silver = "silver";
const string gold = "gold";
const string platinum = "platinum";
string monogram(string firstName, string middleName, string lastName) {
return firstName.substr(0,1) + middleName.substr(0,1) + lastName.substr(0,1);
}
double get_discount(const string level) {
if (level == "silver")
return 0.10;
else if (level == "gold")
return 0.20;
else if (level == "platinum")
return 0.33;
else
return 0.00;
}
double total_after_discount(double priceBeforeDiscount, const string level) {
return priceBeforeDiscount * ( 1.00 - get_discount(level));
}
string outwear_choice(int temperature) {
if (temperature <= 32)
return "parka";
else if (temperature > 32 && temperature < 50)
return "coat";
else if (temperature >= 50 && temperature < 60)
return "jacket";
else if (temperature >= 60)
return "no outwear today";
else
return "";
}
double workout_amt(int slices) {
if (slices == 0)
return 0.5;
else if (slices >= 1 && slices <= 4)
return 1;
else if (slices > 4)
return 1 + .5 * (double (slices) - 4);
else
return 0;
}
int main() {
cout << std::fixed << std::showpoint;
cout << std::setprecision(2);
cout << "-----MONOGRAM TEST-----\n";
cout << "First: Julio, Second: Eduardo, Third: Sandino\n";
cout << "Expected: JES\n";
cout << "Result: ";
cout << monogram("Julio" , "Eduardo", "Sandino") << std::endl;
cout << "-----/MONOGRAM TEST----\n\n";
cout << "-----DISCOUNT TEST-----\n";
cout << "First: Silver, Expected: 0.10\n";
cout << "Result: " << get_discount(silver) << std::endl;
cout << "First: Gold, Expected: 0.20\n";
cout << "Result: " << get_discount(gold) << std::endl;
cout << "First: Platinum, Expected: 0.33\n";
cout << "Result: " << get_discount(platinum) << std::endl;
cout << "-----/DISCOUNT TEST----\n\n";
cout << "-----TOTAL DISCOUNT TEST-----\n";
double price = 100.00;
cout << "Price Before: 100, Tier: Silver, Expected: 90.00\n";
cout << "Result: " << total_after_discount(price, silver) << std::endl;
cout << "Price Before: 100, Tier: Gold, Expected: 80.00\n";
cout << "Result: " << total_after_discount(price, gold) << std::endl;
cout << "Price Before: 100, Tier: Platinum, Expected: 67.00\n";
cout << "Result: " << total_after_discount(price, platinum) << std::endl;
cout << "-----/TOTAL DISCOUNT TEST----\n\n";
cout << "-----OUTWEAR CHOICE TEST-----\n";
cout << "Temperature: 30F, Expected: parka\n";
cout << "Result:" << outwear_choice(30) << std::endl;
cout << "Temperature: 40F, Expected: coat\n";
cout << "Result:" << outwear_choice(40) << std::endl;
cout << "Temperature: 50F, Expected: jacket\n";
cout << "Result:" << outwear_choice(50) << std::endl;
cout << "Temperature: 60F, Expected: no outwear today\n";
cout << "Result:" << outwear_choice(60) << std::endl;
cout << "----/OUTWEAR CHOICE TEST-----\n\n";
cout << "-----WORKOUT AMT TEST-----\n";
cout << "Slices eaten: 1, Expected: 0.50\n";
cout << "Result: " << workout_amt(0) << std::endl;
cout << "Slices eaten: 3, Expected: 1.00\n";
cout << "Result: " << workout_amt(3) << std::endl;
cout << "Slices eaten: 7, Expected: 2.50\n";
cout << "Result: " << workout_amt(7) << std::endl;
cout << "----/WORKOUT AMT TEST-----\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment