Advertisement
AntoniiaG

Untitled

May 23rd, 2022
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.75 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<string.h>
  4. #include<fstream>
  5.  
  6. using namespace std;
  7.  
  8. class Company{
  9. private:
  10.     string comName, comType, registVAT;
  11.    
  12. public:
  13.     Company();
  14.     Company(string name, string type, string VAT){
  15.         comName = name;
  16.         comType = type;
  17.         registVAT = VAT;
  18.     }
  19.     void setCompanyName(string cName){
  20.         comName = cName;
  21.     }
  22.     string getCompanyName(){
  23.         return comName;
  24.     }
  25.     void setComapanyType(string cType){
  26.         comType = cType;
  27.     }
  28.     string getCompanyType(){
  29.         return comType;
  30.     }
  31.     void setRegisteredVAT(string regVAT){
  32.         registVAT = regVAT;
  33.     }
  34.     string getRegisteredVAT(){
  35.         return registVAT;
  36.     }
  37.     void showComData();
  38.     ~Company(){
  39.         cout<<"Destructing company's data\n";
  40.     }
  41.    
  42.     friend ostream& operator <<(ostream& os, const Company& com){
  43.         os <<"Name: "<<com.comName;
  44.         return os;
  45.     }
  46. };
  47.     Company::Company(){
  48.         cout<<"Creating a new company";
  49.     }
  50.     void Company::showComData(){
  51.         cout<<"All "<<comName<<"'s data:\n";
  52.         cout<<"Type of company: "<<comType<<"\n";
  53.         cout<<"Is company registered under VAT: "<<registVAT<<"\n\n";  
  54.     }
  55.    
  56.    
  57. class Dep{
  58. private:
  59.     string depName;
  60.     int years;
  61.     int num_workers;
  62.    
  63. public:
  64.     Dep();
  65.     Dep(string name, int numWorkers){
  66.         depName = name;
  67.         num_workers = numWorkers;
  68.     }
  69.    
  70.     void setdepName(string dName){
  71.         depName = dName;
  72.     }
  73.     string getdepName(){
  74.         return depName;
  75.     }
  76.     void setnumWorkers(int n_work){
  77.         num_workers = n_work;
  78.     }
  79.     int getnumWorkers(){
  80.         return num_workers;
  81.     }
  82.     void setdepYears(int depYears){
  83.         years = depYears;
  84.     }
  85.     int getdepYears(){
  86.         return (2022-years);
  87.     }
  88.     void showDepData();
  89.     ~Dep(){
  90.         cout<<"Destructing department's data\n";
  91.     }
  92. };
  93.     Dep::Dep(){
  94.         cout<<"Creating a department";
  95.     }
  96.     void Dep::showDepData(){
  97.         cout<<"Number of workers: "<<num_workers<<"\n\n";
  98.     }
  99.  
  100.  
  101. class Worker{
  102. private:
  103.     string firstName;
  104.     string lastName;
  105.     string egn;
  106.     int work_exp, projects_incl,  work_hours_contr;
  107.    
  108. public:
  109.     Worker();
  110.     Worker(string fName, string lName, string userEGN, int projects, int workExp, int workHours){
  111.         firstName = fName;
  112.         lastName = lName;
  113.         egn = userEGN;
  114.         work_exp = workExp;
  115.         projects_incl = projects;
  116.         work_hours_contr = workHours;
  117.     }
  118.    
  119.     void setFirstName(string fName){
  120.         firstName = fName;
  121.     }
  122.         void setLastName(string lName){
  123.         lastName = lName;
  124.     }
  125.    
  126.     string getName(){
  127.         return firstName+ " " + lastName;
  128.     }  
  129.    
  130.     void setEGN(string e){
  131.         egn = e;
  132.     }
  133.    
  134.     string getEGN(){
  135.         return egn;
  136.     }
  137.    
  138.     void setworkExp(int we){
  139.         work_exp = we;
  140.     }
  141.    
  142.     int getworkExp(){
  143.         return work_exp;
  144.     }
  145.    
  146.     void setworkHours(int work_h){
  147.         work_hours_contr = work_h;
  148.     }
  149.    
  150.     int getworkHour(){
  151.         return work_hours_contr;
  152.     }
  153.    
  154.     void setProjectsIncl(int pr){
  155.         projects_incl = pr;
  156.     }
  157.    
  158.     int getProjectsIncl(){
  159.         return projects_incl;
  160.     }
  161.    
  162.     void showWorkerData();
  163.     ~Worker(){
  164.         cout<<"Destructing worker's data\n";
  165.     }
  166.    
  167. };
  168.     Worker::Worker(){
  169.         cout<<"Creating a worker!\n";
  170.     }
  171.    
  172.     void Worker :: showWorkerData(){
  173.         cout<<"The worker's name is: "<<firstName+ " " + lastName;
  174.         cout<<"\nThe worker's EGN is: "<<egn;
  175.         cout<<"\nThe worker's work experience is: "<<work_exp<<" years\n";
  176.         cout<<"\nThe worker's working hours under contract are: "<<work_hours_contr<<" per week\n";
  177.         cout<<"\nThe number of projects worker is active in is: "<<projects_incl<<"\n\n";
  178.     }
  179.  
  180.  
  181. int main(){
  182.    
  183.     int choice = 0, num = 0, depYears, count = 0, pr, dep = 0, n_work = 0, we, counter = 0, companyCount = 0, depCount = 0, workCount = 0, work_h;
  184.     string fName, lName, e, dName, cName, cType, regVAT;
  185.     Worker wob[10][10];
  186.     Dep depo[10];
  187.     Company comOb;
  188.    
  189.     fstream new_file;      
  190.         new_file.open("new_company.txt", ios::out);
  191.                    
  192.         if(!new_file){
  193.             cout<<"File is not created.\n";
  194.         }
  195.         else{
  196.             cout<<"\nFile is created.\n";
  197.         }
  198.    
  199.     do{
  200.         cout<<"Please enter a number from 1 to 7 if you want some of the following:\n1 - Enter company's data.\n2 - Enter departments' data.\n3 - Enter workers' data.\n4 - Read company's data.\n5 - Read departments' data.\n6 - Read workers' data.\n7 - Read all data from file.\nIf you want to close the program please press 0.\n\n";
  201.        
  202.         cin>>choice;
  203.         if (choice < 0 || choice > 7){
  204.         if(count==2){
  205.                     cout<<"\nYou didn't entered correct number too many times.\nThe program will be closed. :)\n\n";
  206.                     new_file.close();
  207.                     return 0;
  208.                 }
  209.             cout<<"Please enter a number between 0 and 7.\n\n";
  210.             count++;
  211.                
  212.         }
  213.        
  214.         switch(choice){
  215.                        
  216.             case 1:{
  217.                    
  218.                     cout<<"Enter company's name:\n";
  219.                     cin>>cName;
  220.                     comOb.setCompanyName(cName);
  221.                     cout<<comOb;
  222.                     cout<<"\n";
  223.                     new_file << "Company:"<<endl<<"Name: "<< cName << endl;
  224.                     companyCount++;
  225.            
  226.            
  227.                     cout<<"Enter the type of company(ET/OOD/AD/EOOD):\n";
  228.                     cin>>cType;
  229.                     if(cType == "ET" ||cType == "OOD" ||cType == "AD" ||cType == "EOOD" ||cType == "et" ||cType == "ood" ||cType == "ad"||cType == "eood"){
  230.                         comOb.setComapanyType(cType);
  231.                         new_file << "Type: "<< cType << endl;
  232.                     }
  233.                     else{
  234.                         do{
  235.                             cout<<"Enter the type of company(ET/OOD/AD/EOOD):\n";
  236.                             cin>>cType;
  237.                         }while(cType !="ET"&&cType!="EOOD"&&cType!="OOD"&&cType!="AD"&&cType!="et"&&cType!="eood"&&cType!="ood"&&cType!="ad");
  238.                     }
  239.            
  240.  
  241.                     cout<<"Type 'YES' if company is registered with VAT. If it is not, type 'NO' instead:\n";
  242.                     cin>>regVAT;
  243.                     if(regVAT=="YES"||regVAT=="yes"||regVAT=="NO"||regVAT=="no"){
  244.                         cout<<"Company is registered under VAT.\n\n";
  245.                         comOb.setRegisteredVAT(regVAT);
  246.                         new_file << "Registered under VAT: "<< regVAT << endl << endl;
  247.                     }
  248.                     else{
  249.                         do{
  250.                             cout<<"Type 'YES' if company is registered with VAT. If it is not, type 'NO' instead:\n";
  251.                             cin>>regVAT;
  252.                         }while(regVAT!="YES"&&regVAT!="yes"&&regVAT!="NO"&&regVAT!="no");
  253.                     }
  254.                        
  255.                     break;
  256.                 }
  257.                
  258.                
  259.             case 2:{
  260.                
  261.                     cout<<"Enter the number of departments:\n(Note: Maximum departments could be 10.)\n";
  262.                     cin>>dep;
  263.                     if(dep <= 0){
  264.                         cout<<"No departments will be recorded in this company.\n\n\n";
  265.                         new_file << "Company has no departments." << endl;
  266.                         break;
  267.                     }
  268.                     if(dep<11 && dep>0){
  269.                         depCount = dep;
  270.                     }
  271.                     else{
  272.                         do{
  273.                             cout<<"Please enter a valid data next try.\n";
  274.                             cin>>dep;
  275.                         }while(dep>10 || dep<0);
  276.                     }
  277.                    
  278.                     if(dep<11 && dep>0){
  279.                        
  280.                         for(int i = 0; i < dep; i++){
  281.                            
  282.                         cout<<"Enter department' name:\n";
  283.                         cin>>dName;
  284.                         depo[i].setdepName(dName);
  285.                         new_file <<"Department: "<<endl<<"Name: "<< dName << endl;
  286.            
  287.            
  288.                         cout<<"Enter number of workers in that deparment\n(Note: You can input max 10 workers.):\n";
  289.                         cin>>n_work;
  290.                        
  291.                         if(n_work <= 0){
  292.                         cout<<"No workers will be recorded in this company.\n\n\n";
  293.                         new_file << "Company has no workers." << endl;
  294.                         break;
  295.                             }
  296.                         if(n_work<11 && n_work>0){
  297.                             depo[i].setnumWorkers(n_work);
  298.                             new_file <<"Number of workers: "<< n_work << endl; 
  299.                         }
  300.                         else{
  301.                             do{
  302.                                 cout<<"Please enter a valid data next try.\n";
  303.                                 cin>>n_work;
  304.                             }while(n_work>10 || n_work<0);
  305.                         }
  306.                        
  307.                         cout<<"Enter year of establishment:\n";
  308.                         cin>>depYears;
  309.                         depo[i].setdepYears(depYears); 
  310.                         new_file << "Period since establishment: "<< depo[i].getdepYears() <<" years."<< endl << endl;
  311.                             }
  312.                            
  313.                             break;
  314.                         }
  315.                     }
  316.                    
  317.             case 3: {
  318.                
  319.                         if(dep<=0){
  320.                         cout<<"There will not be recorded any workers.\n\n";
  321.                         new_file << "There are not any workers." << endl;
  322.                         break;
  323.                         }
  324.                        
  325.                        
  326.                     for(int k = 0; k < dep; k++){
  327.                         counter = depo[k].getnumWorkers();
  328.                         workCount = counter;
  329.                         cout<<"Number of workers in "<<depo[k].getdepName()<<" department are: "<<counter<<"\n\nPlease enter needed data:\n";
  330.                         new_file << "Workers in "<<depo[k].getdepName()<<" department: " << endl;
  331.                         for(int i = 0; i < counter; i++){
  332.                
  333.                
  334.                         cout<<"Enter worker #"<<i+1<<"'s first name: \n";
  335.                         cin>>fName;
  336.                         cout<<"Enter worker #"<<i+1<<"'s second name: \n";
  337.                         cin>>lName;
  338.                         wob[k][i].setFirstName(fName);
  339.                         wob[k][i].setLastName(lName);
  340.                         new_file << "Worker #"<<i+1<<" :" << endl << "First name: "<<fName << endl;
  341.                         new_file << "Last name: "<<lName << endl;
  342.                            
  343.                            
  344.                         cout<<"Enter worker #"<<i+1<<"'s EGN: \n";
  345.                         cin>>e;
  346.                         wob[k][i].setEGN(e);
  347.                         new_file << "EGN: "<< e << endl;
  348.                    
  349.                            
  350.                         cout<<"Enter worker #"<<i+1<<"'s work experience(years): \n";
  351.                         cin>>we;
  352.                         wob[k][i].setworkExp(we);
  353.                         new_file << "Work experience: "<< we << endl;
  354.                    
  355.                            
  356.                         cout<<"Enter worker #"<<i+1<<"'s work hours per week by contract: \n";
  357.                         cin>>work_h;
  358.                         wob[k][i].setworkHours(work_h);
  359.                         new_file << "Working hours per week: "<< work_h << endl;
  360.                            
  361.                            
  362.                         cout<<"Enter worker #"<<i+1<<"'s active projects: \n";
  363.                         cin>>pr;
  364.                         wob[k][i].setProjectsIncl(pr);
  365.                         new_file << "Active projects: "<< pr << endl << endl;
  366.                            
  367.                             }
  368.                         }
  369.                             break; 
  370.                     }
  371.                    
  372.             case 4:{
  373.                         if(companyCount == 0){
  374.                             cout<<"There is no such data!\n\n";
  375.                             break;
  376.                                 }
  377.                             else{
  378.                                 comOb.showComData();
  379.                             }
  380.                         break;
  381.                     }
  382.            
  383.             case 5: {
  384.                         if(depCount == 0){
  385.                                 cout<<"There is no such data!\n\n";
  386.                             break;
  387.                                 }
  388.                                 else{
  389.                                     for(int i = 0; i < dep; i++){
  390.                                         cout<<"All "<<depo[i].getdepName()<<" department data is:\n";
  391.                                         cout<<"It is "<<depo[i].getdepYears()<<" years old.\n";
  392.                                         depo[i].showDepData();
  393.                                     }
  394.                                 }
  395.                         break;
  396.                     }
  397.                    
  398.             case 6: {
  399.                         if(workCount == 0){
  400.                                 cout<<"There is no such data!\n\n";
  401.                             break;
  402.                                 }
  403.                                 else{
  404.                                     int counter6 = 0;
  405.                                     for(int k = 0; k < dep; k++){
  406.                                     counter6 = depo[k].getnumWorkers();
  407.                                     cout<<"Number of workers in "<<depo[k].getdepName()<<" department are: "<<counter6<<"\n";
  408.                                     cout<<k+1<<" WORKER: \n";
  409.                                     for(int i = 0; i < counter6; i++){ 
  410.                                         wob[k][i].showWorkerData();
  411.                                         }
  412.                                     }
  413.                                 }
  414.                         break;
  415.                     }
  416.            
  417.             case 7:{
  418.                            
  419.                             if(new_file.is_open()){
  420.                                 new_file.close();
  421.                                 cout<<"File is closed for writing.\n";
  422.                             }
  423.                            
  424.                             cout<<"All data from company's file:\n\n";
  425.                             new_file.open("new_company.txt",  ios::in);
  426.                    
  427.                             if(!new_file){
  428.                                 cout<<"File is not created corectly.\n";
  429.                             }
  430.                            
  431.                             else{
  432.            
  433.                                 string line;
  434.                                 while(std::getline(new_file, line)){
  435.                                     std::cout <<line<<std::endl;
  436.                                     }
  437.                                 }
  438.                            
  439.                             new_file.close();
  440.                     break;
  441.                     }
  442.         }
  443.        
  444.     }
  445.     while(choice != 0);
  446.  
  447. }
  448.  
  449.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement