Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- using namespace std;
- int main() {
- map<int, string> carModels;
- map<int, string> carBrands;
- map<int, float> carCapacities;
- map<int, float> carVelocities;
- cout << "==============================" << endl;
- cout << "CAR DATABASE" << endl;
- cout << "==============================" << endl;
- cout << "How many cars would you like to add?" << endl;
- int carAmount; cin >> carAmount;
- cout << "Cars to be added: " << carAmount << endl;
- for (int i = 1; i <= carAmount; i++) {
- cout << "------------------------------" << endl;
- cout << "Car " << i << ": Enter the MODEL" << endl;
- if (!(cin)) cin.clear();
- string model; cin >> model;
- cout << "------------------------------" << endl;
- cout << "Car " << i << ": Enter the BRAND" << endl;
- if (!(cin)) cin.clear();
- string brand; cin >> brand;
- cout << "------------------------------" << endl;
- cout << "Car " << i << ": Enter the CAPACITY" << endl;
- if (!(cin)) cin.clear();
- float capacity; cin >> capacity;
- cout << "------------------------------" << endl;
- cout << "Car " << i << ": Enter the VELOCITY" << endl;
- if (!(cin)) cin.clear();
- int velocity; cin >> velocity;
- cout << "------------------------------" << endl;
- carModels[i] = model;
- carBrands[i] = brand;
- carCapacities[i] = capacity;
- carVelocities[i] = velocity;
- cout << "Car " << i << ": "<< model << ", " << brand << ", " << capacity << ", " << velocity << endl;
- }
- while (true) {
- cout << "------------------------------" << endl;
- cout << "Commands:" << endl;
- cout << "getmodel" << endl;
- cout << "getbrand" << endl;
- cout << "getcapacity" << endl;
- cout << "getvelocity" << endl;
- cout << "calccapacity" << endl;
- cout << "calcvelocity" << endl;
- cout << "------------------------------" << endl;
- string argument; cin >> argument;
- if (argument == "getmodel") {
- cout << "------------------------------" << endl;
- cout << "Please enter the Car ID" << endl;
- int carId; cin >> carId;
- if (carModels.find(carId) == carModels.end()) {
- cout << "Invalid Car ID" << endl;
- cout << "------------------------------" << endl;
- continue;
- }
- cout << "Result: " << carModels[carId] << endl;
- cout << "------------------------------" << endl;
- }
- if (argument == "getbrand") {
- cout << "------------------------------" << endl;
- cout << "Please enter the Car ID" << endl;
- int carId; cin >> carId;
- if (carBrands.find(carId) == carBrands.end()) {
- cout << "Invalid Car ID" << endl;
- cout << "------------------------------" << endl;
- continue;
- }
- cout << "Result: " << carBrands[carId] << endl;
- cout << "------------------------------" << endl;
- }
- if (argument == "getcapacity") {
- cout << "------------------------------" << endl;
- cout << "Please enter the Car ID" << endl;
- int carId; cin >> carId;
- if (carCapacities.find(carId) == carCapacities.end()) {
- cout << "Invalid Car ID" << endl;
- cout << "------------------------------" << endl;
- continue;
- }
- cout << "Result: " << carCapacities[carId] << endl;
- cout << "------------------------------" << endl;
- }
- if (argument == "getvelocity") {
- cout << "------------------------------" << endl;
- cout << "Please enter the Car ID" << endl;
- int carId; cin >> carId;
- if (carVelocities.find(carId) == carVelocities.end()) {
- cout << "Invalid Car ID" << endl;
- cout << "------------------------------" << endl;
- continue;
- }
- cout << "Result: " << carVelocities[carId] << endl;
- cout << "------------------------------" << endl;
- }
- if (argument == "calccapacity") {
- cout << "------------------------------" << endl;
- cout << "Please enter the Car ID" << endl;
- int car1Id; cin >> car1Id;
- if (carCapacities.find(car1Id) == carCapacities.end()) {
- cout << "Invalid Car ID" << endl;
- cout << "------------------------------" << endl;
- continue;
- }
- cout << "Please enter the Car ID" << endl;
- int car2Id; cin >> car2Id;
- if (carCapacities.find(car2Id) == carCapacities.end()) {
- cout << "Invalid Car ID" << endl;
- cout << "------------------------------" << endl;
- continue;
- }
- float sumCapacity = carCapacities[car1Id] + carCapacities[car2Id];
- cout << "Result: " << sumCapacity << endl;
- cout << "------------------------------" << endl;
- }
- if (argument == "calcvelocity") {
- cout << "------------------------------" << endl;
- cout << "Please enter the Car ID" << endl;
- int car1Id; cin >> car1Id;
- if (carVelocities.find(car1Id) == carVelocities.end()) {
- cout << "Invalid Car ID" << endl;
- cout << "------------------------------" << endl;
- continue;
- }
- cout << "Please enter the Car ID" << endl;
- int car2Id; cin >> car2Id;
- if (carVelocities.find(car2Id) == carVelocities.end()) {
- cout << "Invalid Car ID" << endl;
- cout << "------------------------------" << endl;
- continue;
- }
- int sumVelocity = carVelocities[car1Id] + carVelocities[car2Id];
- int avgVelocity = sumVelocity / 2;
- cout << "Result: " << avgVelocity << endl;
- cout << "------------------------------" << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement