company.h
Code:#ifndef company #define company #include "employee" class company { private: employee *first; public: company(); bool is_empty(); //Checks to see if the list is empty void add_employee(); void list_all(); void update(); void report1(); void report2(); }; #endif [/QUOTE] company.cpp [QUOTE] #include <stdlib> #include <iostream> #include <cstring> #include "company" #include "employee" company::company() { first = NULL; } bool company::is_empty() { if (first == NULL) return true; else return false; } void company::add_employee() { employee *temp, *direct; if( is_empty() ) first = new employee; else { temp = new employee; direct = first; while( direct->get_link() != NULL) direct = direct->get_link(); direct->set_link(temp); } } void company::list_all() { employee *temp; if( !is_empty() ) { temp = first; do { temp->print_bio(); temp = temp->get_link(); }while(temp != NULL); } else cout<<endl<<"The list of employees is empty."<<endl; } void company::update() { employee *ptr; int number, choice; ptr = first; system("cls"); do { cout<<endl<<"Please enter the employee number: "; cin>>number; }while(number > ptr->get_total_num() ); while(ptr->get_employee_num() != number) ptr = ptr->get_link(); cout<<endl<<"The current employee profile is:"; ptr->print_bio(); cout<<endl<<"Please select the field that you would like to modify:"; cout<<endl<<"1. employee Name"; cout<<endl<<"2. employee Gender"; cout<<endl<<"3. employee Type"; cout<<endl<<"4. employee Date of Birth"; cout<<endl<<endl; cin>>choice; switch(choice) { case 1: ptr->set_name(); break; case 2: ptr->set_gender(); break; case 3: ptr->set_type(); break; case 4: ptr->set_dob(); break; default: cout<<endl<<"Sorry you have entered an invalid option."; break; } } void company::report1() { employee *temp1, *temp2, *temp3; temp1 = first; temp2 = first->get_link(); for(int x=0; x<22; x++) { while(temp2 != NULL) { if(strncmp(temp1->get_name(), temp2->get_name(), x) == 1) { if(temp1 == first) { temp3 = first; temp1->set_link( temp2->get_link() ); temp2->set_link(temp1); first = temp2; } else { while(temp3->get_link() != temp1) temp3 = temp3->get_link(); temp1->set_link( temp2->get_link() ); temp2->set_link(temp1); temp3->set_link(temp2); } } temp1 = temp2; temp2 = temp2->get_link(); } } temp1 = first; while(temp1 != NULL) { temp1->print_name(); temp1->print_type(); temp1->print_gender(); temp1 = temp1->get_link(); } } void company::report2() { int max, min, temp; employee *ctr; cout<<endl<<"Please enter the max age: "; cin>>max; cout<<endl<<"Please enter the min age: "; cin>>min; ctr = first; while(ctr != NULL) { temp = 2007 - (ctr->get_dob()%10000); if((min <= temp) && (max >= temp)) ctr->print_bio(); ctr = ctr->get_link(); } }
AND
employee.h
Code:#ifndef employee #define employee class employee { private: static int employee_no; //Will keep track of number of employee objects created char employee_name[21], employee_gender, *employee_type; int employee_year_of_birth, employee_num; employee *next_employee; public: employee(); void print_bio(); int get_total_num(); void print_total_num(); int get_employee_num(); void print_employee_num(); void set_name(); char * get_name(); void print_name(); void set_gender(); char get_gender(); void print_gender(); void set_type(); char * get_type(); void print_type(); void set_dob(); int get_dob(); void print_dob(); void set_link( employee *p ); employee * get_link(); }; #endif
employee.cpp
Code:#include <stdlib> #include <iostream> #include <cstring> #include "employee" int employee::employee_no = 0; employee::employee() { employee_no++; employee_num = employee_no; system("cls"); cout<<endl<<"Please enter all the necessary employee information."; set_name(); set_gender(); set_type(); set_dob(); system("cls"); cout<<endl<<"The employee information you have entered is as follows: "; print_bio(); next_employee = NULL; } int employee::get_total_num() { return employee_no; } void employee::print_total_num() { cout<<endl<<"The total number of employees is: "<<employee_no; } void employee::print_bio() { system("cls"); print_employee_num(); print_name(); print_gender(); print_type(); print_dob(); } int employee::get_employee_num() { return employee_num; } void employee::print_employee_num() { cout<<endl<<"The employee Number is: "<<get_employee_num(); } void employee::set_name() { char temp[25]; cout<<endl<<"Please enter the name of the employee: "; cin>>temp; //cin>>temp; strncpy(employee_name, temp, 20); } char * employee::get_name() { return employee_name; } void employee::print_name() { cout<<endl<<"The employee's name is: "<<employee_name; } void employee::set_gender() { int choice; do { cout<<endl<<"1. Male"; cout<<endl<<"2. Female"; cout<<endl<<"Please select the employee's gender: "; cin>>choice; }while(choice < 1 || choice > 2); if (choice == 1) employee_gender = 'm'; else employee_gender = 'f'; } char employee::get_gender() { return employee_gender; } void employee::print_gender() { cout<<endl<<"The employee's gender is "; if (employee_gender == 'm') cout<<"male."; else cout<<"female."; } void employee::set_type() { int choice; do { cout<<endl<<"1. In employee"; cout<<endl<<"2. Out employee"; cout<<endl<<"Please select the employee type: "; cin>>choice; }while(choice < 1 || choice > 2); if (choice == 1) employee_type = "in"; else employee_type = "out"; } char * employee::get_type() { return employee_type; } void employee::print_type() { cout<<endl<<"The type is: "; if (employee_type == "in") cout<<"In employee"; else cout<<"Out employee"; } void employee::set_dob() { int day, month, year; do { cout<<endl<<"Please enter the day of birth: "; cin>>day; }while(day > 31 || day < 1); do { cout<<endl<<"Please enter the month of birth: "; cin>>month; }while(month > 12 || month < 1); do { cout<<endl<<"Please enter the year of birth: "; cin>>year; }while(year > 2007 || year < 1950); employee_year_of_birth = (day * 1000000) + (month * 10000) + year; } int employee::get_dob() { return employee_year_of_birth; } void employee::print_dob() { cout<<endl<<"The employee's Date of Birth is: "; if (employee_year_of_birth < 10000000) cout<<"0"<<employee_year_of_birth<<endl; else cout<<employee_year_of_birth<<endl; } void employee::set_link(employee *p) { next_employee = p; } employee * employee::get_link() { return next_employee; }
run.CPP
Code:#include <iostream> #include "company" #include "employee" void main () { company test; test.add_employee(); test.list_all(); test.update(); test.report1(); test.report2(); }



LinkBack URL
About LinkBacks


