8) Write a program to declare a class ‘distance’ having data members dist1, dist2 and total_dist. Initialize the two data members using constructor and store their addition in third data member using member function and display the addition

Anonymous School

            (Minds of Hacker)

--------------------------------


Write a program to declare a class ‘distance’ having data members dist1, dist2 and total_dist. Initialize the two data members using constructor and store their addition in third data member using member function and display the addition


C++ Practical



#include<iostream>
using namespace std;

class distanc{
    public:
    int dis1,dis2,total;
    distanc()
    {
        cout<<"Enter the first distance & second distance\n";
        cin>>dis1>>dis2;
    }
    void add()
    {
        total=dis1+dis2;
        cout<<"\nTotal distance = "<<total;
    }
};
int main()
{
    distanc a;
    a.add();

}


Output:



Enter the first distance & second distance 50 30 Total distance = 80




 *******************Don't Make Learning Hard*****************



Follow us on :-

1) YouTube Channel :- Click Here

2) Blog                     :- Click Here


NextGen Digital... Welcome to WhatsApp chat
Howdy! How can we help you today?
Type here...