online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <iostream> #include <fstream> #include <vector> #include <string> #include <functional> #include <iterator> using namespace std; class Worker { protected: string fullname; unsigned int age; float experience; public: void set_fullname(string name){ fullname=name; } string get_fullname() const { return fullname; } void set_age(unsigned int years){ age=years; } unsigned int get_age() const { return age; } void set_experience(float expr){ experience=expr; } float get_experience() const { return experience; } virtual void showworkerinfo() const =0; }; class Driver: public Worker{ private: string licencenumber, category; public: void set_licencenumber(string licence){ licencenumber=licence; } string get_licencenumber() const { return licencenumber; } void set_category(string cat){ category=cat; } string get_category() const { return category; } void showworkerinfo() const override{ cout<<"|"<<'\t'<<fullname<<'\t'<<"|"<<'\t'<<age<<'\t'<<"|"<<'\t'<<experience<<'\t'<<"|"<<'\t'<<licencenumber<<'\t'<<"|"<<'\t'<<category<<'\t'<<"|"<<endl; } }; class Staff: public Worker{ protected: int category; public: void set_category(int cat){ category=cat; } int get_category() const { return category; } void showworkerinfo() const override{ cout<<"|"<<'\t'<<fullname<<'\t'<<"|"<<'\t'<<age<<'\t'<<"|"<<'\t'<<experience<<'\t'<<"|"<<'\t'<<category<<'\t'<<"|"<<endl; } }; class Welder: public Staff{ private: int level; public: void set_level(int lev){ level=lev; } int get_level() const { return level; } void showworkerinfo() const override{ cout<<"|"<<'\t'<<fullname<<'\t'<<"|"<<'\t'<<age<<'\t'<<"|"<<'\t'<<experience<<'\t'<<"|"<<'\t'<<category<<'\t'<<"|"<<'\t'<<level<<'\t'<<"|"<<endl; } }; class Brigadier: public Worker{ public: void showworkerinfo() const override{ cout<<"|"<<'\t'<<fullname<<'\t'<<"|"<<'\t'<<age<<'\t'<<"|"<<'\t'<<experience<<'\t'<<"|"<<endl; } }; class Master: public Brigadier{ }; class Head: public Brigadier{ }; class Garage{ private: float area; public: void set_area(float m2){ area=m2; } float get_area() const { return area; } }; class Vehicle { protected: string brand; string color; string number; unsigned int year_of_production; float petrol; vector<Driver*> driver_; public: void set_brand(string brandname){ brand=brandname; } string get_brand() const { return brand; } void set_color(string colour){ color=colour; } string get_color() const { return color; } void set_number(string nmb){ number=nmb; } string get_number()const{ return number; } void set_year_of_production(unsigned int year){ year_of_production=year; } unsigned int get_year_of_production()const{ return year_of_production; } void set_petrol(float ptrl){ petrol=ptrl; } float get_petrol()const{ return petrol; } void add_driver(Driver* driver) { driver_.push_back(driver); } void show_driver(){ for(int i=0;i<driver_.size();i++){ cout<<"|\t"<<driver_[i]->get_fullname()<<"\t|\t"<<driver_[i]->get_licencenumber()<<"\t|\t\n"; } } virtual void showcarinfo()const=0; }; class PublicTransport: public Vehicle{ protected: unsigned int passengerseats; public: void set_passengersseats(unsigned int seats){ passengerseats=seats; } unsigned int get_passengerseats()const{ return passengerseats; } }; class Bus: public PublicTransport{ private: string route; public: void set_route(string rout){ route=rout; } string get_route()const{ return route; } void showcarinfo()const override{ cout<<"|"<<'\t'<<number<<'\t'<<"|"<<'\t'<<color<<'\t'<<"|"<<'\t'<<brand<<'\t'<<"|"<<'\t'<<year_of_production<<'\t'<<"|"<<'\t'<<petrol<<'\t'<<"|"<<'\t'<< passengerseats<<'\t'<<"|"<<'\t'<<route<<'\t'<<"|"<<endl; } }; class Taxi: public PublicTransport{ private: float kg; public: void set_kg(float kh){ kg=kh; } float get_kg()const{ return kg; } void showcarinfo()const override{ cout<<"|"<<'\t'<<number<<'\t'<<"|"<<'\t'<<color<<'\t'<<"|"<<'\t'<<brand<<'\t'<<"|"<<'\t'<<year_of_production<<'\t'<<"|"<<'\t'<<petrol<<'\t'<<"|"<<'\t'<< passengerseats<<'\t'<<"|"<<'\t'<<kg<<'\t'<<"|"<<endl; } }; class TouristicCoach: public PublicTransport{ private: float moneyperhour; public: void set_moneyperhour(float money){ moneyperhour=money; } float get_moneyperhour()const{ return moneyperhour; } void showcarinfo()const override{ cout<<"|"<<'\t'<<number<<'\t'<<"|"<<'\t'<<color<<'\t'<<"|"<<'\t'<<brand<<'\t'<<"|"<<'\t'<<year_of_production<<'\t'<<"|"<<'\t'<<petrol<<'\t'<<"|"<<'\t'<< passengerseats<<'\t'<<"|"<<'\t'<<moneyperhour<<'\t'<<"|"<<endl; } }; class Truck: public Vehicle{ protected: float tons; public: void set_tons(float ton){ tons=ton; } float get_tons()const{ return tons; } void showcarinfo()const override{ cout<<"|"<<'\t'<<number<<'\t'<<"|"<<'\t'<<color<<'\t'<<"|"<<'\t'<<brand<<'\t'<<"|"<<'\t'<<year_of_production<<'\t'<<"|"<<'\t'<<petrol<<'\t'<<"|"<<'\t'<<tons<<'\t'<<"|"<<endl; } }; class AuxiliaryTransport: public Truck{ private: float length, width; public: void set_length(float m){ length=m; } float get_length()const{ return length; } void set_width(float m){ width=m; } float get_width()const{ return width; } void showcarinfo()const override{ cout<<"|"<<'\t'<<number<<'\t'<<"|"<<'\t'<<color<<'\t'<<"|"<<'\t'<<brand<<'\t'<<"|"<<'\t'<<year_of_production<<'\t'<<"|"<<'\t'<<petrol<<'\t'<<"|"<<'\t'<<tons<<'\t'<<"|"<<'\t'<<length<<'\t'<<"|"<<'\t'<<width<<'\t'<<"|"<<endl; } }; void cin_string(string& str,ifstream& file,int size=256,char delim='|'){ str=""; getline(file,str,delim); } void cin_float(double& f,ifstream& file,char delim='|',int size=256){ char* cstr= new char[size]; file.getline(cstr,size,delim); f=atof(cstr); delete[] cstr; } void cin_int(int& f,ifstream& file,char delim='|',int size=256){ char* cstr= new char[size]; file.getline(cstr,size,delim); f=atoi(cstr); delete[] cstr; } int main() { vector<Bus> buses; vector<Driver> drivers; string carnumber, carcolor, carbrand, carroute, personname, personlicence, personcategory; int caryear, carseat, personage, npersoncategory, personlevel; double carpetrol, carkg, carmoney, carton, carlength, carwidth, cararea, personexp; ifstream fbus("buses.txt"); if(!fbus.is_open ()){ cout<<'\n'<<"Ôàéë, ùî ì³ñòèòü äàí³ ïðî ìàðøðóòí³ àâòîáóñè, íå çíàéäåíî."<<endl; } while(!fbus.eof()){ cin_string(carnumber,fbus); cin_string(carcolor,fbus); cin_string(carbrand,fbus); cin_int(caryear,fbus); cin_float(carpetrol,fbus); cin_int(carseat,fbus); cin_string(carroute,fbus); Bus bus; bus.set_number(carnumber); bus.set_color(carcolor); bus.set_brand(carbrand); bus.set_year_of_production(caryear); bus.set_petrol(carpetrol); bus.set_passengersseats(carseat); bus.set_route(carroute); buses.push_back(bus); } fbus.close(); ifstream fdriver("drivers.txt"); if(!fdriver.is_open ()){ cout<<'\n'<<"Ôàéë, ùî ì³ñòèòü äàí³ ïðî âî䳿â, íå çíàéäåíî."<<endl; } while(!fdriver.eof()){ cin_string(personname,fdriver); cin_int(personage,fdriver); cin_float(personexp,fdriver); cin_string(personlicence,fdriver); cin_string(personcategory,fdriver); Driver driver; driver.set_fullname(personname); driver.set_age(personage); driver.set_experience(personexp); driver.set_licencenumber(personlicence); driver.set_category(personcategory); drivers.push_back(driver); } fdriver.close(); for(int i=0;i<buses.size();i++){ for(int j=0;j<3;j++){ buses[i].add_driver(&drivers[j]); } } cout<<"Enter the car number "; cin>>carnumber; for(int i=0;i<buses.size();i++){ if(carnumber==buses[i].get_number()){ buses[i].show_driver(); } } }
0098|червоний|Ikarus|1999|32.6|38|Івано-Франківськ-Львів| 4400|зелений|Hyundai|2020|16.3|56|Івано-Франківськ-Одеса| 8967|оранжевий|Daewoo|2017|12.3|24|Івано-Франківськ-Тернопіль| 7344|чорний|Mercedes-Benz|2001|36.5|84|Івано-Франківськ-Київ| 3434|білий|MAN|2003|23|40|Івано-Франківськ-Ужгород| 6834|рожевий|Volvo|2009|34.2|48|Івано-Франківськ-Харків| 4814|коричневий|Scania|2005|40.4|80|Івано-Франківськ-Чернігів| 7561|фіолетовий|VolgaBus|2013|40.1|76|Івано-Франківськ-Чернівці| 6522|синій|Ikarus|2007|11.5|20|Івано-Франківськ-Тернопіль| 9274|сірий|Mercedes-Benz|2017|46.4|54|Івано-Франківськ-Чернівці| 8887|чорний|Hyundai|2005|58.1|88|Івано-Франкцівськ-Луцьк| 5782|білий|Ikarus|2015|12.2|24|Івано-Франківськ-Дніпро| 3294|зелений|Daewoo|1995|66.3|54|Івано-Франківськ-Київ| 4323|червоний|Scania|1994|32.8|42|Івано-Фрнанківськ-Київ| 4314|фіолетовий|Ikarus|2000|16.2|30|Івано-Франківськ-Чернівці
Петренко Олексій|27|4.5|397530|D| Давиденко Денис|34|10.5|397531|D| Легін Олег|41|12.5|397532|D| Сегін Андрій|49|19.5|397533|D| Борбулевич Антон|29|5.5|397534|D| Винник Арсен|38|8.5|397535|B| Литвиненко Віктор|59|29.5|397536|B| Карпенко Андрій|45|25.5|397537|B| Глінський Борис|47|27.5|397538|B| Тарасенко Гліб|50|30.5|397539|B| Варварич Данило|58|35.5|397510|C| Шевчук Михайло|43|13.5|397511|C| Бойко Ярослав|33|13.5|397512|С| Якименко Віталій|56|16.5|397513|C| Гаврилюк Павло|39|19.5|397514|C

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue