Question: i need help to debug my code i keep getting error: |36|error: no matching function for call to 'Result::GetUnit() const'| when i have the function
i need help to debug my code i keep getting error: |36|error: no matching function for call to 'Result::GetUnit() const'|
when i have the function in my code.
below is my code:
Unit.H
#ifndef UNIT_H
#define UNIT_H
#include
#include
using namespace std;
class Unit
{
public:
Unit();
Unit( string nam, string unitId, unsigned cred );
// Construct a course from a name, section letter,
// and number of credits.
~Unit();
unsigned getCredits() const;
// Get the number of credits.
string getName() const;
//Get name of unit
string getUnitId() const;
void setName(string name);
//Set name of unit
void setCredits( unsigned cred );
// Set the number of credits.
void setUnitId(string unitId);
// These operators have been made friends. They have
// privileged access to class internals.
// Very useful for debugging the class, but not very good for class design.
// We will keep using it for now but you will have a chance in a later lab
// to redesign this class.
//friend istream & operator >>( istream & input, Unit & C );
private:
string m_name; // course name, C style string. not a C++ string object
string m_unitID; //Unit Id of string
int m_credits; // number of credits
};
ostream & operator <<( ostream & os, const Unit & U ); //Need to change to string
istream & operator >>( istream & input, Unit & U );
#endif
Unit.cpp
#include "Unit.H"
Unit::Unit() :m_name(),m_unitID(), m_credits() { m_name = " "; // it is a char * string, not a C++ string object. m_unitID = " "; //Char string for units m_credits = 100; }
Unit::Unit( string name, string unitId, unsigned cred ) :m_name(),m_unitID(), m_credits() { m_name = name; m_unitID = unitId; m_credits = cred; }
Unit::~Unit() { }
string Unit::getName() const { return m_name; }
void Unit::setName(string name) { m_name = name; }
string Unit::getUnitId() const { return m_unitID; }
void Unit::setUnitId(string unitID) { m_unitID = unitID; }
unsigned Unit::getCredits() const { return m_credits; }
void Unit::setCredits( unsigned cred ) { m_credits = cred; }
istream & operator >>( istream &input, Unit &U ) { string name; string unitID; string cred; getline(input, name, ','); U.setName(name); getline(input, unitID, ','); U.setUnitId(unitID); getline(input, cred, ','); return input; }
ostream & operator <<( ostream &os, const Unit &U ) { string name; string unitID; unsigned cred; name = U.getName(); unitID = U.getUnitId(); cred = U.getCredits(); os << " Unit: " << name << ' ' << " Unit ID: " << unitID << ' ' << " Credits: " << cred << ' '; return os; }
result.h
#ifndef RESULT_H_INCLUDED #define RESULT_H_INCLUDED
#include
using namespace std;
class Result { public: Result();
void GetUnit(Unit &unit) const; void SetUnit(const Unit &unit);
float GetMarks() const; void SetMarks(float marks);
private: Unit m_unit; float m_marks; };
ostream & operator << (ostream & os, const Result & R); //overloading the stream so that to enable print in and print out istream & operator >> (istream & input, Result & R);
#endif // RESULT_H_INCLUDED
result.cpp
#include "result.h"
//constructor Result::Result() :m_unit(), m_marks() { Unit aUnit("Dummy", "ICT000", 3); SetUnit(aUnit); m_marks = 100; }
void Result::GetUnit(Unit &unit) const { unit = m_unit; }
void Result::SetUnit(const Unit &unit) { m_unit = unit; }
float Result::GetMarks() const { return m_marks; }
void Result::SetMarks(float marks) { m_marks = marks; }
ostream & operator << (ostream & os, const Result & R) { float marks; Unit unit; unit = R.GetUnit(); marks = R.GetMarks(); os << R.GetUnit(); << " Marks: " << marks << ' ' ; // os < istream & operator >> (istream & input, Result & R) { float marks; Unit unit; unit = R.GetUnit(); marks = R.GetMarks(); getline(input, unit, ','); R.SetUnit(name); getline(input, marks, ','); R.SetMarks(marks); input >> unit >> marks; //passing 4 fields - name, unit ID, credits and marks return input; } result_test #include using namespace std; int main() { Result result; cout << result <
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
