Thread: please help to link the file.....

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    8

    please help to link the file.....

    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()&#37;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();
    }

  2. #2
    Student legit's Avatar
    Join Date
    Aug 2008
    Location
    UK -> Newcastle
    Posts
    156
    Please help link the files? I shall get my magic compiler wand out and use it to link these files without the compiler you use....

    Tell us what compiler you are using and we may be able to help.

  3. #3
    Registered User
    Join Date
    Aug 2008
    Posts
    8
    i use my <microsoft Visual c++ 6.0> to do this
    and i need to open in the <Microsoft Visual Studio.NET 2003> ... how to link this ??

  4. #4
    Student legit's Avatar
    Join Date
    Aug 2008
    Location
    UK -> Newcastle
    Posts
    156
    Why do you need to open it in Studio.NET? Can you not compile and run it in Visual C++?

    Is this homework by any chance?

  5. #5
    Registered User
    Join Date
    Aug 2008
    Posts
    8
    ya it can run in visual C++..
    but i dono how to open in Studio.net....
    can teach me ???

  6. #6
    Student legit's Avatar
    Join Date
    Aug 2008
    Location
    UK -> Newcastle
    Posts
    156
    But why do you need to open it in Studio.NET if it works fine with Visual C++? I'm not a .NET user so I can't help you there, but there's plenty of people on this board that may be able to help.

  7. #7
    Registered User
    Join Date
    Aug 2008
    Posts
    8
    then did u know that, how create the main menu to link this all together ??

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You might have to create a project, or something like that, and then add the .cpp files to the project. You might be able to find a tutorial about this or something on the internet or perhaps at Microsoft's website.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Create Project. Win32 Console Application. Application Settings > Empty Project.

    In Project, Add Existing Item, select all your files. Save All. Build.

    If it works, open the .dsp file in VC++ .Net. It will convert it to a .vcproj. Save All. Build. It should work.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM