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

I am working with a project that uses structures and arrays. My main code works

ID: 3826181 • Letter: I

Question

I am working with a project that uses structures and arrays. My main code works but does not print my courses or test data and i'm not sure were i messed up at.

this is my input:

Jill Smith
A8049558
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
Steve Left
A9845788
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
Matt Mills
A3548754
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

My Code

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

//defining structure with having arrays
struct StudentData {
//Define Arrays
string nonNumeric[6][9];
int numeric[6][2];
double numeric2[6][3][6];
char letterGrade[6][3];
} data;


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 fins.
ifstream fin;
ofstream fout;
int inputData();
void outputData();
void validateData(string);
void validateData(int);
void letGrade(StudentData Info);
void writetofin(StudentData Info);
void letGrade(StudentData Info,int j)
//loop for courses
{

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

//calculate grade
Info.numeric2[j][k][5] = Info.numeric2[j][k][5] + (Info.numeric2[j][k][l] * percent);
percent += .05;

}
if(Info.numeric2[j][k][5] >= A_Score)
{
Info.letterGrade[j][k] = 'A';
}
else if(Info.numeric2[j][k][5] >= B_Score)
{
Info.letterGrade[j][k] = 'B';
}
else if(Info.numeric2[j][k][5] >= C_Score)
{
Info.letterGrade[j][k] = 'C';
}
else if(Info.numeric2[j][k][5] >= D_Score)
{
Info.letterGrade[j][k] = 'D';
}
else
{
Info.letterGrade[j][k] = 'F';
}
}
}


void validateData(string nonNumeric[6][9],int j)
{
nonNumeric[j][0] = "Students Grade Sheet, Department of Computer Science, Texas State University";
getline(fin, 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" << endl;
}

getline(fin, 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(fin, nonNumeric[j][3]);
if(nonNumeric[j][3].length() > 256)
{
fout << "Student address was too long," << endl;
}
//fout << nonNumeric[j][3]<<endl;
getline(fin, 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" << endl;
}
//fout << nonNumeric[j][4]<<endl;
getline(fin, 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" << endl;
}

}

void validateData(int numeric[6][2],int j)
{
fin >> 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;
fin >> 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()
{
//reading from the input fin.
fin.open("input.txt");
if(!fin)
{
cout << "Error in opening fin: "input.txt" << endl;
return -1;
}
return 0;
}
void outputData()
{
fout.open("output.txt"); //Printing to the output fin
}

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

validateData(data.nonNumeric, j);
validateData(data.numeric, j);
letGrade(data, j);
}
writetofin(data);
return 0;
}

Explanation / Answer

#include <iostream>

#include <fstream>

#include <iomanip>

using namespace std;

struct StudentData {

string nonNumeric[6][9];

int numeric[6][2];

double numeric2[6][3][6];

char letterGrade[6][3];

} data;

int students;

const double A_Score = 90;

const double B_Score = 80;

const double C_Score = 70;

const double D_Score = 60;

ifstream fin;

ofstream fout;

int inputData();

void outputData();

void validateData(string);

void validateData(int);

void letGrade(StudentData Info);

void writetofin(StudentData Info);

void letGrade(StudentData Info,int j)

{

for(int k = 0; k < 3; k++)

{

fin.ignore();

getline(fin, Info.nonNumeric[j][6+k]);

if(Info.nonNumeric[j][6+k].length() > 11)

{

fout << "Course number was too long, skipping to next class!" << endl;

continue;

}

Info.numeric2[j][k][5] = 0;

double percent = .1;

for(int l = 0; l < 5; l++)

{

fin >> Info.numeric2[j][k][l];

if(Info.numeric2[j][k][l] < 1.00 || Info.numeric2[j][k][l] > 100.00)

{

fout << "Test score was not in valid range" << endl;

break;

}

Info.numeric2[j][k][5] = Info.numeric2[j][k][5] + (Info.numeric2[j][k][l] * percent);

percent += .05;

}

if(Info.numeric2[j][k][5] >= A_Score)

{

Info.letterGrade[j][k] = 'A';

}

else if(Info.numeric2[j][k][5] >= B_Score)

{

Info.letterGrade[j][k] = 'B';

}

else if(Info.numeric2[j][k][5] >= C_Score)

{

Info.letterGrade[j][k] = 'C';

}

else if(Info.numeric2[j][k][5] >= D_Score)

{

Info.letterGrade[j][k] = 'D';

}

else

{

Info.letterGrade[j][k] = 'F';

}

}

}

