Implement a program in C++ to define a class MONTHLY_EXPENSE. Declare two data members i.e. household expense and education expense in it.
• Calculate total expense of June and display using member function.
• Calculate total expense of July and display using member function.
• Calculate total expense of two months (objects) i.e. June and July, and display it using member function.
• Also compare total expense of two months (objects) i.e. June and July.
#import <iostream>
class MonthlyExpence {
private:
double household;
double education;
double totalJuneExpence() {
// logic of the function
}
double totalJulyExpence() {
// logic of the function
}
double totalJuneJulyExpence() {
return this->totalJuneExpence() + this->totalJulyExpence();
}
public:
MonthlyExpence(double household, double education) {
this->household = household;
this->education = education;
}
void displayJuneExpence() {
std::cout << "Total expence for June : " << this->totalJuneExpence();
}
void displayJulyExpence() {
std::cout << "Total expence for July : " << this->totalJulyExpence();
}
void displayJuneJulyExpence() {
std::cout << "Total expence for June and July : " << this->totalJuneJulyExpence();
}
bool compareJuneJulyExpence(double june, double july) {
return june > july;
}
};
Comments
Leave a comment