Answer to Question #174014 in C++ for VARUN

Question #174014

The postage for ordinary post is Rs. 2.00 for the first 15 grams and Rs. 1.00 for each additional 10 grams. Write a C++ program to calculate the charge of postage for a post weighting N grams. Read the weights of N packets and display the total amount of postage using multiple inheritance.

* Base class-1: Member variables are name, source and destination.

* Base class-2: Member variables are no. of packets and weight.

* Derived class: Member functions display(), displays the name, source, destination, total weight and total amount.


1
Expert's answer
2021-03-22T07:38:10-0400
#include <iostream>
#include <string>


class Base_1
{
public:
	std::string name;
	std::string sourse;
	std::string destination;
	};
class Base_2
{
public:
	int n = 0;
	int weigth = 0;
};


class Derived :public Base_1, public Base_2
{
public:
	int total_weight = 0;
	int total_amount = 0;
	void display() 
	{
		total_weight = weigth * n;
		total_amount = 2;
		if (total_weight > 15)
			total_amount += (total_weight - 15) * 1;
		std::cout << "name " << name << std::endl;
		std::cout << "sourse " << sourse << std::endl;
		std::cout << "destination " << destination << std::endl;
		std::cout << "total_weight " << total_weight << std::endl;
		std::cout << "total_amount " << total_amount << std::endl;
	}
};


int main()
{
	//example 
	Derived d1;
	d1.name = "name test ";
	d1.destination = "destination test";
	d1.sourse = "sourse_test";
	d1.n = 20;
	d1.weigth = 2;
	d1.display();
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS