Question
So I got the code to work for my other parts of the code but cant figure out where to put the split coce for
So I got the code to work for my other parts of the code but cant figure out where to put the split coce for the last task. I need help coding and figureing out wherre to put the split code in?
here my code:
#include
#include
#include
#include
const int QUIZ_SIZE = 14;//To declare a constant on value
const int HOMEWORK_SIZE = 10;//To declare a constant on value
const int LAB_SIZE = 7;//To declare a constant on value
const int TEST_SIZE = 3;//To declare a constant on value
using namespace std;
string mergeOneLine(int id, string last_name, string first_name, string phone_number, float quizzes[QUIZ_SIZE], float homeworks[HOMEWORK_SIZE], float labs[LAB_SIZE], float tests[TEST_SIZE], float project, float discussion, float teamWork, float extra, float sumScore = 0.0, float percentage = 0.0, char letterGrade = 'X')
{
//Merges all assignments and information into one string and returns it
string oneLine;
stringstream convert;
oneLine += id + "," + last_name + "," + first_name + "," + phone_number + "-";
for (int i = 0; i
convert
//oneLine += convert.str();
}
oneLine += "-";
for (int i = 0; i
convert
//oneLine += convert.str();
}
oneLine += "-";
for (int i = 0; i
convert
//oneLine += convert.str();
}
oneLine += "-";
for (int i = 0; i
convert
//oneLine += convert.str();
}
convert
oneLine += convert.str();
return oneLine;
}
void splitOneLine(string line, int& id, string& last, string& first, string& phone, float quizzes[], float homeworks[], float labs[], float tests[], float& project, float& discussion, float& teamWork, float& extra, float& sumScore, float& percentage, char& letterGrade)//This put grades in one line
{
string temp;
int dash, comma;
comma = line.find(",");
id = stoi(line.substr(0, comma));
line = line.substr(comma + 1);
comma = line.find(",");
last = line.substr(0, comma);
line = line.substr(comma + 1);
comma = line.find(",");
first = line.substr(0, comma);
line = line.substr(comma + 1);
dash = line.find("-");
phone = line.substr(0, dash);
line = line.substr(dash + 1);
dash = line.find("-");
temp = line.substr(0, dash);
for (int i = 0; i
{
comma = temp.find(",");
quizzes[i] = (float)stod(temp.substr(0, comma));
temp = temp.substr(comma + 1);
}
line = line.substr(dash + 1);
dash = line.find("-");
temp = line.substr(0, dash);
for (int i = 0; i
{
comma = temp.find(",");
homeworks[i] = (float)stod(temp.substr(0, comma));
temp = temp.substr(comma + 1);
}
line = line.substr(dash + 1);
dash = line.find("-");
temp = line.substr(0, dash);
for (int i = 0; i
{
comma = temp.find(",");
labs[i] = (float)stod(temp.substr(0, comma));
temp = temp.substr(comma + 1);
}
line = line.substr(dash + 1);
dash = line.find("-");
temp = line.substr(0, dash);
for (int i = 0; i
{
comma = temp.find(",");
tests[i] = (float)stod(temp.substr(0, comma));
temp = temp.substr(comma + 1);
}
line = line.substr(dash + 1);
dash = line.find("-");
project = (float)stod(line.substr(0, dash));//project
cout
line = line.substr(dash + 1);
dash = line.find("-");
discussion = (float)stod(line.substr(0, dash));//discussion
cout
line = line.substr(dash + 1);
dash = line.find("-");
teamWork = (float)stod(line.substr(0, dash));//team work
cout
line = line.substr(dash + 1);
dash = line.find("-");
extra = (float)stod(line.substr(0, dash));//extra
cout
line = line.substr(dash + 1);
dash = line.find("-");
sumScore = (float)stod(line.substr(0, dash)); //sumScore
line = line.substr(dash + 1);
dash = line.find("-");
percentage = (float)stod(line.substr(0, dash)); //average
letterGrade = line.substr(dash + 1)[0];
}
void inputStudentGrades( ){
//Function to perform task2
string first_name, last_name, phone_number, oneLine;
float quizzes[QUIZ_SIZE] = {}, homeworks[HOMEWORK_SIZE] = {}, labs[LAB_SIZE] = {}, tests[TEST_SIZE] = {}, project = 0, discussion = 0, teamWork = 0, extra = 0, sumScore = 0, percentage = 0;//Arrays and variables to store scores
ifstream f("student.txt");//File to read from
ofstream o("tempFile.txt");
char choice, letterGrade = 'X';
int option, id;
do
{
f >> id;
getline(f, last_name, ',');
getline(f, first_name, ',');
getline(f, phone_number, ' ');
cout
cin >> choice;
cin.ignore();
if (choice == 'y' || choice == 'Y')
{
do
{
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cin >> option;
switch (option)
{
case 1: cout
for (int i = 0; i
{
cin >> quizzes[i];
}
break;
case 2: cout
for (int i = 0; i
{
cin >> homeworks[i];
}
break;
case 3: cout
for (int i = 0; i
{
cin >> labs[i];
}
break;
case 4: cout
for (int i = 0; i
{
cin >> tests[i];
}
break;
case 5: cout
cin >> project;
break;
case 6: cout
cin >> discussion;
break;
case 7: cout
cin >> teamWork;
break;
case 8: cout
cin >> extra;
break;
case 0: break;
default: cout
}
} while (option != 0);
oneLine = mergeOneLine(id, last_name, first_name, phone_number, quizzes, homeworks, labs, tests, project, discussion, teamWork, extra, sumScore, percentage, letterGrade);
o
}
} while (choice == 'Y' || choice == 'y' || !f.eof());
f.close();
o.close();
}
int main()
{
char more;
string id, first_name, last_name, phone_number, text;
fstream file;
file.open("student.txt", ios::out);//grab the student .txt and input the grades into that temp
do
{
cout
cout
getline(cin, id);
cout
getline(cin, last_name);
cout
getline(cin, first_name);
cout
getline(cin, phone_number);
file
cout
cin >> more;
cin.ignore();
} while (more == 'y');
cout
string filename = "student.txt";
file.close();
file.open(filename.c_str(), ios::in);
while (file >> text)
cout
file.close();
inputStudentGrades();
//Calling task2 function
return 0;
}
write the above merge line to file tempFile.txt For example in the file one student should be written to the tempFile.txt 1234567,Smith, James,4691234567-2.50,3.50,4.00,5.00,3.25,4.50,3.50,5.00,5.00,4.25,2.50,2.50,5.00,5.00 8.50,9.00,10.00,8.50,9.25,7.50,6.75,8.00,9.00,10.00-30.00,38.50,29.25,23.50,25.00,22.50,28.00-88.50,75.50,78.50-75.50-10.00- 20.00-5.00-0.00-0.00- read next line then do the same until the end of file at the end of this task2 do the following lines of code tempFile.close)//output file ifile.close);//input file //remove original input file remove(fileNe); //rename the tempFile.txt back to orignial file rename("tempFile.txt", fileName) TASK3: GRADING open the above file to read (input file) -open a file tempFile.txt to write (output file) -read file for each line you read split information from the line by using delimeter comma (",") or dash (); then assign each piece of information to the following For example the line is read from file: 1234567,Smith, James,4691234567-2.50,3.50,4.00,5.00,3.25,4.50,3.50,5.00,5.00,4.25,2.50,2.50,5.00,5.00- 8.50,9.00,10.00,8.50,9.25,7.50,6.75,8.00,9.00,10.00-30.00,38.50,29.25,23.50,25.00,22.50,28.00-88.50,75.50,78.50-75.50-10.00- 20.00-5.00-0.00-0.00- Will be splitted into ld 1234567 Last name Smith First name James Phone 4691234567 Quizzes2 Homeworks8.50,9.00,10.00, 509.25,7506. 75,8.00,9.00,10.00 Labs 30.00,38502925,23sa25.00.22.50.28.00 Tests 88.50,75.50,78.50o Project 75.50 Discussion10.00 Team work 20.00 Extra credit 5.00 Sum of score .00 Percentage .00 Letter grade X .50,5.00.5.00,4.25,2 s0,2.50,5.00,5.00 I/these scores are stored in array //these scores are stored in array these scores are stored in array //these scores are stored in array After calculate the percentage and determine the letter grade, you should call the method mergeOneLine again to create a line to write to the output file tempFile.txt -Read another line the do the same until the end of input file After finishing all students do the same thing as task2 to rename the tempFile.txt back to orignial input file Also, display the result of class on the screen in the following format; GRADING CLASS Total students: Grade A: Grade B: Grade C 20 25% 50% 20% 10Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started