0
#include<iostream>
using namespace std;
class B
{
    int a;
public:
    int b;
    void get_ab();

    int get_a();
    void show_a();
};
class D :public B
{
    int c;
public:
    void mul();
    void display();
};
void B::get_ab()
{
    a=5;b=10;
}
int B::get_a()
{
    return a;
}
void B::show_a()
{
    cout<<"a="<<a<<"\n";
}

void D::mul()
{
    c= b * get_a();
}

void D::display()
{
    cout<<"a="<<get_a()<<"\n";
    cout<<"b="<<b<<"\n" ;
     cout<<"c="<<c<<"\n" ;
}
int main()
{
    D d;
    d.get_a() ;
    d.get_ab();
    d.show_a();
    d.display();
    d.b=20;
    d.mul();
    d.display()
    return 0;


}

OUTPUT::
a=5
a=5
b=10
c=50

a=5
b=20
c=100

why in 1st output a=5
a=5
again...

3
Contributors
2
Replies
27
Views
2 Years
Discussion Span
Last Post by Hassan_12
2

The first time a is shown on screen is when you call the function d.show_a();

The second time a is shown is when you call d.display();

Edited by Moschops

0

I know its not required , but totally agree with @Moschops.

I wonder why you didnt notice, that you did not call, d.show_a() and only d.display(), in the next output sequence, and hence had one 'a=' on the console.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.