Home ITT Tech Projects PSU Projects

 

My Programming Skills

// Michael Boros
// date 4-24-01
// CS162

// stage 1
/* This program will read in information for the user and will caclulate
   important data for managerial data.
 
    Input: The user will input A resource ID#, description, amount
    available, and job functions.

    Output: The out put will be the amount of resources available at any
    given time.
  
    I will be more descriptive in this header when I have made more
    progress with the program */

#include<fstream.h>
 
struct resource {  // resource structure
    int idNum;     // integer id number
    char type[50]; // type of resource
    int amount;    // amount availible
};

struct function {  // job function structure
    int idNum;     // integer id number
    char type[50]; //job description
};

// program functions
    void introHeader(); // introduction header
    void mainMenu();    // main menu
    void goBack();      // go back menu option
    int makeSelection(); // selection error checker
    void echo(int selection); // echo selection
    int errorChk(int selection); // menu error check
    int errorChkTwo(int selection); // menu error check
    int errorChkThree(int selection); // menu error check
    void inResource(int menuPick,char fileName[]); //reads in resouce data
    void jobFunc(int menuPick,char fileName[]); //reads in job functions
    void dispResource(int,int);  // displays resouce data to screen
    void dispJobFunction(int,int); // displays job function data
    char response(char answer);  // Y/N charater checker

// initialize structures
    function jobFunction[30] = {0,' '}; //
    resource employees[30] = {0,' ',0};
    resource employeeFile[30] = {0,' ',0};

// define in and out data type
    ifstream in;
    ifstream in2;
    ofstream out;


