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

I am working on a project that deals with functions and arrays. I got the main c

ID: 3821721 • Letter: I

Question

I am working on a project that deals with functions and arrays. I got the main code to run but my output file does not print out my test scores and some of my information. I feel that either my inputfile is not arranged right or maybe one of my arrays is wrong.

this is my Input file:

will Smith
A0235345
601 University Dr, San Marcos, TX 78666
(643)-366-346
342-34-3453
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
Stan Lee
A74850928
500 spring Dr, San Marcos, TX 78666
(210)-765-5686
765-35-2345
22
4
CS1319
97.1
87.3
78.4
89.6
89.7
CS1428
99.1
89.2
89.3
98.4
100.0
CS2308
100.0
98.9
78.6
78.6
98.5
John Mills
A08654678
609 Marcos Dr, San Marcos, TX 78666
(210)-264-7547
898-78-3422
18
1
CS1319
78.9
69.8
85.8
58.8
58.8
CS1428
56.9
99.9
87.7
97.7
89.9
CS2308
99.9
99.9
99.9
100.0
99.9

And this is my code:

#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("aa.txt");
if(!file)
{
cout << "Error in opening file: Project4_input.txt" << endl;
return -1;
}
return 0;
}
void outputData()
{
fout.open("bb.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][2]<<endl;
fout<<setw(32)<<"Age:"<<" "<<numeric[1][5]<<endl;
fout<<setw(32)<<"Address:"<<" "<<nonNumeric[i][3]<<endl;
fout<<setw(32)<<"Number of Years at TxState:"<<" "<<numeric[i][1]<<endl;
fout<<setw(32)<<"telephone:"<<" "<<nonNumeric[i][4]<<endl;
fout<<setw(32)<<"Student Soc. 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;
}

please help!!

Explanation / Answer

This is the complete solution.

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
//Define Arrays
string nonNumeric[6][9];
int numeric[6][2];
double numeric2[6][3][6];
char letterGrade[6][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[6][3][6], int j)
{
//loop for courses
for(int k = 0; k < 3; k++)
{
   file.ignore();
   getline(file, nonNumeric[j][6+k]);
   if(nonNumeric[j][6+k].length() > 11)
   {
       fout << "Course number was too long, skipping to next class!" << endl;
       continue;
   }
   //fout << nonNumeric[j][6+k]<<endl;
   numeric2[j][k][5] = 0;
   double percent = .1;
   //loop fr tests
   for(int l = 0; l < 5; l++)
   {
       file >> numeric2[j][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;
       }
       //fout << numeric2[j][k][l]<<endl;
       //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[6][9],int 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;
}
//fout << nonNumeric[j][1]<<endl;
getline(file, nonNumeric[j][2]);
//checking whether the students address is in reasonable range.
if(nonNumeric[j][2].length() > 10)
{
fout << "Student ID was not in the valid range" << endl;
}
//fout << nonNumeric[j][2]<<endl;
getline(file, nonNumeric[j][3]);
if(nonNumeric[j][3].length() > 256)
{
   fout << "Student address was too long, skipping to next student!" << endl;
}
//fout << nonNumeric[j][3]<<endl;
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;
}
//fout << nonNumeric[j][4]<<endl;
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;
}
//fout << nonNumeric[j][5]<<endl;
}

void validateData(int numeric[6][2],int 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 "<<numeric[j][0] << endl;
}
//fout << numeric[j][0]<<endl;
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;
}
//fout << numeric[j][1]<<endl;
}
int inputData()
{
file.open("aa.txt");
if(!file)
{
cout << "Error in opening file: Project4_input.txt" << endl;
return -1;
}
return 0;
}
void outputData()
{
fout.open("bb.txt");
}

void writetoFile()
{
for(int i = 0; i <students; 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][2]<<endl;
        fout<<setw(32)<<"Age:"<<" "<<numeric[i][0]<<endl;
        fout<<setw(32)<<"Address:"<<" "<<nonNumeric[i][3]<<endl;
        fout<<setw(32)<<"Number of Years at TxState:"<<" "<<numeric[i][1]<<endl;
        fout<<setw(32)<<"telephone:"<<" "<<nonNumeric[i][4]<<endl;
        fout<<setw(32)<<"Student Soc. 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();
for(int j=0;j<students;j++){
   //fout<<"j="<<j<<endl;
   if(j>0)
       file.ignore();
   validateData(nonNumeric,j);
   validateData(numeric,j);
   letterGra(numeric2, j);
}

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