Here’s some UML samples: code and diagrams:
// // main.cpp // testUML // // Created by Petricioiu Robert on 6/8/13. // Copyright (c) 2013 Petricioiu Robert. All rights reserved. // #include <iostream> #include <vector> using namespace std; class Vehicle{ protected: bool state; int cost; public: Vehicle(bool newState, int newCost) : state(newState), cost(newCost){} void setState(bool newState){ state = newState; } int getState(){ return state; } void setCost(int newCost){ cost = newCost; } int getCost(int newCost){ return cost; } virtual void printInfo() = 0; }; class Autom : public Vehicle{ private: int numberOfSits; int numberOfKm; public: Autom(bool newState, int newCost, int newNumberOfSits, int newNumberOfKm) : numberOfKm(newNumberOfKm), numberOfSits(newNumberOfSits), Vehicle(newState,newCost){} void setNumberOfSits(int newVal){ numberOfSits = newVal; } void setNumberOfKm(int newVal){ numberOfKm = newVal; } int getNumberOfSits(){ return numberOfSits; } int getNumberOfKm(){ return numberOfKm; } void printInfo(){ cout<<"Cost: "<<cost<<endl; if (!state) cout<<"State: rent"<<endl; else cout<<"State: undisposed"<<endl; cout<<"Number locuri: "<<numberOfSits<<endl; cout<<"Number of km: "<<numberOfKm<<endl; } }; class Truck : public Vehicle{ private: int capacity; int numberOfKm; public: Truck(bool newState, int newCost, int newCapacity, int newNumberOfKm) : capacity(newCapacity), numberOfKm(newNumberOfKm), Vehicle(newState,newCost){} void setNumberOfKm(int newVal){ numberOfKm = newVal; } int getNumberOfKm(){ return numberOfKm; } void setCapacity(int newVal){ capacity = newVal; } int getCapacity(){ return capacity; } void printInfo(){ cout<<"Cost: "<<cost<<endl; if (!state) cout<<"State: rent"<<endl; else cout<<"State: undisposed"<<endl; cout<<"Capacity: "<<capacity<<endl; cout<<"Number of km: "<<numberOfKm<<endl; } }; class Bike : public Vehicle{ private: int numberOfRentDays; public: Bike(bool newState, int newCost, int newNumberOfRentDays) : numberOfRentDays(newNumberOfRentDays), Vehicle(newState,newCost){} void setNumberOfRentDays(int newVal){ numberOfRentDays = newVal; } int getNumberOfRentDays(){ return numberOfRentDays; } void printInfo(){ cout<<"Cost: "<<cost<<endl; if (!state) cout<<"State: rent"<<endl; else cout<<"State: undisposed"<<endl; cout<<"NumberOfRentDays: "<<numberOfRentDays<<endl; } }; class Manager{ private: vector<Vehicle* > _vehicles; public: Manager(){} void addVehicle(Vehicle* newVehicle){ _vehicles.push_back(newVehicle); } void showVehicleInfo(Vehicle* _vehicle){ _vehicle->printInfo(); } void showMeTheVehicles(){ for (vector<Vehicle*>::iterator it =_vehicles.begin(); it != _vehicles.end(); ++it) { (*it)->printInfo(); } } }; int main(int argc, const char * argv[]) { Autom *m = new Autom(true,2500,5,100); Truck *t = new Truck(false, 25000, 3, 100); Bike *b = new Bike(true, 500, 120); Manager _boss; _boss.addVehicle(m); _boss.addVehicle(t); _boss.addVehicle(b); _boss.showMeTheVehicles(); return 0; }