void validateData(string nonNumeric[6][9],int j)

{

nonNumeric[j][0] = "Students Grade Sheet, Department of Computer Science, Texas State University";

getline(fin, nonNumeric[j][1]);

if(nonNumeric[j][1].length() > 256)

{

fout << "Student Name was too long" << endl;

}

getline(fin, nonNumeric[j][2]);

if(nonNumeric[j][2].length() > 10)

{

fout << "Student ID was not in the valid range" << endl;

}

fout << nonNumeric[j][2]<<endl;

getline(fin, nonNumeric[j][3]);

if(nonNumeric[j][3].length() > 256)

{

fout << "Student address was too long," << endl;

}

getline(fin, nonNumeric[j][4]);

if(nonNumeric[j][4].length() > 16)

{

fout << "Student telephone number was too long" << endl;

}

getline(fin, nonNumeric[j][5]);

if(nonNumeric[j][5].length() > 11)

{

fout << "Student social was too long" << endl;

}

}

void validateData(int numeric[6][2],int j)

{

fin >> numeric[j][0];

if(numeric[j][0] > 90 || numeric[j][0] < 1)

{

fout << "Age was not in the valid range "<<numeric[j][0] << endl;

}

fin >> numeric[j][1];

if(numeric[j][1] > 90 || numeric[j][1] < 1)

{

fout << "Number of years at Texas state was not in the valid range" << endl;

}

}

int inputData()

{

fin.open("input.txt");

if(!fin)

{

cout << "Error in opening fin: "input.txt" << endl;

return -1;

}

return 0;

}

void outputData()

{

fout.open("output.txt");

}

void writetofin(StudentData Info)

{

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

{

fout << setw(32) << Info.nonNumeric[i][0] << endl;

fout << setw(32) << "Name of Student:" << " " << Info.nonNumeric[i][1] << endl;

fout << setw(32) << "Student ID:" << " " << Info.nonNumeric[i][2] << endl;

fout << setw(32) << "Age:" << " " << Info.numeric[i][0] << endl;

fout << setw(32) << "Address:" << " " << Info.nonNumeric[i][3] << endl;

fout << setw(32) << "Number of years at Texas State:" << " " << Info.numeric[i][1] << endl;

fout << setw(32) << "Telephone Number:" << " " << Info.nonNumeric[i][4] << endl;

fout << setw(32) << "Student Social Security #:" << " " << Info.nonNumeric[i][5] << endl << endl;

for(int k = 0; k < 3; k++)

{

fout << setw(32) << "Course#:" << " " << Info.nonNumeric[i][6+k] << endl;

for(int j = 0; j < 5; j++)

{

fout << setw(30) << "Test#" << j + 1 << ":" << " " << Info.numeric2[i][k][j] << endl;

}

fout << fixed << setw(32) << "Numerical Grade:" << " " << Info.numeric2[i][k][5] << endl;

fout << setw(32) << "Letter Grade:" << " " << Info.letterGrade[i][k] << endl;

if(Info.numeric2[i][k][5] >= A_Score)

{

fout << setw(32) << "Commend Note:" << " " << "Congratulations! You have an A!" << endl;

}

else if(Info.numeric2[i][k][5] < D_Score)

{

fout << setw(32) << "Warning Note:" << " " << "You Should Study! You are below a 70 grade average!" << endl;

}

fout << endl << endl;

}

}

fin.close();

fout.close();

}

int main()

{

cout << "Enter the number of Students: ";

cin >> students;

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++){

if(j>0)

fin.ignore();

validateData(data.nonNumeric, j);

validateData(data.numeric, j);

letGrade(data, j);

}

writetofin(data);

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