Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<iostream>
- #include<string.h>
- #include<fstream>
- using namespace std;
- class Company{
- private:
- string comName, comType, registVAT;
- public:
- Company();
- Company(string name, string type, string VAT){
- comName = name;
- comType = type;
- registVAT = VAT;
- }
- void setCompanyName(string cName){
- comName = cName;
- }
- string getCompanyName(){
- return comName;
- }
- void setComapanyType(string cType){
- comType = cType;
- }
- string getCompanyType(){
- return comType;
- }
- void setRegisteredVAT(string regVAT){
- registVAT = regVAT;
- }
- string getRegisteredVAT(){
- return registVAT;
- }
- void showComData();
- ~Company(){
- cout<<"Destructing company's data\n";
- }
- friend ostream& operator <<(ostream& os, const Company& com){
- os <<"Name: "<<com.comName;
- return os;
- }
- };
- Company::Company(){
- cout<<"Creating a new company";
- }
- void Company::showComData(){
- cout<<"All "<<comName<<"'s data:\n";
- cout<<"Type of company: "<<comType<<"\n";
- cout<<"Is company registered under VAT: "<<registVAT<<"\n\n";
- }
- class Dep{
- private:
- string depName;
- int years;
- int num_workers;
- public:
- Dep();
- Dep(string name, int numWorkers){
- depName = name;
- num_workers = numWorkers;
- }
- void setdepName(string dName){
- depName = dName;
- }
- string getdepName(){
- return depName;
- }
- void setnumWorkers(int n_work){
- num_workers = n_work;
- }
- int getnumWorkers(){
- return num_workers;
- }
- void setdepYears(int depYears){
- years = depYears;
- }
- int getdepYears(){
- return (2022-years);
- }
- void showDepData();
- ~Dep(){
- cout<<"Destructing department's data\n";
- }
- };
- Dep::Dep(){
- cout<<"Creating a department";
- }
- void Dep::showDepData(){
- cout<<"Number of workers: "<<num_workers<<"\n\n";
- }
- class Worker{
- private:
- string firstName;
- string lastName;
- string egn;
- int work_exp, projects_incl, work_hours_contr;
- public:
- Worker();
- Worker(string fName, string lName, string userEGN, int projects, int workExp, int workHours){
- firstName = fName;
- lastName = lName;
- egn = userEGN;
- work_exp = workExp;
- projects_incl = projects;
- work_hours_contr = workHours;
- }
- void setFirstName(string fName){
- firstName = fName;
- }
- void setLastName(string lName){
- lastName = lName;
- }
- string getName(){
- return firstName+ " " + lastName;
- }
- void setEGN(string e){
- egn = e;
- }
- string getEGN(){
- return egn;
- }
- void setworkExp(int we){
- work_exp = we;
- }
- int getworkExp(){
- return work_exp;
- }
- void setworkHours(int work_h){
- work_hours_contr = work_h;
- }
- int getworkHour(){
- return work_hours_contr;
- }
- void setProjectsIncl(int pr){
- projects_incl = pr;
- }
- int getProjectsIncl(){
- return projects_incl;
- }
- void showWorkerData();
- ~Worker(){
- cout<<"Destructing worker's data\n";
- }
- };
- Worker::Worker(){
- cout<<"Creating a worker!\n";
- }
- void Worker :: showWorkerData(){
- cout<<"The worker's name is: "<<firstName+ " " + lastName;
- cout<<"\nThe worker's EGN is: "<<egn;
- cout<<"\nThe worker's work experience is: "<<work_exp<<" years\n";
- cout<<"\nThe worker's working hours under contract are: "<<work_hours_contr<<" per week\n";
- cout<<"\nThe number of projects worker is active in is: "<<projects_incl<<"\n\n";
- }
- int main(){
- 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;
- string fName, lName, e, dName, cName, cType, regVAT;
- Worker wob[10][10];
- Dep depo[10];
- Company comOb;
- fstream new_file;
- new_file.open("new_company.txt", ios::out);
- if(!new_file){
- cout<<"File is not created.\n";
- }
- else{
- cout<<"\nFile is created.\n";
- }
- do{
- 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";
- cin>>choice;
- if (choice < 0 || choice > 7){
- if(count==2){
- cout<<"\nYou didn't entered correct number too many times.\nThe program will be closed. :)\n\n";
- new_file.close();
- return 0;
- }
- cout<<"Please enter a number between 0 and 7.\n\n";
- count++;
- }
- switch(choice){
- case 1:{
- cout<<"Enter company's name:\n";
- cin>>cName;
- comOb.setCompanyName(cName);
- cout<<comOb;
- cout<<"\n";
- new_file << "Company:"<<endl<<"Name: "<< cName << endl;
- companyCount++;
- cout<<"Enter the type of company(ET/OOD/AD/EOOD):\n";
- cin>>cType;
- if(cType == "ET" ||cType == "OOD" ||cType == "AD" ||cType == "EOOD" ||cType == "et" ||cType == "ood" ||cType == "ad"||cType == "eood"){
- comOb.setComapanyType(cType);
- new_file << "Type: "<< cType << endl;
- }
- else{
- do{
- cout<<"Enter the type of company(ET/OOD/AD/EOOD):\n";
- cin>>cType;
- }while(cType !="ET"&&cType!="EOOD"&&cType!="OOD"&&cType!="AD"&&cType!="et"&&cType!="eood"&&cType!="ood"&&cType!="ad");
- }
- cout<<"Type 'YES' if company is registered with VAT. If it is not, type 'NO' instead:\n";
- cin>>regVAT;
- if(regVAT=="YES"||regVAT=="yes"||regVAT=="NO"||regVAT=="no"){
- cout<<"Company is registered under VAT.\n\n";
- comOb.setRegisteredVAT(regVAT);
- new_file << "Registered under VAT: "<< regVAT << endl << endl;
- }
- else{
- do{
- cout<<"Type 'YES' if company is registered with VAT. If it is not, type 'NO' instead:\n";
- cin>>regVAT;
- }while(regVAT!="YES"&®VAT!="yes"&®VAT!="NO"&®VAT!="no");
- }
- break;
- }
- case 2:{
- cout<<"Enter the number of departments:\n(Note: Maximum departments could be 10.)\n";
- cin>>dep;
- if(dep <= 0){
- cout<<"No departments will be recorded in this company.\n\n\n";
- new_file << "Company has no departments." << endl;
- break;
- }
- if(dep<11 && dep>0){
- depCount = dep;
- }
- else{
- do{
- cout<<"Please enter a valid data next try.\n";
- cin>>dep;
- }while(dep>10 || dep<0);
- }
- if(dep<11 && dep>0){
- for(int i = 0; i < dep; i++){
- cout<<"Enter department' name:\n";
- cin>>dName;
- depo[i].setdepName(dName);
- new_file <<"Department: "<<endl<<"Name: "<< dName << endl;
- cout<<"Enter number of workers in that deparment\n(Note: You can input max 10 workers.):\n";
- cin>>n_work;
- if(n_work <= 0){
- cout<<"No workers will be recorded in this company.\n\n\n";
- new_file << "Company has no workers." << endl;
- break;
- }
- if(n_work<11 && n_work>0){
- depo[i].setnumWorkers(n_work);
- new_file <<"Number of workers: "<< n_work << endl;
- }
- else{
- do{
- cout<<"Please enter a valid data next try.\n";
- cin>>n_work;
- }while(n_work>10 || n_work<0);
- }
- cout<<"Enter year of establishment:\n";
- cin>>depYears;
- depo[i].setdepYears(depYears);
- new_file << "Period since establishment: "<< depo[i].getdepYears() <<" years."<< endl << endl;
- }
- break;
- }
- }
- case 3: {
- if(dep<=0){
- cout<<"There will not be recorded any workers.\n\n";
- new_file << "There are not any workers." << endl;
- break;
- }
- for(int k = 0; k < dep; k++){
- counter = depo[k].getnumWorkers();
- workCount = counter;
- cout<<"Number of workers in "<<depo[k].getdepName()<<" department are: "<<counter<<"\n\nPlease enter needed data:\n";
- new_file << "Workers in "<<depo[k].getdepName()<<" department: " << endl;
- for(int i = 0; i < counter; i++){
- cout<<"Enter worker #"<<i+1<<"'s first name: \n";
- cin>>fName;
- cout<<"Enter worker #"<<i+1<<"'s second name: \n";
- cin>>lName;
- wob[k][i].setFirstName(fName);
- wob[k][i].setLastName(lName);
- new_file << "Worker #"<<i+1<<" :" << endl << "First name: "<<fName << endl;
- new_file << "Last name: "<<lName << endl;
- cout<<"Enter worker #"<<i+1<<"'s EGN: \n";
- cin>>e;
- wob[k][i].setEGN(e);
- new_file << "EGN: "<< e << endl;
- cout<<"Enter worker #"<<i+1<<"'s work experience(years): \n";
- cin>>we;
- wob[k][i].setworkExp(we);
- new_file << "Work experience: "<< we << endl;
- cout<<"Enter worker #"<<i+1<<"'s work hours per week by contract: \n";
- cin>>work_h;
- wob[k][i].setworkHours(work_h);
- new_file << "Working hours per week: "<< work_h << endl;
- cout<<"Enter worker #"<<i+1<<"'s active projects: \n";
- cin>>pr;
- wob[k][i].setProjectsIncl(pr);
- new_file << "Active projects: "<< pr << endl << endl;
- }
- }
- break;
- }
- case 4:{
- if(companyCount == 0){
- cout<<"There is no such data!\n\n";
- break;
- }
- else{
- comOb.showComData();
- }
- break;
- }
- case 5: {
- if(depCount == 0){
- cout<<"There is no such data!\n\n";
- break;
- }
- else{
- for(int i = 0; i < dep; i++){
- cout<<"All "<<depo[i].getdepName()<<" department data is:\n";
- cout<<"It is "<<depo[i].getdepYears()<<" years old.\n";
- depo[i].showDepData();
- }
- }
- break;
- }
- case 6: {
- if(workCount == 0){
- cout<<"There is no such data!\n\n";
- break;
- }
- else{
- int counter6 = 0;
- for(int k = 0; k < dep; k++){
- counter6 = depo[k].getnumWorkers();
- cout<<"Number of workers in "<<depo[k].getdepName()<<" department are: "<<counter6<<"\n";
- cout<<k+1<<" WORKER: \n";
- for(int i = 0; i < counter6; i++){
- wob[k][i].showWorkerData();
- }
- }
- }
- break;
- }
- case 7:{
- if(new_file.is_open()){
- new_file.close();
- cout<<"File is closed for writing.\n";
- }
- cout<<"All data from company's file:\n\n";
- new_file.open("new_company.txt", ios::in);
- if(!new_file){
- cout<<"File is not created corectly.\n";
- }
- else{
- string line;
- while(std::getline(new_file, line)){
- std::cout <<line<<std::endl;
- }
- }
- new_file.close();
- break;
- }
- }
- }
- while(choice != 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement