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

c++ program for . Your program needs to allow an advisor to register students fo

ID: 3832303 • Letter: C

Question

c++ program for . Your program needs to allow an advisor to register students for classes and then provide the student with a class schedule and cost breakdown. The advisor should be able to continue to register students until they are done.

Your application should prompt the advisor to enter the student’s full name, major, age, state of residency and if they are a new or returning student. After gathering this information from the student the advisor can then register the student for classes up to a maximum of 15 credit hours. The student may register for less credit hours if they prefer but cannot exceed the 15 credit hour maximum.

The cost is $214.00 per credit hour for out-of-state students and $186.00 per credit hour for in-state students. If this is a new student, there is also a $50.00 application fee added to their registration cost. If this student is 65 years old or older, they only play $25.00 per class that they enroll in and there is no application fee if they are a new student. If the course enrolled in requires a lab, add a $75.00 fee for that course.

The majors a student may choose from are:

                                General Studies (GS)

                                Computer Science (CS)

                                Engineering (EN)

                                Nursing (NU)

The courses a student may enroll in are:

Course ID

Course

Credit Hours

Lab Required

001

Math

4

No

002

English

3

Yes

003

Reading

3

No

004

Computer Applications

3

No

005

CAD

4

No

006

Biology

4

Yes

007

Sociology

3

No

008

Speech

3

No

Your program does not need to display the above major and course information on the screen because the advisor will have a sheet with this information on it in front of them.

Your program should perform data validation such as making sure a valid Major or Course is entered and any other validation that should be performed. Remember to make the program user-friendly but also “idiot” proof.

The output should provide the student with their name, major and student status(new or returning). The output should also list the courses that the student has registered for including the course ID, name and credit hours. Following their schedule should be a breakdown of their costs such application fee, credit hour costs and lab fees.

Program Requirements:

Proper code structure

Easy to read layout

Programmer-friendly comments

Correct variable definitions

User-friendly input and output statements

At least two array variables

Any numbers with decimal places should be formatted to 2 decimal places

Correct use of while or for loops, if or switch conditions and calculations

Use at least two functions

Course ID

Course

Credit Hours

Lab Required

001

Math

4

No

002

English

3

Yes

003

Reading

3

No

004

Computer Applications

3

No

005

CAD

4

No

006

Biology

4

Yes

007

Sociology

3

No

008

Speech

3

No

Explanation / Answer

#include "stdafx.h"

#include <iostream>

#include <string>

#include <fstream>

#include <iomanip>

#include <cmath>

using namespace std;

struct StudentData

{

    int studentID;

    string first_name;

    string last_name;

    int ex1;

    int ex2;

    int ex3;

    int total;

    char ch;

};

const int SIZE = 9;

const int INFO = 4;

// Function prototypes

void openInputFile(ifstream &, string);

void getTotal(StudentData[]);

void getGrade(StudentData[]);

void calcLowest(StudentData[], int &, int &, int &, int &, int[]);

void calcHighest(StudentData[], int &, int &, int &, int &, int[]);

void getAverage(StudentData[], int, double &, double &, double &, double &, double[]);

void getStd(StudentData[], double &, double &, double &, double &, double &, double &, double &, double &, double[]);

void print(StudentData[], int[], int[], double[], double[]);

void sort(StudentData[]);

int main()

{

    // Variables

    StudentData arr[SIZE];

    int lowest1, lowest2, lowest3, lowest4; // Stores lowest ex scores

    int highest1, highest2, highest3, highest4; // Holds highest ex scores

    double average1 = 0, average2 = 0, average3 = 0, average4 = 0; // Represents average of each ex

    double std1 = 0, std2 = 0, std3 = 0, std4 = 0; // Holds standard deviation for Exs 1-3 and Total

    int lowest[INFO] = {};

    int highest[INFO] = {};

    double average[INFO] = {};

    double standardDeviation[INFO] = {};

    ifstream inFile;

    string inFileName = "C:\Users\Lisa\Desktop\scores.txt";

    // Call function to read data in file

    openInputFile(inFile, inFileName);

    // Read data into an array of structs

    for(int count = 0; count < SIZE; count++)

    {

        inFile >> arr[count].studentID >> arr[count].first_name >> arr[count].last_name >> arr[count].ex1 >> arr[count].ex2 >> arr[count].ex3;

    }

    // Close input file

    inFile.close();

    // Get score total for each student

    getTotal(arr);

    // Determine grade for each student

    getGrade(arr);

    // Calculate lowest scores in each ex and total scores

    calcLowest(arr, lowest1, lowest2, lowest3, lowest4, lowest);

    // Calculate highest scores in each ex and total scores

    calcHighest(arr, highest1, highest2, highest3, highest4, highest);

    // Calculate average of each ex and the average of the total scores

    getAverage(arr, SIZE, average1, average2, average3, average4, average);

    // Calculate standard deviation of each category

    getStd(arr, std1, std2, std3, std4, average1, average2, average3, average4, standardDeviation);

    cout << " ";

    // Print unsorted data

    print(arr, lowest, highest, average, standardDeviation);

    cout << " ";

    // Sort data

    sort(arr);

    // Print sorted data

    print(arr, lowest, highest, average, standardDeviation);

    system("PAUSE");

    return 0;

}

/**

* Pre-condition:

* Post-condition:

*/

void openInputFile(ifstream &inFile, string inFileName)

{

    //Open the file

    inFile.open(inFileName);

    //Input validation

    if (!inFile)

    {

        cout << "Error to open file." << endl;

        cout << endl;

        return;

    }

}

/**

* Pre-condition:

* Post-condition:

*/

void getTotal(StudentData arr[])

{

    for(int i = 0; i < SIZE; i++)

    {

        arr[i].total = arr[i].ex1 + arr[i].ex2 + arr[i].ex3;

    }

}

/**

* Pre-condition:

* Post-condition:

*/

void getGrade(StudentData arr[])

{

    for(int i = 0; i < SIZE; i++)

    {

        if(arr[i].total >= 270)

            arr[i].ch = 'A';

        else if(arr[i].total >= 240)

            arr[i].ch = 'B';

        else if(arr[i].total >= 210)

            arr[i].ch = 'C';

        else if(arr[i].total >= 180)

            arr[i].ch = 'D';

        else

            arr[i].ch = 'F';

    }

}

/**

* Pre-condition:

* Post-condition:

*/

void calcLowest(StudentData arr[], int &lowest1, int &lowest2, int &lowest3, int &lowest4, int lowest[])

{

    int smallest = 0;

    lowest1 = arr[0].ex1;

    lowest2 = arr[0].ex2;

    lowest3 = arr[0].ex3;

    lowest4 = arr[0].total;

    // Loop to determine lowest score from Ex1, 2, 3, and Total

    for (int i = 0; i < SIZE; i++)

    {

        if (lowest1 > arr[i].ex1)

        {

            lowest1 = arr[i].ex1;

            smallest = i;

        }

        if (lowest2 > arr[i].ex2)

        {

            lowest2 = arr[i].ex2;

            smallest = i;

        }

        if (lowest3 > arr[i].ex3)

        {

            lowest3 = arr[i].ex3;

            smallest = i;

        }

        if (lowest4 > arr[i].total)

        {

            lowest4 = arr[i].total;

            smallest = i;

        }

    }

    // Loop lowest values into an array of size 4

    for(int index = 0; index < INFO; index++)

    {

        if(index == 0)

            lowest[0] = lowest1;

        else if(index == 1)

            lowest[1] = lowest2;

        else if(index == 2)

            lowest[2] = lowest3;

        else if(index == 3)

          lowest[3] = lowest4;

        else

            cout << "Fail!" << endl;

    }

}

/**

* Pre-condition:

* Post-condition:

*/

void calcHighest(StudentData arr[], int &highest1, int &highest2, int &highest3, int &highest4, int highest[])

{

    int biggest = 0;

    highest1 = arr[0].ex1;

    highest2 = arr[0].ex2;

    highest3 = arr[0].ex3;

    highest4 = arr[0].total;

    // Loop to determine highest score from Ex1, 2, 3, and Total

    for (int i = 0; i < SIZE; i++)

    {

       if (highest1 < arr[i].ex1)

        {

            highest1 = arr[i].ex1;

            biggest = i;

        }

        if (highest2 < arr[i].ex2)

        {

            highest2 = arr[i].ex2;

            biggest = i;

        }

        if (highest3 < arr[i].ex3)

        {

            highest3 = arr[i].ex3;

            biggest = i;

        }

        if (highest4 < arr[i].total)

        {

            highest4 = arr[i].total;

            biggest = i;

        }

    }

    // Loop highest values into an array of size 4

    for(int index = 0; index < INFO; index++)

    {

        if(index == 0)

            highest[0] = highest1;

        else if(index == 1)

            highest[1] = highest2;

        else if(index == 2)

            highest[2] = highest3;

        else if(index == 3)

            highest[3] = highest4;

        else

            cout << "Fail!" << endl;

    }

}

