Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

· Create two and three-dimensional arrays to store all input and output data and

ID: 3739201 • Letter: #

Question

  

·       Create two and three-dimensional arrays to store all input and output data and fill these arrays by the data read from the input file and by the computed data. The data of all employees will be stored in these arrays before writing it to the output file.

·       As you know, all elements of an array must be of same type. Therefore, you will be creating different arrays to store different types of data. For an example you could have the following array declarations:

o   A two-dimensional array NonNumeric of type string to store headings, Employee name, and supervisor’s name. Employee ID, Employee Telephone, Employee Address, warning/appreciation letter, and Note for n employees. For three employees it may look like NonNumeric1 [3] [8]

o   A three-dimensional array Numeric1 of type double to store three years and three semesters input data read from the input file for n employees. For three employees it may look like Numeric1 [3] [3] [3]

o   A two-dimensional array Numeric2 of type double to store Final Weighted Evaluation, 2013, Final Weighted Evaluation, 2014, Final Weighted Evaluation, 2015, Total Final Weighted Evaluation, Average Final Weighted Evaluation, Current Salary, Salary Raise in %, Salary Raise in Dollars, Salary in dollars with the raise. For three employees it may look like Numeric2 [3] [9].

·       At the end when all the input and output data has been stored in arrays, you will generate all reports and write them to the output file.

·       Of course, you will need nested loops in the program.

·       You must use named constants to declare the sizes of arrays.

·       In addition to input validation, you should also validate if the file opened correctly.

·       In your loops, you should also check that arrays do not get out of bound.

INPUT

                           Name of the Employee:                                             Nancy Price

                          Name of the Supervisor:                                              John Albert

                                       Employee ID #:                                       A-5971-359182

                                 Telephone Number:                                     (512) 354 – 9855

                                                  Address:      510 Albatross Dr., Austin, TX 78310           

          Spring Semester Evaluation, 2013:                                                       80.00

       Summer Semester Evaluation, 2013:                                                       75.00

              Fall Semester Evaluation, 2013:                                                       90.00

          Spring Semester Evaluation, 2014:                                                       83.00

       Summer Semester Evaluation, 2014:                                                       78.00

              Fall Semester Evaluation, 2014:                                                       93.00

          Spring Semester Evaluation, 2015:                                                       86.00

       Summer Semester Evaluation, 2015:                                                       79.00

              Fall Semester Evaluation, 2015:                                                       95.00

Current Salary:                       $90,000.00

NOTE: Information in Red color is for information only. It should not be read.   

OUTPUT

Texas State University, San Marcos

Annual Employee Evaluation Report from January 1, 2013 to December 31, 2015

                           Name of the Employee:                                             Nancy Price

                        Name of the Supervisor:                                              John Albert

                                       Employee ID #:                                       A-5971-359182

                                 Telephone Number:                                        (512) 354-9855

                                                  Address:      510 Albatross Dr., Austin, TX 78310

          Spring Semester Evaluation, 2013:                                                       80.00

       Summer Semester Evaluation, 2013:                                                       75.00

              Fall Semester Evaluation, 2013:                                                       90.00

          Spring Semester Evaluation, 2014:                                                       83.00

       Summer Semester Evaluation, 2014:                                                       78.00

              Fall Semester Evaluation, 2014:                                                       93.00

          Spring Semester Evaluation, 2015:                                                       86.00

       Summer Semester Evaluation, 2015:                                                       79.00

              Fall Semester Evaluation, 2015:                                                       95.00

            Final Weighted Evaluation, 2013:                                      Computed Value

            Final Weighted Evaluation, 2014:                                      Computed Value

            Final Weighted Evaluation, 2015:                                      Computed Value           

           Total Final Weighted Evaluation:                                      Computed Value

       Average Final Weighted Evaluation:                                      Computed Value

                                        Current Salary:                                              $90,000.00

                                   Salary Raise in %:                                      Computed Value

                           Salary Raise in Dollars:                                      Computed Value

                Salary in dollars with the raise:                                      Computed Value

Warning/Appreciation Letter: Drafted by the student

Note: This report for Nancy Price was prepared according to the fair practice of the University.

           Any discrepancies must be reported by Nancy Price to her supervisor, John Albert.

                                                                       

Explanation / Answer

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

