Hello members,

Well I am always facing trouble with operator overloading. I just have this Assignment in which when I reached operator overloading nothing worked. I tried to do it in many ways but couldnt. Could someone help with this issue please! the question asks to include

d) An overloaded -= operator that will be used to decrement the student’s tuition by a certain value. A
warning message should be displayed for “sports’ Grant” students when the tuition goes below 600.00
dollars. No warning for the other students.
e) An overloaded += operator that will be used to increment the number of siblings by a certain value.

here is the Financial Aid class and 3 other classes are inherited the sports grant, the sibling grant and the scholarship .

Could you please tell me what to write to overload the tuition and could you please explain it to me. Thank you a lot!

class FinancialAid // start of class FinancialAid
{//start of class
	protected:

		int  id;
		char Name[7];
		int age;
		float tuition;
	   
	     
	
public:
		const FinancialAid &operator-=( const FinancialAid & ); 
		FinancialAid( int = 1000 , char* = "hi", int = 20, float = 3000.0);//default arguments

        void get_id();
		void set_id(int);
       
		void set_Name(char []);
		void get_Name();

		void set_Age(int);
		void get_Age();

		void set_tuition(float);
		void get_tuition();

	    void print_all();
        
		void get_Deduction();
        void printAmountDue();
       
};//end of class




const FinancialAid &FinancialAid::operator+=( const FinancialAid &right )
{
int i;
if(tuition < right.tuition)
int *t = new int[right.tuition+1];
for (i = 0; i<=right.tuition; i++)
{
	t[i] = (i<=degree ?a[i] : 0);
	tuition = right.tuition;
	delete[] a;
	a=t;

}
for(i=0;i<=tuition;i++) a[i] += right.a[i];
return *this;
}








FinancialAid::FinancialAid(int ID, char* Name, int age, float tuition) // constructor
{
	
	set_id(ID);
	set_Name(Name);
	set_Age(age);
	set_tuition(tuition);
}

void FinancialAid::printAmountDue()
{
	cout<<"ID: "<<id<<endl;
	cout<<"Name: "<<Name<<endl;
	
	get_Deduction();

}


void FinancialAid::set_Name(char name[])
{
	 strcpy(Name , name);
	
}





void FinancialAid::get_Name() //getting FinancialAid Name
{								//start of get code
		 cout<<"Name:";
         cout<<Name;
         
}							//end of get code





void FinancialAid::set_id(int c)
{//start of set ID


             id =c;
         
}      //end of set ID             
    
void FinancialAid::get_id() 
{
	cout<<"id:";
	cout<<id;


}

void FinancialAid::set_Age(int a)
{

age = a;

}


void FinancialAid::get_Age()
{
cout<<"Age:";
cout<<age;

}

void FinancialAid::set_tuition(float t)
{

tuition = t;

}

void FinancialAid::get_tuition()
{
	cout<<"Tuition:";
	cout<<tuition<<"$";

}

void FinancialAid::print_all()//print all function

{//start of print all

get_id();
cout<<endl;
get_Name();
cout<<endl;
get_Age();
cout<<endl;
get_tuition();
cout<<endl;
}//end of print all

 void FinancialAid::get_Deduction()
{


	cout<<"The student's tuition is: "<<tuition<<"$";
	
}

Something like this?

FinancialAid* operator += (const int incValue)
{
   this->Siblings+=incValue;
   return this;
}

FinancialAid* operator -= (const float decValue)
{
   //Perform the desired checks
   this->tuition+=decValue;
   return this;
}

thanks for ur help !

Mark the thread as solved please. Glad to be of help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.