mirror of
https://codeberg.org/andyscott/exercism.git
synced 2024-11-09 13:20:48 -05:00
36 lines
1,006 B
C++
36 lines
1,006 B
C++
|
#include "vehicle_purchase.h"
|
||
|
#include <cctype>
|
||
|
#include <string>
|
||
|
|
||
|
namespace vehicle_purchase {
|
||
|
|
||
|
// needs_license determines whether a license is needed to drive a type of
|
||
|
// vehicle. Only "car" and "truck" require a license.
|
||
|
bool needs_license(std::string kind) {
|
||
|
return (kind == "car") || (kind == "truck");
|
||
|
}
|
||
|
|
||
|
// choose_vehicle recommends a vehicle for selection. It always recommends the
|
||
|
// vehicle that comes first in lexicographical order.
|
||
|
std::string choose_vehicle(std::string option1, std::string option2) {
|
||
|
std::string suffix{" is clearly the better choice."};
|
||
|
return (option1 > option2) ? option2 + suffix : option1 + suffix;
|
||
|
}
|
||
|
|
||
|
// calculate_resell_price calculates how much a vehicle can resell for at a
|
||
|
// certain age.
|
||
|
double calculate_resell_price(double original_price, double age) {
|
||
|
|
||
|
if (age < 3) {
|
||
|
original_price *= 0.8;
|
||
|
} else if (age >= 10) {
|
||
|
original_price *= 0.5;
|
||
|
} else {
|
||
|
original_price *= 0.7;
|
||
|
}
|
||
|
|
||
|
return original_price;
|
||
|
}
|
||
|
|
||
|
} // namespace vehicle_purchase
|