int main()
{

    const double FALL = 0.39,
            SPRING = 0.27,
            SUMMER = 0.24;

    int n;

    //input number of employees and validating.
    cout << " Enter number of employees you want to evaluate: ";
    cin >> n;

    string myStrings[n][7];
    double myScores[n][3][3];
    double compV[n][9];


    while (n < 1 || n > 100)
    {
        cout << "Invalid input: Enter a number between 1-100: ";
        cin >> n;
    }

    ifstream inFile;
    inFile.open("input.txt");

    ofstream outFile;
    outFile.open("output.txt");

    //validate if the file exists.
    if (!inFile)
    {
        cout << "File does not exist." << endl;
        return 0;
    }

    //get number of employees
    for (int emp = 0; emp < n; emp++)
    {

        for(int a = 0; a < 7; a++)
        {
            getline(inFile, myStrings[emp][a]);
            //outFile<< myStrings[emp][a] << " ";
        }
        outFile << " " << myStrings[0][0] << endl;
        outFile << " " << myStrings[0][1] << endl;
        outFile << endl;
        outFile << " Name of the Employee: " << myStrings[0][2] << endl;
        outFile << "Name of the Supervisor: " << myStrings[0][3] << endl;
        outFile << "        Employee's ID#: " << myStrings[0][4] << endl;
        outFile << "      Telephone number: " << myStrings[0][5] << endl;
        outFile << "               Address: " << myStrings[0][6] << endl;

        outFile << endl;

        for (int i = 0; i < 3; i++)
        {
            for(int j = 0 ; j < 3; j++)
            {
                inFile >> myScores[emp][i][j];

                switch(j)
                {
                    case 0:

                        outFile << fixed << showpoint << setprecision(2);
                        outFile << " Spring Semester Evaluation, " << 2013+i <<": " << myScores[emp][i][j]<< " ";
                        break;

                    case 1:
                        outFile << fixed << showpoint << setprecision(2);
                        outFile << " Summer Semester Evaluation, " << 2013+i <<": " << myScores[emp][i][j]<< " ";
                        break;

                    case 2:
                        outFile << fixed << showpoint << setprecision(2);
                        outFile << " Fall Semester Evaluation,   " << 2013+i <<": " << myScores[emp][i][j]<< " ";
                        break;
                }

            }
            outFile << endl;

        }

        compV[emp][0] = (myScores[emp][0][0]*FALL)+ (myScores[emp][0][1]*SUMMER) + (myScores[emp][0][2]*SPRING);
        compV[emp][1] = (myScores[emp][1][0]*FALL)+ (myScores[emp][1][1]*SUMMER) + (myScores[emp][1][2]*SPRING);
        compV[emp][2] = (myScores[emp][2][0]*FALL)+ (myScores[emp][2][1]*SUMMER) + (myScores[emp][2][2]*SPRING);

        compV[emp][3] = compV[emp][0]+ compV[emp][1]+ compV[emp][2];
        compV[emp][4] = compV[emp][3]/3;

        inFile >> myScores[emp][0][1];

        //display evaluation for each year, total, and average
        outFile << fixed << showpoint << setprecision(2);
        outFile << " Final Semester Evaluation, 2013: " << compV[emp][0] << endl;
        outFile << " Final Semester Evaluation, 2014: " << compV[emp][1] << endl;
        outFile << " Final Semester Evaluation, 2015: " << compV[emp][2] << endl;

        outFile << " Total Final Weighted Evaluation: " << compV[emp][3] << endl;
        outFile << " Average Final Weighted Evaluation: " << compV[emp][4]<< endl;

        //get input data
        outFile << " Current Salary : " << "$"<<myScores[emp][0][1]<< endl;

        if (compV[emp][4] < 75)
        {
            compV[emp][5] = 0;
            outFile << setw(31) << "Salary Raise in % : 0%" << " ";
            double raise$ = compV[emp][4] * 0.00;
            outFile << setw(31) << "Salary Raise in Dollars: "<< "$"<< raise$ << endl;
            double totalRaise = myScores[emp][0][1]+ raise$;
            outFile << "Salary in Dollars with the Raise: "<<"$"<< totalRaise<< endl;
        }
        else if (compV[emp][4] > 75 && compV[emp][4] <= 80)
        {
            compV[emp][5] = compV[emp][4] * 0.01;
            outFile << setw(31) << "Salary Raise in % :   1%"<< " ";
            double raise$ = compV[emp][4] * 0.01;
            outFile << setw(31) << "Salary Raise in Dollars: "<< "$"<< raise$ << endl;
            double totalRaise = myScores[emp][0][1]+ raise$;
            outFile << "Salary in Dollars with the Raise: "<<"$"<< totalRaise<< endl;

        }
        else if (compV[emp][4] > 80 && compV[emp][4] <= 90)
        {
            compV[emp][5] = compV[emp][4] * 0.03;
            outFile << setw(31) << "Salary Raise in % : 3%" << " ";
            double raise$ = compV[emp][4] * 0.3;
            outFile << setw(31) << "Salary Raise in Dollars: "<< "$"<< raise$ << endl;
            double totalRaise = myScores[emp][0][1]+ raise$;
            outFile << "Salary in Dollars with the Raise: "<<"$"<< totalRaise<< endl;
        }
        else if (compV[emp][4] > 90 && compV[emp][4] <= 100)
        {
            compV[emp][5] = compV[emp][4] * 0.05;
            outFile << setw(31) << "Salary Raise in % : 5%" <<" ";
            double raise$ = compV[emp][4] * 0.05;
            outFile << setw(31) << "Salary Raise in Dollars: "<< "$"<< raise$ << endl;
            double totalRaise = myScores[emp][0][1]+ raise$;
            outFile << "Salary in Dollars with the Raise: "<<"$"<< totalRaise<< endl;
        }
        else{
            compV[emp][5] = compV[emp][4] * 0.1;
            outFile << setw(31) << "Salary Raise in % : 10%" << endl;
            double raise$ = compV[emp][4] * 0.1;
            outFile << setw(31) << "Salary Raise in Dollars: "<< "$"<< raise$ << endl;
            double totalRaise = myScores[emp][0][1]+ raise$;
            outFile << "Salary in Dollars with the Raise: "<<"$"<< totalRaise<< endl;
        }

        if (compV[emp][4] < 70)
        {
            outFile << "Your Grade is : C" << endl;
        }
        else if(compV[emp][4] >= 90)
            outFile << "Your grade is : A" << endl;
        else
            outFile<< "Your grade is : B" << endl;


        outFile << endl;

        outFile << "Note:    This report for "<< myStrings[emp][2] << " was prepared according "
                << " to the fair practice "
                << " of the University." << endl;
        outFile << "         Any discrepancies must be reported by " << myStrings[emp][2] << " to her/his "
                << "supervisor, "<< myStrings[emp][3] << endl;

        outFile << endl;

        inFile.ignore();
    }
    inFile.close();
    outFile.close();
    return 0;
}