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

Modify project #4 by using modular programming principle: Divide the main functi

ID: 3819790 • Letter: M

Question

Modify project #4 by using modular programming principle: Divide the main function written for the project #4 into nine functions which are explained below. The number of students (n) will be declared global. Also, use global constants for the size of arrays. The numeric arrays and non-numeric array must be passed through parameters/arguments. Note that arrays are passed by reference only. The main function will be placed first. Therefore, you will need to declare prototypes of functions. Use your own student’s data and names of arrays. The description of functions is given below:
Function main: It will include proper declarations. It will read the value of n (the number of students) from the key board and validate using a while loop (The value of n must be at least 3). It will call other functions as needed.
Function inputData: This function will read the data from the input file into proper arrays and then call ValidateData to validate.
Functions validateData: These will be two overloaded functions with same name. One function will validate non-numeric data and the other will validate numeric data.
Function NumGrade: This function will compute and store into proper array elements the numerical grades.
Function LetGrade: This function will compute and store into proper array elements the letter grades.
Function Comments: This function will determine and write commend/warning comments. Function Report: After all computations are completed. Arrays will contain all the information. Pass these arrays to this function which will write to the output file the reports of all students.

//This program is designed to calculate several students grades in different courses.
#include
#include
#include
#include

using namespace std;

int main()
{
//Define Arrays
string nonNumeric[3][9];
int numeric[3][2];
double numeric2[3][3][6];
char letterGrade[3][3];
int students;

//Define Floating point variables.
const double A_Score = 90;
const double B_Score = 80;
const double C_Score = 70;
const double D_Score = 60;

//open files.
ifstream file;
file.open("Project4_A04778903_input.txt");

if(!file)
{
cout << "Error in opening file: Project4_input.txt" << endl;
return -1;
}
ofstream fout;
fout.open("Project4_output.txt");

//get number of students
cout << "Enter the number of Students: ";
cin >> students;

//loop for student information
while(students >= 6 || students <= 0)
{
cout << "Incorrect range of students, please enter a number between 1 - 5" << endl;
cin >> students;
}
for(int j = 0; j < 3; j++)
{
nonNumeric[j][0] = "Students Grade Sheet, Department of Computer Science, Texas State Univeristy";
getline(file, nonNumeric[j][1]);
//checking whether the students name is within a reasonable range.
if(nonNumeric[j][1].length() > 256)
{
fout << "Student Name was too long, skipping to next student!" << endl;
continue;
}
file >> numeric[j][0];
//checking whether age is between 1 and 90
if(numeric[j][0] > 90 || numeric[j][0] < 1)
{
fout << "Age was not in the valid range" << endl;
break;
}
file.ignore();

getline(file, nonNumeric[j][2]);
//checking whether the students address is in reasonable range.
if(nonNumeric[j][2].length() > 256)
{
fout << "Student address was too long, skipping to next student!" << endl;
continue;
}

file >> numeric[j][1];
//checking whether number of years is between 1 and 90
if(numeric[j][1] > 90 || numeric[j][1] < 1)
{
fout << "Number of years at Texas state was not in the valid range" << endl;
break;
}
file.ignore();
getline(file, nonNumeric[j][3]);
if(nonNumeric[j][3].length() > 10)
{
fout << "Student ID was not in the valid range" << endl;
break;
}
getline(file, nonNumeric[j][4]);
//used 16 to allow different country telephone numbers
//checking whether the telephone number is within a reasonable range.
if(nonNumeric[j][4].length() > 16)
{
fout << "Student telephone number was too long, skipping to next student!" << endl;
continue;
}
getline(file, nonNumeric[j][5]);
//11 is the max social number.
//checking whether the social is within a reasonable range.
if(nonNumeric[j][5].length() > 11)
{
fout << "Student social was too long, skipping to next student!" << endl;
continue;
}

//loop for courses
for(int k = 0; k < 3; k++)
{
getline(file, nonNumeric[j][6+k]);
if(nonNumeric[j][6].length() > 11)
{
fout << "Course number was too long, skipping to next class!" << endl;
continue;
}
numeric2[j][k][5] = 0;
double percent = .1;
//loop fr tests
for(int l = 0; l < 5; l++)
{
file >> numeric2[2][k][l];
if(numeric2[j][k][l] < 1.00 || numeric2[j][k][l] > 100.00)
{
fout << "Test score was not in valid range" << endl;
break;
}
file.ignore();
//calculate grade
numeric2[j][k][5] = numeric2[j][k][5] + (numeric2[j][k][l] * percent);
percent += .05;

}
if(numeric2[j][k][5] >= A_Score)
{
letterGrade[j][k] = 'A';
}
else if(numeric2[j][k][5] >= B_Score)
{
letterGrade[j][k] = 'B';

}
else if(numeric2[j][k][5] >= C_Score)
{
letterGrade[j][k] = 'C';
}
else if(numeric2[j][k][5] >= D_Score)
{
letterGrade[j][k] = 'D';
}
else
{
letterGrade[j][k] = 'F';
}
}

}
for(int i = 0;i <3; i++)
{
fout << setw(32) << nonNumeric[i][0] << endl;
fout << setw(32) << "Name of Student:" << " " << nonNumeric[i][1] << endl;
fout << setw(32) << "Student ID:" << " " << nonNumeric[i][3] << endl;
fout << setw(32) << "Age:" << " " << numeric[i][0] << endl;
fout << setw(32) << "Address:" << " " << nonNumeric[i][2] << endl;
fout << setw(32) << "Number of years at Texas State:" << " " << numeric[i][1] << endl;
fout << setw(32) << "Telephone Number:" << " " << nonNumeric[i][4] << endl;
fout << setw(32) << "Student Social Security #:" << " " << nonNumeric[i][5] << endl << endl;
for(int k = 0; k < 3; k++)
{
fout << setw(32) << "Course#:" << " " << nonNumeric[i][6+k] << endl;
for(int j = 0; j < 5; j++)
{
fout << setw(30) << "Test#" << j + 1 << ":" << " " << numeric2[i][k][j] << endl;
}
fout << fixed << setpresicion(1) << setw(32) << "Numerical Grade:" << " " << numeric2[i][k][5] << endl;

fout < if(numeric2[i][k][5] >= A_Score)
{
fout << "Comment Note Congratulations! You have an A";
}
else if(numeric2[i][k][5] < D_Score)
{
fout << "Warning Note: You Should Study! You are below a 70 grade average!";
}
fout << endl << endl;


}
}
file.close();
fout.close();
return 0;
}

input file

Ben Hill
A04778903
601 University Dr, San Marcos, TX 78666
(281)-254-3294
262-39-1329
21
3
CS1319
90.1
92.3
86.4
87.6
94.1
CS1428
80.1
98.6
80.9
95.3
100.0
CS2308
37.0
52.3
45.4
57.5
52.5
Bennie   Benson
B01256310
601 University Dr, San Marcos, TX 78666
(281)-521-3439
321-39-4589
28
4
CS1319
87.8
88.4
79.8
95.5
67.3
CS1428
80.1
98.6
65.1
95.3
50.3
CS2308
34.2
52.3
45.4
60.2
67.8
Luis Harper
L45901739
601 University Dr, San Marcos, TX 78666
(713)-767-9803
431-50-7564
24
2
CS1319
87.8
97.8
88.4
67.7
78.2
CS1428
80.1
78.5
90.3
95.3
50.3
CS2308
56.7
78.5
45.3
55.7
92.3

Output file

Student Grade Sheet
Name of Student:   Ben Hill
StudentID:    A04778903
Address of the Student:    601 University Dr, San Marcos, TX 78666
Telephone Number:    (281)-254-3294
Student Soc.Security:    262-39-1329
Age of the Student:    21
Number if years at Texas State:    3
Course Number:    CS1319
Exam#1:    90.1
Exam#2:    92.3
Exam#3:    86.4
Exam#4:    87.6
Exam#5:    94.1
Numeric Grade:    89.95
Letter Grade:    B
Course Number:    CS1428
Exam#1:    80.1
Exam#2:    98.6
Exam#3:    80.9
Exam#4:    95.3
Exam#5:    100.0
Numeric Grade:    92.45
Letter Grade:    A
Course Number:    CS2308
Exam#1:    37.0
Exam#2:    52.3
Exam#3:    45.4
Exam#4:    57.5
Exam#5:    52.5
Letter Grade:    F
Warning Note:    Your grade is too low and needs improvements.

Student Grade Sheet
Name of Student:   Bennie   Benson
StudentID:    B01256310
Address of the Student:    601 University Dr, San Marcos, TX 78666
Telephone Number:    (281)-521-3439
Student Soc.Security:    321-39-4589
Age of the Student:    28
Number if years at Texas State:    4
Course Number:    CS1319
Exam#1:    87.8
Exam#2:    88.4
Exam#3:    79.8
Exam#4:    95.5
Exam#5:    67.3
Numeric Grade:    81.55
Letter Grade:    B
Course Number:    CS1428
Exam#1:    80.1
Exam#2:    98.6
Exam#3:    65.1
Exam#4:    95.3
Exam#5:    50.3
Numeric Grade:    74.45
Letter Grade:    C
Course Number:    CS2308
Exam#1:    34.2
Exam#2:    52.3
Exam#3:    45.4
Exam#4:    60.2
Exam#5:    67.8
Letter Grade:    F
Warning Note:    Your grade is too low and needs improvements.

Student Grade Sheet
Name of Student:   Luis Harper
StudentID:    L45901739
Address of the Student:    601 University Dr, San Marcos, TX 78666
Telephone Number:    (713)-767-9803
Student Soc.Security:    431-50-7564
Age of the Student:    24

Explanation / Answer

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

using namespace std;
//Define Arrays
string nonNumeric[3][9];
int numeric[3][2];
double numeric2[3][3][6];
char letterGrade[3][3];
int students;
//Define Floating point variables.
const double A_Score = 90;
const double B_Score = 80;
const double C_Score = 70;
const double D_Score = 60;
//open files.
ifstream file;
ofstream fout;
int inputData();
void outputData();
void validateData(string);
void validateData(int);
void letterGra(double);
void writetoFile();

void letterGra(double numeric2[3][3][6])
{
for(int j = 0; j < 3; j++)
{
//loop for courses
for(int k = 0; k < 3; k++)
{
getline(file, nonNumeric[j][6+k]);
if(nonNumeric[j][6].length() > 11)
{
fout << "Course number was too long, skipping to next class!" << endl;
continue;
}
numeric2[j][k][5] = 0;
double percent = .1;
//loop fr tests
for(int l = 0; l < 5; l++)
{
file >> numeric2[2][k][l];
if(numeric2[j][k][l] < 1.00 || numeric2[j][k][l] > 100.00)
{
fout << "Test score was not in valid range" << endl;
break;
}
file.ignore();
//calculate grade
numeric2[j][k][5] = numeric2[j][k][5] + (numeric2[j][k][l] * percent);
percent += .05;
}
if(numeric2[j][k][5] >= A_Score)
{
letterGrade[j][k] = 'A';
}
else if(numeric2[j][k][5] >= B_Score)
{
letterGrade[j][k] = 'B';
}
else if(numeric2[j][k][5] >= C_Score)
{
letterGrade[j][k] = 'C';
}
else if(numeric2[j][k][5] >= D_Score)
{
letterGrade[j][k] = 'D';
}
else
{
letterGrade[j][k] = 'F';
}
}
}
}

void validateData(string nonNumeric[3][9])
{
for(int j = 0; j < 3; j++)
{
nonNumeric[j][0] = "Students Grade Sheet, Department of Computer Science, Texas State Univeristy";
getline(file, nonNumeric[j][1]);
//checking whether the students name is within a reasonable range.
if(nonNumeric[j][1].length() > 256)
{
fout << "Student Name was too long, skipping to next student!" << endl;
continue;
}

getline(file, nonNumeric[j][2]);
//checking whether the students address is in reasonable range.
if(nonNumeric[j][2].length() > 256)
{
fout << "Student address was too long, skipping to next student!" << endl;
continue;
}

getline(file, nonNumeric[j][3]);
if(nonNumeric[j][3].length() > 10)
{
fout << "Student ID was not in the valid range" << endl;
break;
}
getline(file, nonNumeric[j][4]);
//used 16 to allow different country telephone numbers
//checking whether the telephone number is within a reasonable range.
if(nonNumeric[j][4].length() > 16)
{
fout << "Student telephone number was too long, skipping to next student!" << endl;
continue;
}
getline(file, nonNumeric[j][5]);
//11 is the max social number.
//checking whether the social is within a reasonable range.
if(nonNumeric[j][5].length() > 11)
{
fout << "Student social was too long, skipping to next student!" << endl;
continue;
}

}
}

void validateData(int numberic[3][2])
{

for(int j = 0; j < 3; j++)
{
file >> numeric[j][0];
//checking whether age is between 1 and 90
if(numeric[j][0] > 90 || numeric[j][0] < 1)
{
fout << "Age was not in the valid range" << endl;
break;
}

file >> numeric[j][1];
//checking whether number of years is between 1 and 90
if(numeric[j][1] > 90 || numeric[j][1] < 1)
{
fout << "Number of years at Texas state was not in the valid range" << endl;
break;
}

}
}

int inputData()
{

file.open("Project4_A04778903_input.txt");
if(!file)
{
cout << "Error in opening file: Project4_input.txt" << endl;
return -1;
}
return 0;
}

void outputData()
{
fout.open("Project4_output.txt");
}


void writetoFile()
{
for(int i = 0; i <3; i++)
{
fout << setw(32) << nonNumeric[i][0] << endl;
fout << setw(32) << "Name of Student:" << " " << nonNumeric[i][1] << endl;
fout << setw(32) << "Student ID:" << " " << nonNumeric[i][3] << endl;
fout << setw(32) << "Age:" << " " << numeric[i][0] << endl;
fout << setw(32) << "Address:" << " " << nonNumeric[i][2] << endl;
fout << setw(32) << "Number of years at Texas State:" << " " << numeric[i][1] << endl;
fout << setw(32) << "Telephone Number:" << " " << nonNumeric[i][4] << endl;
fout << setw(32) << "Student Social Security #:" << " " << nonNumeric[i][5] << endl << endl;
for(int k = 0; k < 3; k++)
{
fout << setw(32) << "Course#:" << " " << nonNumeric[i][6+k] << endl;
for(int j = 0; j < 5; j++)
{
fout << setw(30) << "Test#" << j + 1 << ":" << " " << numeric2[i][k][j] << endl;
}
fout << fixed << setw(32) << "Numerical Grade:" << " " << numeric2[i][k][5] << endl;
if(numeric2[i][k][5] >= A_Score)
{
fout << "Comment Note Congratulations! You have an A";
}
else if(numeric2[i][k][5] < D_Score)
{
fout << "Warning Note: You Should Study! You are below a 70 grade average!";
}
fout << endl << endl;

}
}
file.close();
fout.close();
}


int main()
{

//get number of students
cout << "Enter the number of Students: ";
cin >> students;
//loop for student information
while(students >= 6 || students <= 0)
{
cout << "Incorrect range of students, please enter a number between 1 - 5" << endl;
cin >> students;
}
inputData();
outputData();
validateData(nonNumeric);
validateData(numeric);
letterGra(numeric2);
writetoFile();
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote