Question: Code below is from the a'nswer sheet but what I do not understand is that whenever I click build and run, CodeBlocks keep telling me

Code below is from the a'nswer sheet but what I do not understand is that

whenever I click build and run, CodeBlocks keep telling me that line 25 in main.cpp class which is

aC.SetCredits(5) has an error.

Error: 'aC' was not declared in this scope.

I thought aC calls method or module but I have no idea why CodeBlocks say it is an error.

Here is my main.cpp class :

#include

#include

#include "unit.h"

#include "regist.h"

using namespace std;

int main()

{

ifstream infile( "rinput.txt" );

if( !infile ) return -1;

Registration R;

infile >> R;

ofstream ofile( "routput.txt" );

ofile << R

<< "Number of Units = " << R.GetCount() << ' '

<< "Total credits= " << R.GetCredits() << ' ';

Unit aUnit( "dstructs", "ICT283", 2 );

aC.SetCredits(5);

cout << aUnit << endl;

return 0;

}

UNIT.h class.

#ifndef UNIT_H

#define UNIT_H

#include

#include

using namespace std;

const unsigned UNIT_NAME_SIZE = 10;

const unsigned UNIT_ID_SIZE = 7;

class Unit

{

public:

Unit();

Unit( const char * name, char * unitId, unsigned credits);

unsigned GetCredits() const;

void SetCredits( unsigned cred );

friend ostream & operator << (ostream & os, const Unit & unitObj);

friend istream & operator >> (istream & input, Unit & unitObj);

private:

char m_name[UNIT_NAME_SIZE];

char m_unitId[UNIT_ID_SIZE];

int m_credits;

};

#endif

Regist.h class:

#ifndef REGIST_H

#define REGIST_H

#include

#include "result.h"

using namespace std;

const unsigned MAX_RESULTS = 10;

class Registration {

public:

Registration();

unsigned GetCredits() const;

unsigned GetCount() const;

friend ostream & operator <<( ostream & os,

const Registration & R);

friend istream & operator >>( istream & input,

Registration & R );

private:

long m_studentId;// student ID number

unsigned m_semester;// semester year, number

unsigned m_count;// number of units

Result m_results[MAX_RESULTS]; // array of units

};

inline unsigned Registration::GetCount() const

{

return m_count;

}

#endif

Result.h class

#ifndef RESULT_H

#define RESULT_H

#include "unit.h"

using namespace std;

class Result

{

public:

Result();

Result(Unit &unit, float marks);

float GetMarks() const;

void SetMarks(float marks);

unsigned GetCredits() const;

friend ostream & operator << (ostream & os, const Result & resultObj);

friend istream & operator >> (istream & input, Result & resultObj);

private:

float m_marks;

Unit m_unit;

};

#endif // RESULT_H

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!