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.
#include<iostream>
#include<string>
using namespace std;
class Base_Class_1{
public:
std::string name;
std::string source;
std::string destination;
};
class Base_class_2{
public:
int no_of_pack=0;
int weight=0;
};
class Derived_class: public Base_Class_1, public Base_class_2{
public:
int total_weight=0;
int total_amount=0;
void display(){
total_weight=weight*no_of_pack;
total_amount=2;
if(total_weight>15)
total_amount += (total_weight-15)*1;
std::cout<<"name"<<name<<std::endl;
std::cout<<"source"<<source<<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(){
Derived_class a; //object of derived class
a.name = "name test";
a.destination = "destination test";
a.source="source test";
a.no_of_pack=20;
a.weight=2;
a.display();
return 0;
}
Comments
Leave a comment