subject
Computers and Technology, 24.06.2021 21:20 mitch80

Below, suppose that you have the following classes: classA and classB. Write the class into a header that is called from main. Be sure to #include , using namespace std; and any additions such as #include "pch. h" are present. class classA
{
public:
virtual void print() const;
void doubleNum();
classA(int a = 0);
private:
int x;
};
void classA::print() const
{
cout << "ClassA x: " << x << endl;
}
void classA::doubleNum()
{
x = 2 * x;
}
classA::classA(int a)
{
x = a;
}
class classB: public classA
{
public:
void print() const;
void doubleNum();
classB(int a = 0, int b = 0);
private:
int y;
};
void classB::print() const
{
classA::print();
cout << "ClassB y: " << y << endl;
}
void classB::doubleNum()
{
classA::doubleNum();
y = 2 * y;
}
classB::classB(int a, int b) : classA(a)
{
y = b;
}
What is the output of the following function main?
int main()
{
classA *ptrA;
classA objectA(2);
classB objectB(3, 5);
ptrA = &objectA;
ptrA->doubleNum();
ptrA->print();
cout << endl;
ptrA = &objectB;
ptrA ->doubleNum();
ptrA->print();
cout << endl;
return 0;
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 07:30
An endless cycle of creation and response on the internet is called
Answers: 1
question
Computers and Technology, 22.06.2019 11:30
Write a function so that the main program below can be replaced by the simpler code that calls function original main program: miles_per_hour = float( minutes_traveled = float( hours_traveled = minutes_traveled / 60.0 miles_traveled = hours_traveled * miles_per_hour print('miles: %f' % miles_traveled) sample output with inputs: 70.0 100.0 miles: 116.666667
Answers: 3
question
Computers and Technology, 22.06.2019 19:20
Consider the following code snippet: #ifndef cashregister_h#define cashregister_hconst double max_balance = 6000000.0; class cashregister{public: cashregister(); cashregister(double new_balance); void set_balance(double new_balance); double get_balance() const; private: double balance[12]; }; double get_monthly_balance(cashregister bk, int month); #endifwhich of the following is correct? a)the header file is correct as given.b)the definition of max_balance should be removed since header files should not contain constants.c)the definition of cashregister should be removed since header files should not contain class definitions.d)the body of the get_monthly_balance function should be added to the header file.
Answers: 1
question
Computers and Technology, 23.06.2019 00:00
What season was better from fortnite?
Answers: 2
You know the right answer?
Below, suppose that you have the following classes: classA and classB. Write the class into a header...
Questions
question
Mathematics, 13.04.2021 22:50
question
English, 13.04.2021 22:50
question
Mathematics, 13.04.2021 22:50
question
Mathematics, 13.04.2021 22:50