HELP! bugged program

This is a discussion on HELP! bugged program within the C++ Programming forums, part of the General Programming Boards category; I been having problems debugging this program, can you give me some hints to solve it... i been getting a ...

  1. #1
    help-me
    Guest

    Post HELP! bugged program

    I been having problems debugging this program, can you give me some hints to solve it... i been getting a lot of errors, and the more i try to fix it, the more errors i get.

    here is the code.
    //----------------------------------------------------------------------------------



    //main driver

    #include <iostream.h>
    #include <fstream.h>
    #include <iomanip.h>
    //main driver

    #include <string.h>
    #include <conio.h>
    #include <process.h>

    #include "Employ2.h"
    #include "Boss1.h"
    #include "Commis1.h"
    #include "Piece1.h"
    #include "Hourly1.h"
    #include "workinfo.h"
    #include "workinfo.cpp"


    int menu();
    int n;

    int main()
    {

    int n=0;
    int choice;
    char answer;
    Worker w;

    do
    {
    choice = menu();

    //______________1st CHOICE__________________
    if (choice ==1)
    {
    do
    {
    w.SetEmpInfo(();
    w.TitleChoice();
    w.DisplayEmpInfo();
    w.DisplayTitleChoice();

    w.diskOut();

    cout<<endl;
    cout<<setw(17)<<" ""Do you want to enter another worker? (Y or N): ";
    cin >>answer;
    cout<<endl;
    }
    while (answer=='Y');
    }

    //_________________________________________
    // CHOICE 2

    if (choice==2)
    {
    do
    {
    int n= Worker::diskCount();
    for (int j=0; j<n; j++)
    {
    system("cls");
    w.diskIn(j);

    w.DisplayEmpInfo();
    w.DisplayTitleChoice();

    cout<<endl;
    cout<<setw(30)<<"See another worker? (Y or N): ";
    cin>>answer;
    }
    }
    while (answer=='Y');
    }

    //___________________________________________
    // CHOICE 3

    if (choice==3)
    {
    exit(0);
    }

    } while (choice !=3);
    cout<<endl;
    return menu();
    }

    //*********MENU ()

    int menu()
    {

    system("cls");
    system ("color 1c");

    int selection;



    cout<<"\n\n\n\n\n" <<setw(21)<<" "<<"MAIN MENU"
    <<"\n\n"
    <<setw(20)<<"_____________________________________ __________"<<"\n"
    <<"\n"<<setw(25)<<"1.- Add Information for a new worker\n"
    <<"\n"<<setw(25)<<"2.- Retrieve Information of a worker\n"
    <<"\n"<<setw(20)<<"3.- EXIT The Program\n\n"
    <<"\n"<<setw(20)<<"_______________________________ ________________"<<"\n\n"
    <<"\n"<<setw(20)<<"********* Enter your choice ****************\n"
    <<"\n"<<setw(20)<<" Choice: ";


    cin>>selection;

    return(selection);
    }

    //*************


    //----------------------------------------------------------------------------------
    // boss1.h
    // Boss class derived from Employee
    #ifndef BOSS1_H
    #define BOSS1_H
    #include "employ2.h"

    class Boss : public Employee {
    public:
    Boss( const char *, const char *, double = 0.0 );
    void setWeeklySalary( double );
    virtual double earnings() const;
    virtual void print() const;
    private:
    double weeklySalary;
    };

    #endif


    //-------------------------------------------------------------------------------
    // commis1.h
    // CommissionWorker class derived from Employee
    #ifndef COMMIS1_H
    #define COMMIS1_H
    #include "employ2.h"

    class CommissionWorker : public Employee
    {
    public:
    CommissionWorker( const char *, const char *,
    double = 0.0, double = 0.0,
    int = 0 );
    void setSalary( double );
    void setCommission( double );
    void setQuantity( int );
    virtual double earnings() const;
    virtual void print() const;
    private:
    double salary; // base salary per week
    double commission; // amount per item sold
    int quantity; // total items sold for week
    };

    #endif

    //----------------------------------------------------------------------------------
    // employ2.h
    // Abstract base class Employee
    #ifndef EMPLOY2_H
    #define EMPLOY2_H

    class Employee {
    public:
    Employee( const char *, const char * );
    ~Employee(); // destructor reclaims memory
    const char *getFirstName() const;
    const char *getLastName() const;

    // Pure virtual function makes Employee abstract base class
    virtual double earnings() const = 0; // pure virtual
    virtual void print() const; // virtual
    private:
    char *firstName;
    char *lastName;
    };

    #endif

    //-------------------------------------------------------------------------------
    // hourly1.h
    // Definition of class HourlyWorker
    #ifndef HOURLY1_H
    #define HOURLY1_H
    #include "employ2.h"

    class HourlyWorker : public Employee {
    public:
    HourlyWorker( const char *, const char *,
    double = 0.0, double = 0.0);
    void setWage( double );
    void setHours( double );
    virtual double earnings() const;
    virtual void print() const;
    private:
    double wage; // wage per hour
    double hours; // hours worked for week
    };

    #endif


    //-----------------------------------------------------------------------------// piece1.h
    // PieceWorker class derived from Employee
    #ifndef PIECE1_H
    #define PIECE1_H
    #include "employ2.h"

    class PieceWorker : public Employee {
    public:
    PieceWorker( const char *, const char *,
    double = 0.0, int = 0);
    void setWage( double );
    void setQuantity( int );
    virtual double earnings() const;
    virtual void print() const;
    private:
    double wagePerPiece; // wage for each piece output
    int quantity; // output for week
    };

    #endif


    //--------------------------------------------------------------------------------
    //workinfo.cpp
    // Member function definitions for class WorkInfo
    # include <iostream.h>
    # include <iomanip.h>
    # include <string.h>
    # include <conio.h>
    # include <process.h>
    # include <fstream.h>

    #include<iostream>

    using namespace std;
    #include<iomanip>
    using std::setw;

    # include "Employ2.h"
    # include "Boss1.h"
    # include "Commis1.h"
    # include "Piece1.h"
    # include "Hourly1.h"
    # include "workinfo.h"

    int tc ;

    void Worker: : set EmpInfo()
    {
    char x [2]
    system ("cls");

    cout << "\n";
    cout<<"\t Enter the employee's last name: ";
    cin>> lname;

    cout << "\n";
    cout<<"\t Enter the employee's first name: ";
    cin>> fname;

    cout << "\n";
    cout<<"\t Enter the employee's social security number: ";
    cin>> ssn;

    cout << "\n";
    cout<<"\t Enter the employee's date of birth (mm/dd/yyyy): ";
    cin>> dobirth;

    cout << "\n";
    cout<<"\t Enter the employee's address: ";
    cin.getline(x, 2);
    cin.getline(address, 30);


    cout << "\n";
    cout<<"\t Enter the state: ";
    cin>> state;

    cout << "\n";
    cout<<"\t Enter zip code: ";
    cin>> zip;

    cout << "\n";
    cout<<"\t Enter the employee's phone number (***)-***-****: ";
    cin>> phone;

    cout << "\n";
    cout<<"\t Enter the employee's date hire (mm/dd/yyyy): ";
    cin>> dohire;

    }

    void Worker:isplayEmpInfo()
    {
    system("cls");
    cout << setw(5) << " " << " ************************************************** *****************
    **" << end1 ;
    cout << setw (31) << " " << "WORKER INFORMATION" << endl;
    cout << setw(5) << " " << " ************************************************** *****************
    **" << end1;

    cout << "\n" << setw(14) << " " << "Last Name: " << 1name
    <<setw(20) << " " << " First Name: " << fname << endl ;

    cout << "\n" << setw(14) << " " << " Social Security Number: " << ssn
    << endl;

    cout << "\n" << setw(14) << " " << " Date of Birth: " << do birth
    << endl;

    cout << "\n" << setw(14) << " " << "City: " << city << endl;

    cout << "\n" << setw(14) << " " << "State: " << state
    << setw(28) << " " << " Zip Code: " << zip<< endl;

    cout <<"\n" << setw(140 << " " << "Phone Number: " << phone << endl;

    cout << "\n" <<setw(14) << " " << " Date of Hire: " << dohire;

    cout << "\n\n" <<setw(5) << " " << "************************************************* *********************";

    {


    void Worker: :TitleChoice()
    {

    system ("cls");


    cout << "\n\n\n\n" << endl;
    cout << setw(20) << " " << " ___________________________________________" << endl;
    cout << "\n" ;
    cout << setw(30) << " " << " Select WORKER'S TITLE " << endl;
    cout << setw(20) << " " << " ___________________________________________" << endl;

    cout << "\n" << setw(31) << " " << "1) Boss" << endl;
    cout << "\n" << setw(31) << " " << "2) Commision Worker" << endl;
    cout << "\n" << setw(31) << " " << "3) Piece Worker" << endl;
    cout << "\n" << setw(31) << " " << "4) Hourly Worker" << endl;
    cout << setw(20) << " " << " ___________________________________________" << endl;
    cout << "\n\n" << setw(30) << " " << "Place choose one: " ;
    cin >> tc;

    system ("cls") ;
    swith (tc)
    {

    case 1:
    {
    cout << "\n\n" << endl;
    cout << "\tBoss information: " << endl;
    cout << "\t*****************" << endl;
    cout << \n\t\tEnter weekly salary: $ " ;
    cin >> weeklySal ;
    cout << end1; << endl;

    }
    break;
    case 2:
    {
    cout << "\n\n" << end1;
    cout << "\tCommision Worker information: " << endl;
    cout << "\t************************************" << endl;
    cout << "\n\t\tEnter salary: $ ";

    cin >>salary;
    cout << "\n\t\tEnter commision: $ " ;
    cin >> commision;
    cout << "\n\t\tEnter quantity: ";
    cin >> quantity;

    }
    break;

    case 3:
    {

    cout << "\n\n" << endl;
    cout << "\tPiece Worker information: " << endl;
    cout << "\t******************************" << endl;
    cout << "\n\t\tEnter wage per piece: $ " ;
    cin >> wage;
    cout << "\n\t\tEnter number of pieces: " ;
    cin >> quantity;
    }
    break;

    case 4:
    {

    cout << "\"\n\n" << endl;
    cout << "\tHourly Worker information: " << endl;
    cout << "\t******************************" << endl;
    cout << "\n\t\tEnter wage per piece: $ " ;
    cin >> wage;
    cout << "\n\t\tEnter number of hours: ";
    cin >> hours;
    }
    break;

    }
    }

    void Worker: : DisplayTitleChoice()
    {
    cout << endl;
    swicth (tc)
    {


    case 1:
    {

    Boss b ( fname, lname, weeklySal );
    b. print () ;
    cout << " earned $" << b. earnings () ;
    cout << endl;
    }
    break;

    case 2:
    {

    commisionWorker c ( fname, iname, salary, commision, quantity ) ;
    c. print () ;
    cout << " earned $" << c.earnings () ;
    cout << endl;
    }
    break;

    case 3:
    {

    piceWorker p ( fname, iname, wage, quantity ) ;
    p. print () ;
    cout << " earned $ " << p. earnings () ;
    cout << endl;
    }
    break;

    case 4:
    {

    HourlyWorker h ( fname, iname, wage, hours ) ;
    h. print () ;
    cout << " earned $ " << h.earnings () ;
    cout << endl ;
    }
    break;
    }
    }


    void Worker::diskIn(int pn)
    {
    ifstream infile;
    //infile.open("Worker.DAT", ios::binary);
    infile.open(""C:\documents and Settings\czum7628\Desktop\moenia\Worker.TXT"");
    infile.seekg(pn*sizeof(Worker));
    infile.read((char*)this, sizeof(*this));
    }

    void Worker::diskOut()
    {
    ofstream outfile;

    // outfile.open ("WORKER.DAT, ios::app|ios::binary);
    outfile.open("C:\documents and Settings\czum7628\Desktop\moenia\Worker.TXT");
    outfile.write((char*)this, sizeof(*this));

    }

    void Worker::diskCount()
    {
    ifstream infile;
    //infile.open("WORKER.DAT, ios::app|ios::binary);
    infile.open(""C:\documents and Settings\czum7628\Desktop\moenia\Worker.TXT"");
    infile.seekg(0, ios::end);
    return (int) infile.tellg()/sizeof (Worker);
    }







    //----------------------------------------------------------------------------------
    #ifndef workinfo_h
    #define workinfo_h

    class workinfo
    {

    public:
    Worker(); // constructor

    void SetInfo();
    void DisplayInfo();
    void TitleChoice();
    void DisplayTitleChoice();
    void diskIn(int pn);
    void diskOut();
    void diskCount();

    private:

    char lname;
    char fname;
    int ssn;
    char address;
    int state;
    int zip;
    int phone;
    int dohire;
    double salary;
    double commision;
    int quantity;
    int hours;

    };
    #endif

    //------------------------------------------------------------------------------
    ERRORS:

    C:\Documents and Settings\czum7628\Desktop\moenia\workinfo.cpp(251) : error C2653: 'Worker' : is not a class or namespace name

    c:\documents and settings\czum7628\desktop\moenia\workinfo.cpp(25) : error C2239: unexpected token ':' following declaration of 'Worker'


    c:\documents and settings\czum7628\desktop\moenia\workinfo.cpp(79) : error C2059: syntax error : 'bad suffix on number'

    c:\documents and settings\czum7628\desktop\moenia\workinfo.cpp(90) : error C2872: 'cout' : ambiguous symbol

    c:\documents and settings\czum7628\desktop\moenia\workinfo.cpp(131) : error C2017: illegal escape sequence


    c:\documents and settings\czum7628\desktop\moenia\workinfo.cpp(252) : error C2601: 'diskCount' : local function definitions are illegal

    c:\documents and settings\czum7628\desktop\moenia\maindriver.cpp(39 ) : error C2143: syntax error : missing ';' before 'PCH creation point'



    I appreciate your help...

  2. #2
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    I agree with the starting from scratch. You have many fundamental flaws in your code. For example:

    # include <iostream.h>
    # include <iomanip.h>
    # include <string.h>
    # include <conio.h>
    # include <process.h>
    # include <fstream.h>

    #include<iostream>
    using namespace std;

    You need to start, from the ground up, and make better decisions. E.g. are you planning on using the standard headers (iostream, string, fstream) or the deprecated (iostream.h, string.h, fstream.h). You use BOTH, which is very dangerous. E.g.:

    iostream.h defines a variable called cout, in the global namespace (::cout). iostream defines a variable called cout in the std namespace (std::cout). Now, within the global namespace, you included the namespace std (which is itself usually bad form). Now you just have the mother of all name collisions, because you now have 2 definitions of cout that are in scope, 2 definitions of cin, 2 definitions of many, many things.

    Further, some parts of your code are just plain unnecesary, which strongly suggests that you should read more on namespaces, and the 1998 C++ standards. Some things you do are just plain bizarre, like:

    using namespace std;
    #include<iomanip>
    using std::setw;

    The first line brings every symbol from namespace std into the current namespace (in your case, the global namespace). The third line brings one symbol in. Now, it's not WRONG, per se, but it's completely useless; the top line by definition includes std::setw, because it includes std::*.

    It IS wrong that you *already* had a ::setw declared in the global namespace because you used deprecated headers, though. You should get a million "ambiguous reference" errors, because "cout" could mean std::cout or ::cout, "setw" could mean std::setw or ::setw, etc.
    Last edited by Cat; 06-08-2003 at 02:06 PM.

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Just to repeat what Salem said...

    Here's something I posted last week:
    Start small... Just write enough code so that it compiles. Add a little code at a time, test-compiling and test-running as you proceed. This way you will know right away where the problems are.

    It takes a bit of practice to learn how to sequence your program development so that it's testable as you go along. Usually, the user interface, or input/output is started first (but maybe not finalized) so you can see what your program is doing.

    Programming is difficult, and every programmer test-compiles and test-runs during development. Beginners should test-compile every line or two! More experienced programmers might only test-compile every "page" or so, depending on how familiar they are with the particular functions they are using, etc.
    And, please read the post above aboutcode tags that says "Posting Code? Read This First"
    Last edited by DougDbug; 06-09-2003 at 07:39 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21