main()
{

// define and initalize program variables
    int firstMenuSelection = 0;
    int error = 0;
    int count = 0;
    int countTwo = 0;

// beginning of main program loop
do {
 
// program variables initalized and defined
    int selectionTwo = 0;
    int selectionThree = 0;
    int secondMenuSelection = 0;
    int thirdMenuSelection = 0;
    int fourthMenuSelection = 0;
    char answer[100];
    char resourceFile[20];
    char funcFile[20];

    do {

// main menu system
       do {
            introHeader();
            cout << endl; 

            mainMenu();
            cout << endl;

            firstMenuSelection = makeSelection();
            echo(firstMenuSelection);
            cin >> ws;
            cin.get(answer,100);
            cin.get();
           
           answer[0] = response(answer[0]);   
        }
        while ((answer[0] == 'N') || (answer[0] == 'n'));   
        error = errorChk(firstMenuSelection);

    }
    while (error == 202);

// second menu system
        if (firstMenuSelection == 1) {
            do {   
                do {
                    cout << endl;   
                    cout << "Enter 1 for Resources \n";
                    cout << "Enter 2 for Job Functions \n";
                    goBack(); 
                    cout << endl;
                    secondMenuSelection = makeSelection();
                    echo(secondMenuSelection);
                    cin >> ws;
                    cin.get(answer,100);
                    cin.get;
                    answer[0] = response(answer[0]);
                }
                while ((answer[0] == 'N') || (answer[0] == 'n'));
                error = errorChkTwo(secondMenuSelection);
            }
            while (error == 202);
        }

// third menu system
        if (firstMenuSelection == 2) {
            do {
                do {
                    cout << endl;
                    cout << "Enter 1 to Edit Project Input \n";
                    cout << "Enter 2 to Add a New Project \n";
                    goBack();
                    cout << endl;
                    thirdMenuSelection = makeSelection();
                    echo(thirdMenuSelection);
                    cin >> ws;
                    cin.get(answer,100);
                    cin.get();                 
                    answer[0] = response(answer[0]);
                }
                while ((answer[0] == 'N') || (answer[0] == 'n'));
                error = errorChkTwo(thirdMenuSelection);
            }
            while (error == 202);
        }

// fourth menu system
        if (firstMenuSelection == 3) {
            do {
                do {
                    cout <<endl;
                    cout << "Enter 1 to List Current Availible ";   
                    cout << "Resources \n";
                    cout << "Enter 2 to View When Resources Will Become ";
                    cout << "Availible \n";
                    cout << "Enter 3 to List Current Jobs In Progress \n";
                    cout << "Enter 4 to List a Jobs Status \n";
                    goBack();
                    cout << endl;
                    fourthMenuSelection = makeSelection();
                    echo(fourthMenuSelection);
                    cin >> ws;
                    cin.get(answer,100);
                    cin.get();
                    answer[0] = response(answer[0]);
                 }
                 while ((answer[0] == 'N') || (answer[0] == 'n'));
                 error = errorChkThree(fourthMenuSelection);
            }
            while (error == 202);
        }

// fith menu system
        if (secondMenuSelection == 1) {
            do {
                do {
                    do {
                        do {
                            error = 0;
                            answer[0] = 'n';
                            cout << endl;
                            cout << "Please enter the file name to read ";
                            cout << endl;
                            cout << "and write out the resources data \n";
                            cin >> ws;
                            cin.get(resourceFile,20);
                            cout << "You have entered " << resourceFile;
                            cout << endl;
                            cout << "Is this corret? Y/N \n";
                            cin >> ws;
                            cin.get(answer,10);
        
                            answer[0] = response(answer[0]);
                        }
                        while (error == 202);
                    }
                    while ((answer[0] == 'N') || (answer[0] == 'n'));

// open resource file and error check              
                    in.open(resourceFile);
                    if (!in) {
                        cout << endl;
                        cout << "Error in opening storage file! \n";
                    }

// sixth menu system
                    cout << endl;
                    cout << "Enter 1 to Add Resources \n";
                    cout << "Enter 2 to View All Resources \n";
                    goBack();
                    cout << endl;
                    selectionTwo = makeSelection();
                    echo(selectionTwo);
                    cin >> ws;
                    cin.get(answer,100);
                    cin.get();
                    answer[0] = response(answer[0]);
                 
                }
                while ((answer[0] == 'N') || (answer[0] == 'n'));
                error = errorChkTwo(selectionTwo);
            }
            while(error == 202);
        }
 

// seventh menu system
        if (secondMenuSelection == 2) {
            do {
                do {
                    do {
                        do {
                            error = 0;
                            answer[0] = 'n';
                            cout << endl;
                            cout << "Please enter the file name to read ";
                            cout << endl;
                            cout << "and write out the job function data";
                            cout << endl;
                            cin >> ws;
                            cin.get(funcFile,20);
                            cout << "You have entered " << funcFile;
                            cout << endl;
                            cout << "Is this correct? Y/N \n";
                            cin >> ws;
                            cin.get(answer,10);

                            answer[0] = response(answer[0]);
                        }
                        while (error == 202);
                    }
                    while ((answer[0] == 'N') || (answer[0] == 'n'));
 
// open job function file and error check
                    in2.open(funcFile);
                    if (!in2) {
                        cout << endl;
                        cout << "Error in opening storage file \n";
                    }

// eighth menu system
                    cout << endl;
                    cout << "Enter 1 to View all Job Functions \n";
                    cout << "Enter 2 to Add JobFunctions \n";
                    goBack();
                    cout << endl;
                    selectionThree = makeSelection();
                    echo(selectionThree);
                    cin >> ws;
                    cin.get(answer,100);
                    cin.get();
                    answer[0] = response(answer[0]);
                  }
                  while ((answer[0] == 'N') || (answer[0] == 'n'));
                  error = errorChkTwo(selectionThree);
             }
             while(error == 202); 
        }

// reads in resource data from external file
    int i = 0;
    while (!in.eof()) {
 
        in >> ws;
        in.ignore(5,'#');
        in >> employeeFile[i].idNum;
        in.ignore(30,';');
        in >> ws;
        in.get(employeeFile[i].type,40,';');
        in.ignore(30,';');
        in.ignore(30,';');
        in >> employeeFile[i].amount;
        in >> ws;

        count++;
        ++i;
    }

// reads in job function data from external file
    int k = 0;
    while (!in2.eof()) {

        in2 >> ws;
        in2.ignore(5,'#');
        in2 >> jobFunction[k].idNum;
        in2.ignore(30,';');
        in2 >> ws;
        in2.get(jobFunction[k].type,40,';');
        in2.ignore(30,';');
        in2 >> ws;

        countTwo++;
        ++k;

    }
// program function calls
    jobFunc(selectionThree,funcFile); // reads in job functions
    inResource(selectionTwo,resourceFile); // reads in resources
    dispJobFunction(selectionThree,countTwo); // displays jobs
    dispResource(selectionTwo,count); // displays resources

// closing open files
    in.close();
    in2.close();

} // end of main menu loop
while (firstMenuSelection != 0);

} // end of main

// function definitions

////////////////////////////////////////////////////////////////////////////

void dispResource(int selectionTwo,int count) {
    char answer[10];

    if (selectionTwo == 2) {
        answer[0] = 'y';
        do {
            cout << "          *****************<< Hi Tec Inc. >>";
            cout << "***************** \n";
            cout << "            ";
            cout << "Data Base of Company Resources \n";
            cout << endl;
            cout << "Employee ID#     Resource Type      Total Amount ";
            cout << "Available \n";             

            int k = 0;
            while (k <= count) {
                cout << employeeFile[k].idNum << "                  ";
                cout << employeeFile[k].type << "                  ";
                cout << employeeFile[k].amount << "         \n";
            
                ++k; 
            }
            cout << "Would you like to repeat this menu? Y/N \n";
            cin >> ws;
            cin.get(answer,100);            
            answer[0] = response(answer[0]);  
            cin.get();
        }
        while ((answer[0] == 'Y') || (answer[0] == 'y'));
    }
}

void dispJobFunction(int selectionThree,int count) {

    char answer[20];

    if (selectionThree == 1) {
        do {
            cout << "Data Base on Company Job Functions \n";
            cout << endl;
          
            int k = 0;
            while (k <= count) {
                cout << "ID# " << jobFunction[k].idNum << "   ";
                cout << jobFunction[k].type << endl;

                ++k;
            }
            cout << "Would you like to repeat this menu? Y/N \n";
            cin >> ws;
            cin.get(answer,100);
            answer[0] = response(answer[0]);
        }
        while ((answer[0] == 'Y') || (answer[0] == 'y'));
    }
}



void mainMenu() {
    cout << "Enter 1 for Data Base Entry \n";
    cout << "Enter 2 for Project Input Parameters \n";
    cout << "Enter 3 for Project Output Data \n";
    cout << "Enter 0 to Exit Program \n";
}

void introHeader() {
    cout << endl;
    cout << "          *****************<< Hi Tec Inc. >>";
    cout << "***************** \n";
    cout << endl;
    cout << endl;
    cout << "Please read the following Menu carefully and choose \n";
    cout << "from the following options \n";
    cout << endl;
    cout << endl;
}


void goBack() {
    cout << "Enter 0 For Main Menu \n";
}

int makeSelection() {
    int selection = 0;

    cout << "Please enter your selection \n";
    cin >> selection;
    return selection;
}

void echo(int selection) {
    cout << endl;
    cout << "You have entered " << selection << endl;
    cout << "Is this correct? Y/N \n";
    cout << endl;
}

int errorChk(int selection) {
    int i = 0;
    i = selection;
    if (((i != 1) && (i != 2)) && ((i != 3) && (i != 0))) {
        cout << endl;
        cout << "You have made an improper selection \n";
        cout << "Please try again \n";
        cout << endl;
        return 202;
    }
    else
        return 0;
}

int errorChkTwo(int selection) {
    int i = 0;
    i = selection;
    if (((i != 1) && (i != 2)) && (i != 0)) {
        cout << endl;
        cout << "You have made an improper selection \n";
        cout << "Please try again \n";  
        cout << endl;
        return 202;
    }
    else 
      return 0;
}   

int errorChkThree(int selection) {
    int i = 0;
    i = selection;
    if ((((i != 1) && (i != 2)) && ((i != 3) && (i != 0))) && (i != 4)) {
        cout << endl;
        cout << "You have made an improper selection \n";
        cout << "Please try again \n";
        cout << endl;
        return 202;
    }
    else
        return 0;
}

char response(char answer) {
    if ((answer == 'N') || (answer == 'n'))
        return 'n';
    else {
        if ((answer != 'Y') && (answer != 'y')) {
            answer = 'n';
            cout << "Error in response! \n";
            cout << "Please try again \n";
            cout << endl;
         }
   
    return answer;
    }
}

void inResource(int menuPick,char fileName[]) {

    char answer[100];
    int i = 0;
    int error = 0;

    ofstream out;
 
    if (menuPick == 1) {
 
        do {
            int i = 0;
            i++;
            cout << "Enter resource ID# \n";
            cin >> employees[i].idNum;
            cin.get();
            cout << "Enter resource type \n";
            cin.get(employees[i].type,20);
            cout << "Enter amount of resource availible \n";
            cin >> employees[i].amount;
           
            out.open(fileName, ios::app);

            out << endl;
            out << "ID# " << employees[i].idNum << "  ";
            out << "Resource type; " << employees[i].type << " ;  ";
            out << "Amount availible; " << employees[i].amount;
            out << endl;

            out.close();

        do {
            cout << "Would you like to continue? Y/N \n";
            cin >> ws;
            cin.get(answer,100);

            error = 0;
            answer[0] = response(answer[0]);
        }
        while (error == 202);
        }
        while ((answer[0] == 'Y') || (answer[0] == 'y'));
    }
}           
 
void jobFunc(int menuPick, char fileName[]) {

    char answer[100];
    int i = 0;
    int error = 0;

    ofstream out;

    if (menuPick == 2) {

        do {
            int i = 0;
            i++;
            cout << "Enter job function ID# \n";
            cin >> jobFunction[i].idNum;
            cin.get();
            cout << "Enter job description \n";
            cin.get(jobFunction[i].type,20);

            out.open(fileName, ios::app);

            out << endl;
            out << "ID# " << jobFunction[i].idNum << "  ";
            out << "Job description; " << jobFunction[i].type << " ;  ";
            out << endl;
    
            out.close();

                do {
                    cout << "Would you like to continue? Y/N \n";
                    cin >> ws;
                    cin.get(answer,100);

                    error = 0;
                }
                while (error ==202);
            }      
            while ((answer[0] == 'Y') || (answer[0] == 'y'));
        }
}

 Back to Top