Hi,so Im working with this code, I just got stalk on now and I am not able to fi
ID: 3828672 • Letter: H
Question
Hi,so Im working with this code, I just got stalk on now and I am not able to figure out the error this is question and my code is under it and I will have the txt file below, thanks!
99.0 1 100
87.5 1 100
103.0 2 100
96.0 2 100
48.5 2 100
78.0 2 100
10.0 3 10
98.5 3 100
73.0 3 75
98.5 3 100
97.0 3 100
100.0 3 100
100.0 4 100
96.5 4 100
95.0 4 100
94.0 4 100
80.0 4 100
90.0 4 100
100.0 4 100
10.0 4 10
20.0 4 20
15.0 4 15
9.0 5 10
8.0 5 10
10.0 5 10
7.0 5 10
14.0 5 20
20.0 5 20
17.0 5 20
21.0 5 21
10.0 5 10
5.0 5 5
71.5 6 100
Part I: Create Score Class
Write a new class for the Score. The Score should store the following:
Score
Max points for assignment
Grade type
Part II: Input Function
Write a function that will read in the data from a text file to store in the array of Scores. This function will have four parameters passed by reference:
Array of Scores
Size of the arrays
Part III: Average Function
Write a function that will compute the average of a specific grade type. This function will have four parameters passed by value and return the average.
Array of Scores
Size of the array
Part IV: Calculate Final Grade Function
Write a function that will compute the student’s final grade based on the grade type averages and their weight (you can define these in the main) towards the final grade. The input parameters will be up to you determine/customize. Just make sure the function returns the final grade (numerical).
Part V: Output Final Grade
Write a function that will output the numeric and letter grade for the student.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <math.h>
#include <fstream>
using namespace std;
class Sample
{
Private:
Int number;
char letter_grade(double score) {
char limit[][4] = { { 90,80,70,60 },{ 'A','B','C','D' } };
for (int i = 0; i < 4; i++) {
if (score >= limit[0][i])
return limit[1][i];
}
return 'F';
}
void inputData(double score[], int &size) {
//open the input file
ifstream input("X:\Downloads\lab4input.txt");
if (input) {
cout << "quizz grades my guy " << endl;
}
//In the while condition, add the instream variable
while (input >> score[size]) {
size++;
}
//clsoe the file
input.close();
}
int main() {
Public:
Int getNumber() {
Return number;
//Array to store the scores
double score[50];
int size = 0;
inputData(score, size);
// print the input data
for (int i = 0; i < size; i++) {
cout << ", score " << score[i] << endl;
}
system("pause");
return 0;
}
Explanation / Answer
#include <iostream>
#include <fstream>
using namespace std;
// Creating Score Class
class Score{
public:
float score;
int gradeType;
float maxScore;
};
// read data from file in score, grade, max_score format
void inputData(Score score[], int &size){
std::ifstream infile("thefile.txt");
float s, m;
int g;
int index = 0;
while (infile >> s >> g >> m)
{
Score s;
s.score = s;
s.gradeType = g;
s.maxScore = m;
score[index] = s;
index++;
}
}
// Calculate average score of a specific type of grade
float averageOfGrade(Score score[], int size, int gradeType){
float sum = 0;
int count = 0;
for(int i=0; i< size; i++){
Score s = score[index];
if(s.gradeType == gradeType){
sum += s.score;
count++;
}
}
return (float)(sum)/count;
}
// Calcuate final score based on weights to each gradetype
float finalGrade(Score score[], int scoreSize, int grades[], float weights[], int sizeGrades){
float sumEachGrade[sizeGrades];
int countEachGrade[sizeGrades];
for(int i=0; i< sizeGrades; i++){
sumEachGrade[i] = 0.0;
countEachGrade[i] = 0;
}
for(int i=0; i< sizeGrades; i++){
for(int j=0; j<scoreSize; j++){
Score s = score[j];
if(s.gradeType == grades[i]){
sumEachGrade[i] += sumEachGrade[i] + s.score;
countEachGrade[i] += 1;
}
}
}
float final_grade = 0.0;
for(int i=0; i< sizeGrades; i++){
final_grade += (float)(sumEachGrade[i]/countEachGrade[i]) * weights[i];
}
return final_grade;
}
void print_grade(float final_grade) {
char limit[][4] = { { 90,80,70,60 },{ 'A','B','C','D' } };
char grade = 'F';
for (int i = 0; i < 4; i++) {
if (score >= limit[0][i])
grade = limit[1][i];
}
cout << "Grade is: " << grade << " and grade numeric is " << final_grade ;
}
int main(){
Score score[50];
int size = 50;
int grade[] = {1,2,3,4,5,6};
int gradeSize = 6;
float weight[] = {0.1, 0.2, 0.15, 0.15, 0.2, 0.2};
inputData(score, size);
cout<<"Average is: " << averageOfGrade(score, size, 1);
print_grade(finalGrade(score, size, grade, weights, gradeSize ));
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.