/**

* Pre-condition:

* Post-condition:

*/

void getAverage(StudentData arr[], int size, double &average1, double &average2, double &average3, double &average4, double average[])

{

    int sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;

    // Get sum of each category (Ex1, 2, 3, and Total)

    for(int i = 0; i < SIZE; i++)

    {

        sum1 += arr[i].ex1;

        sum2 += arr[i].ex2;

        sum3 += arr[i].ex3;

        sum4 += arr[i].total;

    }

    // Calculate average for each category

    average1 += static_cast<double>(sum1)/size;

    average2 += static_cast<double>(sum2)/size;

    average3 += static_cast<double>(sum3)/size;

    average4 += static_cast<double>(sum4)/size;

    // Loop average values into an array of size 4

    for(int index = 0; index < INFO; index++)

    {

        if(index == 0)

            average[0] = average1;

        else if(index == 1)

            average[1] = average2;

        else if(index == 2)

            average[2] = average3;

        else if(index == 3)

            average[3] = average4;

        else

            cout << "Fail!" << endl;

    }

}

/**

* Pre-condition:

* Post-condition:

*/

void getStd(StudentData arr[], double &std1, double &std2, double &std3, double &std4, double &average1, double &average2, double &average3, double &average4, double standardDeviation[])

{

    double deviationSum1 = 0, deviationSum2 = 0, deviationSum3 = 0, deviationSum4 = 0;

    for(int i = 0; i < SIZE; i++)

    {

        deviationSum1 += pow((arr[i].ex1 - average1), 2);

        deviationSum2 += pow((arr[i].ex2 - average2), 2);

        deviationSum3 += pow((arr[i].ex3 - average3), 2);

        deviationSum4 += pow((arr[i].total - average4), 2);

    }

    std1 = sqrt(deviationSum1 / ((SIZE) - 1));

    std2 = sqrt(deviationSum2 / ((SIZE) - 1));

    std3 = sqrt(deviationSum3 / ((SIZE) - 1));

    std4 = sqrt(deviationSum4 / ((SIZE) - 1));

    // Loop average values into an array of size

    for(int index = 0; index < INFO; index++)

    {

        if(index == 0)

            standardDeviation[0] = std1;

        else if(index == 1)

            standardDeviation[1] = std2;

        else if(index == 2)

            standardDeviation[2] = std3;

        else if(index == 3)

            standardDeviation[3] = std4;

        else

            cout << "Fail!" << endl;

    }

}

    cout << " ";

}

/**

* Pre-condition:

* Post-condition:

*/

void sort(StudentData arr[])

{

    StudentData temp;

    for (int i = 0; i < (SIZE - 1); i++)

    {

        for (int j = i + 1; j < SIZE; j++)

        {

            if (arr[i].last_name > arr[j].last_name)

            {

                temp = arr[i];   

                arr[i] = arr[j];

                arr[j] = temp;

            }

        }

    }

}

#include "stdafx.h"

#include <iostream>

#include <string>

#include <fstream>

#include <iomanip>

#include <cmath>

using namespace std;

struct StudentData

{

    int studentID;

    string first_name;

    string last_name;

    int ex1;

    int ex2;

    int ex3;

    int total;

    char ch;

};

const int SIZE = 9;

const int INFO = 4;

// Function prototypes

void openInputFile(ifstream &, string);

void getTotal(StudentData[]);

void getGrade(StudentData[]);

void calcLowest(StudentData[], int &, int &, int &, int &, int[]);

void calcHighest(StudentData[], int &, int &, int &, int &, int[]);

void getAverage(StudentData[], int, double &, double &, double &, double &, double[]);

void getStd(StudentData[], double &, double &, double &, double &, double &, double &, double &, double &, double[]);

void print(StudentData[], int[], int[], double[], double[]);

void sort(StudentData[]);

int main()

