Thread: c++ complete program

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    4

    Question c++ complete program

    hi all
    i hope all of you are fine

    i have a program to accomplesh and i was finished a part of it

    i just need simple help to complete it

    i have the following :
    Code:
     #define male 'm'
    #define female 'f'
    
    #include <iostream>
    #include <cstdlib>
    #include <ctime>
    #include <string>
    using namespace std;
    
    class person
    {
    public:
        person(int,char,string);
        person();
        int id();
        char sex();
        string name();
        int changename(string);
        static int reset_count();
    protected:
        int person_id;
        char person_sex;
        string person_name;
        static int count;
    };
    
    class student: public person
    {
    public:
        student (string,char);
        student (string,char,char);
        int number();
        char specialization();
    protected:
        int student_number;
        char student_specialization;
    };
    
    class employee: public person
    {
    public:
        employee (int,char);
        employee (string,char,char);
        int number ();
        char working ();
    protected:
        int employee_number;
        char employee_working;
    };
    
    int person::count;
    
    int person::reset_count() {
        person::count=0;
        return (person::count);
    }
    
    person::person(int a, char b, string c)
    {
        person_id=person::count;
        person::count++;
        person_sex=b;
        person_name=c;
    }
    
    person::person()
    {
        person_id=person::count;
        person::count++;
        char this_persons_sex;
        int random=rand()%2;
        if (random==0) this_persons_sex='m';
        else this_persons_sex='f';
        person_sex=this_persons_sex;
        person_name="";
    }
    
    
    int person::id()
    {
        return (person_id);
    }
    
    char person::sex()
    {
        return (person_sex);
    }
    
    string person::name()
    {
        return (person_name);
    }
    
    int person::changename(string a)
    {
        person_name=a;
        return 0;
    }
    
    
    student::student(string a, char b )
    {
        student_number=person_id;
        person_name=a;
        student_specialization=b;
    }
    
    student::student(string a, char b, char c )
    {
        person_name=a;
        student_number=person_id;
        student_specialization=b;
        person_sex=c;
    }
    
    int student::number()
    {
        return (student_number);
    }
    
    char student::specialization()
    {
        return (student_specialization);
    }
    
    employee::employee(int a, char b )
    {
        employee_number=a;
        employee_working=b;
    }
    
    employee::employee(string a, char b, char c )
    {
        person_name=a;
        employee_number=person_id;
        person_sex=b;
        employee_working=c;
    }
    
    int employee::number()
    {
        return (employee_number);
    }
    
    char employee::working()
    {
        return (employee_working);
    }
    
    int main()
    {
        person::reset_count();
        srand(time(NULL));
        employee ** emp;
        student ** stu;
        char tmpsex;
        string tmpname;
        string junk;
        char tmpspec;
        emp=new employee*[10];
        stu=new student*[10];
    
        cout<<"students:"<<endl;
        for (int i=0;i<10;i++)
        {
            cout<<"name: ";
            getline(cin,tmpname);
            cout<<"specialization: ";
            cin >> tmpspec;
            cout<<"sex: ";
            cin >> tmpsex;
            getline(cin,junk); // clear input buffer from junk cin leaves there
            stu[i]=new student(tmpname,tmpspec,tmpsex);
        }
        cout<<"employees:"<<endl;
        for (int i=0;i<10;i++)
        {
            cout<<"name: ";
            getline(cin,tmpname);
            cout<<"sex: ";
            cin>> tmpsex;
            cout << "Working?: ";
            cin >> tmpspec;
            getline(cin,junk);
            emp[i]=new employee(tmpname,tmpsex,tmpspec);
        }
        cout << "Student Data:\nid\tname\tsex\tspecialization\n";
        cout<<"-------------------------------------------------------------------------"<<endl;
        for (int i =0; i<10;++i)
        {
            cout<<stu[i]->id()<<"\t"<<stu[i]->name()<<"\t"<<stu[i]->sex()<<"\t"<<stu[i]->specialization()<<endl;
        }
        cout<<"-------------------------------------------------------------------------"<<endl;
        cout << "\nEmployee Data:\nid\tname\tsex\tworking\n";
        cout<<"-------------------------------------------------------------------------"<<endl;
        for (int i =0; i<10;++i)
        {
            cout<<emp[i]->id()<<"\t"<<emp[i]->name()<<"\t"<<emp[i]->sex()<<"\t"<<emp[i]->working()<<endl;
        }
        cout<<"-------------------------------------------------------------------------"<<endl;
        cout<<"\n\nPress <ENTER> to Exit. ";
        cin.get();
        return 0;
    }
    want to split it on files
    .h , .cpp , .cpp

    I tried to split it but it dosent wark with me

    please any one can help me and split it for me to being work ?

    It is important for me

    wating your help

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    http://faq.cprogramming.com/cgi-bin/...&id=1043284392

    My guess is you'll end up with
    person.h
    person.cpp
    student.h
    student.cpp
    employee.h
    employee.cpp
    main.cpp

    The 4 .cpp files need to be added to the "source code" section of your IDE project.

    Tell us which IDE, if you're stuck.

    Oh, and try to be more descriptive than "it didn't work".
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2008
    Posts
    4
    thank you very much salem

    i want to tell you about the steps of the program..

    the steps:-
    - The main class is named person , Two classes inheritant from the main class (Student ,Employee) .
    -The members of the main class are :Identifier Id ,name ,Sex .
    - The Member of the Student :student number , the Specialization of the student.
    - The member of the class employee : employee number ,the work he do.
    - Using the overload Function in output and input .
    - Using the writeload Function in the print Function.
    - Insert at lest 10 student and 10 employees .
    - Print the list of the employees as a table with all own data.
    - Print the list of the Students as a table with all own data.
    - The proportion of male to female in the employee.
    -After finish built a destructor function to destruct all the objects in the class

    I think .. I can write all the steps but the last steps I can not write it
    please help me in it
    -After finish built a destructor function to destruct all the objects in the class

    thank you very much

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675

  5. #5
    Registered User
    Join Date
    Dec 2008
    Posts
    4
    ok sir

    but can you help me??

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No. Go elsewhere. You seem to have asked on plenty of forums, so go elsewhere.
    I'm sure one of the other will "help" you.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Dec 2008
    Posts
    4
    ok.. thank you and good bye

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Bye.
    Come back when you've decided to stick to one forum.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  2. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  3. insufficient memory for tsr
    By manmohan in forum C Programming
    Replies: 8
    Last Post: 01-02-2004, 09:48 AM
  4. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 05:23 PM
  5. Replies: 3
    Last Post: 01-14-2003, 10:34 PM