Description: As you know in a header file (.h) for a class we include itsdeclara
ID: 3612194 • Letter: D
Question
Description:
As you know in a header file (.h) for a class we include itsdeclaration while in implementation file (.cpp) part we addimplementation of all methods of that class. In this assignment youhave to do exactly the same for all classes in your Dev c++ projectyou already have created in Assignment No.4, you have to add thefollowing for each class,
Important Note:
· In thisassignment you are required to write the necessary code for eachclass only the associations betweendifferent classes will be handled in next assignment.
Appendix:
Example code for a Course class to store any course attributesis given below similarly you have to add code for all your classesin your Dev c++ project,
Course.h
#include <iostream>
using namespacestd;
class Course {
public:
Course(char* , char *, int );
void setName(char*);
char*getName() const;
void setCode(char*);
char*getCode() const;
int gerCreditHours();
voidsetCreditHours(int);
int getCreditHours()const;
~Course();
private:
char*name;
char*code;
int credithours;
};
Course.cpp
#include "Course.h"
Course::Course(char* _name, char *_code, int _credithours)
{
name =newchar[strlen(_name)];
strcpy(name,_name);
code =newchar[strlen(_code)];
strcpy(code,_code);
credithours =_credithours;
}
void Course::setName(char* _name)
{
if (name !=NULL )delete[]name;
name =newchar[strlen(_name)];
strcpy(name,_name);
}
char *Course::getName() const
{
return name;
}
void Course::setCode(char* _code)
{
if(code !=NULL) delete[]code;
code =newchar[strlen(_code)];
strcpy(code,_code);
}
char *Course::getCode() const
{
return code;
}
voidCourse::setCreditHours(int_credithours )
{
credithours =_credithours;
}
int Course::getCreditHours()const
{
return credithours;
}
Course::~Course()
{
if(name!= NULL)delete[]name;
if (code!= NULL)delete[]code;
}
Course.h
#include <iostream>
using namespacestd;
class Course {
public:
Course(char* , char *, int );
void setName(char*);
char*getName() const;
void setCode(char*);
char*getCode() const;
int gerCreditHours();
voidsetCreditHours(int);
int getCreditHours()const;
~Course();
private:
char*name;
char*code;
int credithours;
};
Course.cpp
#include "Course.h"
Course::Course(char* _name, char *_code, int _credithours)
{
name =newchar[strlen(_name)];
strcpy(name,_name);
code =newchar[strlen(_code)];
strcpy(code,_code);
credithours =_credithours;
}
void Course::setName(char* _name)
{
if (name !=NULL )delete[]name;
name =newchar[strlen(_name)];
strcpy(name,_name);
}
char *Course::getName() const
{
return name;
}
void Course::setCode(char* _code)
{
if(code !=NULL) delete[]code;
code =newchar[strlen(_code)];
strcpy(code,_code);
}
char *Course::getCode() const
{
return code;
}
voidCourse::setCreditHours(int_credithours )
{
credithours =_credithours;
}
int Course::getCreditHours()const
{
return credithours;
}
Course::~Course()
{
if(name!= NULL)delete[]name;
if (code!= NULL)delete[]code;
}
Explanation / Answer
x.