{

    // Variables

    StudentData arr[SIZE];

    int lowest1, lowest2, lowest3, lowest4; // Stores lowest ex scores

    int highest1, highest2, highest3, highest4; // Holds highest ex scores

    double average1 = 0, average2 = 0, average3 = 0, average4 = 0; // Represents average of each ex

    double std1 = 0, std2 = 0, std3 = 0, std4 = 0; // Holds standard deviation for Exs 1-3 and Total

    int lowest[INFO] = {};

    int highest[INFO] = {};

    double average[INFO] = {};

    double standardDeviation[INFO] = {};

    ifstream inFile;

    string inFileName = "C:\Users\Lisa\Desktop\scores.txt";

    // Call function to read data in file

    openInputFile(inFile, inFileName);

    // Read data into an array of structs

    for(int count = 0; count < SIZE; count++)

    {

        inFile >> arr[count].studentID >> arr[count].first_name >> arr[count].last_name >> arr[count].ex1 >> arr[count].ex2 >> arr[count].ex3;

    }

    // Close input file

    inFile.close();

    // Get score total for each student

    getTotal(arr);

    // Determine grade for each student

    getGrade(arr);

    // Calculate lowest scores in each ex and total scores

    calcLowest(arr, lowest1, lowest2, lowest3, lowest4, lowest);

    // Calculate highest scores in each ex and total scores

    calcHighest(arr, highest1, highest2, highest3, highest4, highest);

    // Calculate average of each ex and the average of the total scores

    getAverage(arr, SIZE, average1, average2, average3, average4, average);

    // Calculate standard deviation of each category

    getStd(arr, std1, std2, std3, std4, average1, average2, average3, average4, standardDeviation);

    cout << " ";

    // Print unsorted data

    print(arr, lowest, highest, average, standardDeviation);

    cout << " ";

    // Sort data

    sort(arr);

    // Print sorted data

    print(arr, lowest, highest, average, standardDeviation);

    system("PAUSE");

    return 0;

}

/**

* Pre-condition:

* Post-condition:

*/

void openInputFile(ifstream &inFile, string inFileName)

{

    //Open the file

    inFile.open(inFileName);

    //Input validation

    if (!inFile)

    {

        cout << "Error to open file." << endl;

        cout << endl;

        return;

    }

}

/**

* Pre-condition:

* Post-condition:

*/

void getTotal(StudentData arr[])

{

    for(int i = 0; i < SIZE; i++)

    {

        arr[i].total = arr[i].ex1 + arr[i].ex2 + arr[i].ex3;

    }

}

/**

* Pre-condition:

* Post-condition:

*/

void getGrade(StudentData arr[])

{

    for(int i = 0; i < SIZE; i++)

    {

        if(arr[i].total >= 270)

            arr[i].ch = 'A';

        else if(arr[i].total >= 240)

            arr[i].ch = 'B';

        else if(arr[i].total >= 210)

            arr[i].ch = 'C';

        else if(arr[i].total >= 180)

            arr[i].ch = 'D';

        else

            arr[i].ch = 'F';

    }

}

/**

* Pre-condition:

* Post-condition:

*/

void calcLowest(StudentData arr[], int &lowest1, int &lowest2, int &lowest3, int &lowest4, int lowest[])

{

    int smallest = 0;

    lowest1 = arr[0].ex1;

    lowest2 = arr[0].ex2;

    lowest3 = arr[0].ex3;

    lowest4 = arr[0].total;

    // Loop to determine lowest score from Ex1, 2, 3, and Total

    for (int i = 0; i < SIZE; i++)

    {

        if (lowest1 > arr[i].ex1)

        {

            lowest1 = arr[i].ex1;

            smallest = i;

        }

        if (lowest2 > arr[i].ex2)

        {

            lowest2 = arr[i].ex2;

            smallest = i;

        }

        if (lowest3 > arr[i].ex3)

        {

            lowest3 = arr[i].ex3;

            smallest = i;

        }

        if (lowest4 > arr[i].total)

        {

            lowest4 = arr[i].total;

            smallest = i;

        }

    }

    // Loop lowest values into an array of size 4

    for(int index = 0; index < INFO; index++)

    {

        if(index == 0)

            lowest[0] = lowest1;

        else if(index == 1)

            lowest[1] = lowest2;

        else if(index == 2)

            lowest[2] = lowest3;

        else if(index == 3)

          lowest[3] = lowest4;

        else

            cout << "Fail!" << endl;

    }

}

/**

* Pre-condition:

* Post-condition:

*/

void calcHighest(StudentData arr[], int &highest1, int &highest2, int &highest3, int &highest4, int highest[])

{

    int biggest = 0;

    highest1 = arr[0].ex1;

    highest2 = arr[0].ex2;

    highest3 = arr[0].ex3;

    highest4 = arr[0].total;

    // Loop to determine highest score from Ex1, 2, 3, and Total

    for (int i = 0; i < SIZE; i++)

    {

       if (highest1 < arr[i].ex1)

        {

            highest1 = arr[i].ex1;

            biggest = i;

        }

        if (highest2 < arr[i].ex2)

        {

            highest2 = arr[i].ex2;

            biggest = i;

        }

        if (highest3 < arr[i].ex3)

        {

            highest3 = arr[i].ex3;

            biggest = i;

        }

        if (highest4 < arr[i].total)

        {

            highest4 = arr[i].total;

            biggest = i;

        }

    }

    // Loop highest values into an array of size 4

    for(int index = 0; index < INFO; index++)

    {

        if(index == 0)

            highest[0] = highest1;

        else if(index == 1)

            highest[1] = highest2;

        else if(index == 2)

            highest[2] = highest3;

        else if(index == 3)

            highest[3] = highest4;

        else

            cout << "Fail!" << endl;

    }

}

/**

* Pre-condition:

* Post-condition:

*/

void getAverage(StudentData arr[], int size, double &average1, double &average2, double &average3, double &average4, double average[])

{

    int sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;

    // Get sum of each category (Ex1, 2, 3, and Total)

    for(int i = 0; i < SIZE; i++)

    {

        sum1 += arr[i].ex1;

        sum2 += arr[i].ex2;

        sum3 += arr[i].ex3;

        sum4 += arr[i].total;

    }

    // Calculate average for each category

    average1 += static_cast<double>(sum1)/size;

    average2 += static_cast<double>(sum2)/size;

    average3 += static_cast<double>(sum3)/size;

    average4 += static_cast<double>(sum4)/size;

    // Loop average values into an array of size 4

    for(int index = 0; index < INFO; index++)

    {

        if(index == 0)

            average[0] = average1;

        else if(index == 1)

            average[1] = average2;

        else if(index == 2)

            average[2] = average3;

        else if(index == 3)

            average[3] = average4;

        else

            cout << "Fail!" << endl;

    }

}

/**

* Pre-condition:

* Post-condition:

*/

void getStd(StudentData arr[], double &std1, double &std2, double &std3, double &std4, double &average1, double &average2, double &average3, double &average4, double standardDeviation[])

{

    double deviationSum1 = 0, deviationSum2 = 0, deviationSum3 = 0, deviationSum4 = 0;

    for(int i = 0; i < SIZE; i++)

    {

        deviationSum1 += pow((arr[i].ex1 - average1), 2);

        deviationSum2 += pow((arr[i].ex2 - average2), 2);

        deviationSum3 += pow((arr[i].ex3 - average3), 2);

        deviationSum4 += pow((arr[i].total - average4), 2);

    }

    std1 = sqrt(deviationSum1 / ((SIZE) - 1));

    std2 = sqrt(deviationSum2 / ((SIZE) - 1));

    std3 = sqrt(deviationSum3 / ((SIZE) - 1));

    std4 = sqrt(deviationSum4 / ((SIZE) - 1));

    // Loop average values into an array of size

    for(int index = 0; index < INFO; index++)

    {

        if(index == 0)

            standardDeviation[0] = std1;

        else if(index == 1)

            standardDeviation[1] = std2;

        else if(index == 2)

            standardDeviation[2] = std3;

        else if(index == 3)

            standardDeviation[3] = std4;

        else

            cout << "Fail!" << endl;

    }

}

    cout << " ";

}

/**

* Pre-condition:

* Post-condition:

*/

void sort(StudentData arr[])

{

    StudentData temp;

    for (int i = 0; i < (SIZE - 1); i++)

    {

        for (int j = i + 1; j < SIZE; j++)

        {

            if (arr[i].last_name > arr[j].last_name)

            {

                temp = arr[i];   

                arr[i] = arr[j];

                arr[j] = temp;

            }

        }

    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote