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

How is this possible I cannot seem to clear my errors with out changing the othe

ID: 3551354 • Letter: H

Question

How is this possible I cannot seem to clear my errors with out changing the other files? I keep getting the error message "no matching function for call to "Student::Student(std::string&"

You may not change any of the provided code for the program outside of student.h and student.cpp. Your new code must be consistent with the calls already written into the other code.


----------------------------------------------------------------------------------------------------------------------------------------------------------------------

gpaCalc.cpp

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include "student.h"
#include "gradeValue.h"

using namespace std;

/**
* Read a student record, followed by a number of grade records.
* Update the student record to reflect the new grades, then
* compute and print the student's GPA.
*
* @param input
* @param output
*/
void gpaCalc (istream& input, ostream& output)
{
string name;
getline (input, name);
int credits;
double qp;
input >> credits >> qp;
Student student(name, credits, qp);
string grade;
input >> grade >> credits;
while (grade != "0" && credits != 0)
   {
    student.addGrade (grade, credits);
    input >> grade >> credits;
   }
   double gpa = student.computeGPA();
   output << student.name << ' '
   << fixed << setprecision(2) << gpa << endl;
}


int main (int argc, char** argv)
{
// A useful "trick": The code below looks to see if
// a command line parameter has been specified. If so,
//     e.g.: gpaCalc fileName
// the command line paraemter is assumed to name an input file
// and the rest of the program reads form that file.
// If no command parameter is given, the program reads its
// input from cin.
//
// What makes this useful is that it is often easier to supply
// input from a file during debugging, even if the program is
// normally supposed to read from standard input (cin).

if (argc > 1)
    {
      ifstream inputFile (argv[1]);
      gpaCalc (inputFile, cout);
    }
else
    gpaCalc (cin, cout);
return 0;
}

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

student.h

----------------------------------------------------------------------------------------------------------------------------------------------------------------------



#ifndef STUDENT_H_INCLUDED

#define STUDENT_H_INCLUDED

#include <fstream>

#include <string>

using namespace std;

struct Student {

string name;

    int credits;

double qp;

};

void addGrade(Student& aStudent, std::string grade, int credits);

double computeGPA (const Student aStudent);

#endif

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

student.cpp

----------------------------------------------------------------------------------------------------------------------------------------------------------------------



#include "student.h"

#include "gradeValue.h"

using namespace std;

void addGrade(Student& aStudent, string grade, int credits)

{

    aStudent.credits += credits;

double v = findGradeValue(grade);

    aStudent.qp += credits * v;

}

double computeGPA (const Student aStudent)

{

if (aStudent.credits > 0)

return aStudent.qp / aStudent.credits;

else

return 0.0;

}

----------------------------------------------------------------------------------------------------------------------------------------------------------------

gradeValue.h

----------------------------------------------------------------------------------------------------------------------------------------------------------------


#ifndef GRADEVALUE_H
#define GRADEVALUE_H

#include <string>

/**
* Search an array of GradeValues for one matching a given grade string,
* returning the corresponding grade value. If the grade string is not in the array,
* return the value of the last element of the array.
*
* @param grade   the grade that we are searching for
* @return the value corresponding to that grade
*/
double findGradeValue (std::string grade);

#endif

-------------------------------------------------------------------------------------------------------------------------------------------------------------

gradeValue.cpp

---------------------------------------------------------------------------------------------------------------------------------------------------------------

#include "gradeValue.h"

using namespace std;

struct GradeValue {
string grade;
double value;
};


const GradeValue gradeValues[] = {
  {"A", 4.0},
  {"A-", 3.7},
  {"B+", 3.3},
  {"B", 3.0},
  {"B-", 2.7},
  {"C+", 2.3},
  {"C", 2.0},
  {"C-", 1.7},
  {"D+", 1.3},
  {"D", 1.0},
  {"F", 0.0}
};

const int numGradeValues = 11;


/**
* Search an array of GradeValues for one matching a given grade string,
* returning the corresponding grade value. If the grade string is not in the array,
* return the value of the last element of the array.
*
* @param table   an array of GradeValues
* @param tableSize number of elements i nthe array
* @param grade   the grade that we are searching for
* @return the value corresponding to that grade
*/
double findGradeValue (string grade)
{
for (int i = 0; i < numGradeValues; ++i)
    if (gradeValues[i].grade == grade)
      return gradeValues[i].value;
return gradeValues[numGradeValues-1].value;
}


--------------------------------------------------------------------------------------------------------------------------------------------------------------------

Explanation / Answer

You do not require files gradeValue.cpp and student.cpp,other 3 files are


1) gpaCalc.cpp


#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include "student.h"
#include "gradeValue.h"

using namespace std;

/**
* Read a student record, followed by a number of grade records.
* Update the student record to reflect the new grades, then
* compute and print the student's GPA.
*
* @param input
* @param output
*/
void gpaCalc (istream& input, ostream& output)
{
string name;
getline (input, name);
int credits;
double qp;
input >> credits >> qp;
Student student;
student.name = name;
student.credits = credits;
student.qp = qp;
string grade;
input >> grade >> credits;
while (grade != "0" && credits != 0)
   {
    addGrade (student,grade, credits);
    input >> grade >> credits;
   }
   double gpa = computeGPA(student);
   output << student.name << ' '
   << fixed << setprecision(2) << gpa << endl;
}


int main (int argc, char** argv)
{
// A useful "trick": The code below looks to see if
// a command line parameter has been specified. If so,
//     e.g.: gpaCalc fileName
// the command line paraemter is assumed to name an input file
// and the rest of the program reads form that file.
// If no command parameter is given, the program reads its
// input from cin.
//
// What makes this useful is that it is often easier to supply
// input from a file during debugging, even if the program is
// normally supposed to read from standard input (cin).

if (argc > 1)
    {
      ifstream inputFile (argv[1]);
      gpaCalc (inputFile, cout);
    }
else
    gpaCalc (cin, cout);
return 0;
}


2) student.h


#ifndef STUDENT_H_INCLUDED
#define STUDENT_H_INCLUDED
#include <fstream>
#include <string>
#include "gradeValue.h"
using namespace std;

struct Student
{
    string name;
    int credits;
    double qp;
};

void addGrade(Student& aStudent, string grade, int credits)
{
    aStudent.credits += credits;

    double v = findGradeValue(grade);

    aStudent.qp += credits * v;
}

double computeGPA (const Student aStudent)
{
    if (aStudent.credits > 0)
        return aStudent.qp / aStudent.credits;
    else
        return 0.0;
}
#endif


3) gradeValue.h


#ifndef GRADEVALUE_H
#define GRADEVALUE_H
#include <string>

struct GradeValue {
std::string grade;
double value;
};


const int numGradeValues = 11;

const GradeValue gradeValues[] = {
{"A", 4.0},
{"A-", 3.7},
{"B+", 3.3},
{"B", 3.0},
{"B-", 2.7},
{"C+", 2.3},
{"C", 2.0},
{"C-", 1.7},
{"D+", 1.3},
{"D", 1.0},
{"F", 0.0}
};

double findGradeValue (std::string grade)
{
for (int i = 0; i < numGradeValues; ++i)
    if (gradeValues[i].grade == grade)
      return gradeValues[i].value;
return gradeValues[numGradeValues-1].value;
}

#endif

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