Calculation from inheritance of different classes

I'm doing a question which includes a DineInMeal class, HomeDelivery Class and a HomeMeal class. The DineInMeal class is to instantiate a specific set meal and the price, and display the members. The HomeDelivery class is to insantiate the district of the delivery and the delivery fee and display the members. The HomeMeal is to instantiate the address and the total charge of the price of the meal and the delivery fee. I've been able to complete both the DineInMeal and HomeDelivery class. However, for the HomeMeal class, I couldn't figure out how to calculate the price of the set meal and the delivery fee which is here inherited from the previous two classes. I have tried quite several times but there is some sort of an error. Can anyone help me?

DineInMeal header file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#pragma once
#include <iostream>
#include <string>
using namespace std;

class DineInMeal
{
		private:
		string mealSet;
		double price;
	public:
		DineInMeal(string = "", double = 0.0);
		void showDineInMeal();
};


DineInMeal cpp file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <string>
#include "dineinmeal.h"
using namespace std;

DineInMeal::DineInMeal(string ms, double p)
{
	mealSet = ms;
	price = p;
}

void DineInMeal::showDineInMeal()
{
	cout << "Meal set: " << mealSet << endl;
	cout << "Price: " << price << endl;
}


HomeDelivery header file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#pragma once
#include <iostream>
#include <string>
using namespace std;

class HomeDelivery
{
	private:
		int district;
		double deliveryFee;
	public:
		HomeDelivery(int = 0, double = 0.0);
		void showHomeDelivery();
};


HomeDelivery cpp file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <string>
#include "homedelivery.h"
using namespace std;

HomeDelivery::HomeDelivery(int d, double df)
{
	district = d;
	deliveryFee = df;
}

void HomeDelivery::showHomeDelivery()
{
	if (district == 123)
	{
		deliveryFee = 5.00;
	}
	else if (district == 135)
	{
		deliveryFee = 10.00;
	}
	else 
	{
		deliveryFee = 20.00;
	}
	cout << "District: " << district << endl;
	cout << "Delivery Fee: " << deliveryFee << endl;
}


HomeMeal header file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#pragma once
#include <iostream>
#include <string>
#include "dineinmeal.h"
#include "homedelivery.h"
using namespace std;

class HomeMeal :public DineInMeal, public HomeDelivery
{
private:
	DineInMeal dineInMeal;
	HomeDelivery homeDelivery;
	string address;
	double totalCharge;
public:
	HomeMeal(string = "", string = "", double = 0.0, int = 0, double = 0.0, double = 0.0);
	double getTotalCharge(double p, double df, double tc);
	void showHomeMeal();
};


HomeMeal cpp file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <string>
#include "dineinmeal.h"
#include "homedelivery.h"
#include "homemeal.h"
using namespace std;

HomeMeal::HomeMeal(string addr, string ms, double p, int d, double df, double tc) : DineInMeal(ms, p), HomeDelivery(d, df)
{
	address = addr;
	totalCharge = tc;
	totalCharge = 0;
}

void HomeMeal::showHomeMeal()
{
	cout << "Address: " << address << endl;
	DineInMeal::showDineInMeal();
	HomeDelivery::showHomeDelivery();
	getTotalCharge(double p, double df, double tc);
}

double HomeMeal::getTotalCharge(double p, double df, double tc)
{
	totalCharge = p + df;
	return totalCharge;
}



test driver
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include "dineinmeal.h" //to create cashcard object
#include "homedelivery.h"
#include "homemeal.h"//to create bankaccount aobject
using namespace std;
int main()
{

	HomeMeal h1("123 Thomson Close", "Dinner Premium Set A", 123.50, 450, 0);
	h1.showHomeMeal();
	cin.ignore();
}


I keep getting error on the "getTotalCharge(double p, double df, double tc)" function. What seems to be missing in my codes?
In HomeMeal::showHomeMeal(), what are doing on the last line?

getTotalCharge(double p, double df, double tc);

Are you trying to call the function?
Yes I'm trying to call it, cause if I dont call, one of the brackets will be red underlined.
firedraco's point was that line 20 is not a function call. It is actually a function prototype.
Do NOT include argument types in a function call.
The line should be:
 
getTotalCharge (p, df, tc);


Last edited on
I tried erasing the "double" in all, according to your corrected line but it's still in error which I'm unsure why.
Please post the exact text of your error.

homemeal header lines 8, 11-12: You both inherit DineInMeal and HomeDelivery and have them as member variables. This is wrong. Consider the IS A and HAS A rules. If a HomeMeal IS A DineInMeal and IS A HomeDelivery, then inheritance is correct and you should NOT have them as member variables. If a HomeMeal HAS A DineInMeal and HAS A HomeDelivery, then construction is correct and inheritance should not be used.

Last edited on
Topic archived. No new replies allowed.