loading...

CS304 Object Oriented Programming Assignment 4 Solution Fall 2013

Consider the following Class Diagram; detailed description of the diagram is given in the table.

Class Name

Attribute Name

Attribute Data Type

Behavior (Functions)

FeeStructure

DegreeProgram

Character String

-InputFeeDetail()

-PrintFeeDetail()

-TotalFee ()

       AdmissionFee

Integer

EnrollmentFee

Integer

TuitionFee

Integer

Local_FS

SecurityFee

Integer

-InputFeeDetail()

-PrintFeeDetail()

-TotalFee ()

AdmissionProcessingFee

Integer

Overseas_FS

-InputFeeDetail()

-PrintFeeDetail()

-TotalFee ()

 

In given class diagram, FeeStructure is a base class; while Local_FS and Overseas_FS are its derived classes sharing its all attributes and functions.

You are required to implement above class diagram in C++. For this you have to use the concept of inheritance and polymorphism. (Hint:  In FeeStructure class, make InputFeeDetail(), PrintFeeDetail() and TotalFee()virtual functions.)

Idea Solution:

#include
#include
#include
class FeeStructure
{
protected :
char *DegreeProgram;
int AdmissionFee;
int EnrollmentFee;
int TuitionFee;
public:
FeeStructure()
{
DegreeProgram = new char[20];
}
virtual void InputFeeDetails(){}
virtual void PrintFeeDetails(){}
int TotalFee();
};

class Local_FS : public FeeStructure
{
private:
int SecurityFee;
int AdmissionProcessingFee;
public:
void InputFeeDetails()
{
cout<<"Enter Degree Program: "; cin>>DegreeProgram;
cout<<"\nEnter Admission Fee: "; cin>>AdmissionFee;
cout<<"\nEnter Enrollment Fee: "; cin>>EnrollmentFee;
cout<<"\nEnter Tuition Fee: "; cin>>TuitionFee;
cout<<"\nEnter SecurityFee: "; cin>>SecurityFee;
cout<<"\nEnter Admission Processing Fee: "; cin>>AdmissionProcessingFee;
}
virtual void PrintFeeDetails()
{
cout<<"Degree Name is: "<>DegreeProgram;
cout<<"\nEnter Admission Fee: "; cin>>AdmissionFee;
cout<<"\nEnter Enrollment Fee: "; cin>>EnrollmentFee;
cout<<"\nEnter Tuition Fee: "; cin>>TuitionFee;

}
virtual void PrintFeeDetails()
{
cout<<"Degree Name is: "<>input;
if(input == 'Y' || input == 'y')
{
char ch;
cout<<"\n***********************************************\n"; cout<<"Press 'L ' or 'l' for Local Student\n"; cout<<"\nPress 'O' or o for Overseas Student "; cout<<"\n*********************************************\n"; cin>>ch;

if(ch == 'L' || ch == 'l')
{

freeStructure = &local;
cout<<"\n------------------------------------------------------\n"; freeStructure->InputFeeDetails();
cout<<"\n------------------------------------------------------\n"; freeStructure->PrintFeeDetails();
cout<<"\n------------------------------------------------------\n\n"; goto Rp; }else if(ch == 'O' || ch == 'o') { freeStructure = &ovreseas; cout<<"\n------------------------------------------------------\n"; freeStructure->InputFeeDetails();
cout<<"\n------------------------------------------------------\n"; freeStructure->PrintFeeDetails();
cout<<"\n------------------------------------------------------\n\n"; goto Rp; } }else if(input == 'N' || input == 'n') cout<

DOWNLOAD SOLUTION HERE
loading...