Computers and Technology

What is the output of the following C++ program?

#include
#include

using namespace std;

class baseClass
{
public:
void print() const;
baseClass(string s = " ", int a = 0);
//Postcondition: str = s; x = a;

protected:
int x;

private:
string str;
};

class derivedClass: public baseClass
{
public:
void print() const;
derivedClass(string s = "", int a = 0, int b = 0);
//Postcondition: str = s; x = a; y = b;
private:
int y;
};

int main()
{
baseClass baseObject("This is the base class", 2);
derivedClass derivedObject("", 3, 7);

baseObject. print();
derivedObject. print();

system("pause");

return 0;
}
void baseClass::print() const
{
cout << x << " " << str << endl;
}

baseClass::baseClass(string s, int a)
{
str = s;
x = a;
}

void derivedClass::print() const
{
cout << "Derived class: " << y << endl;
baseClass::print();
}

derivedClass::derivedClass(string s, int a, int b) :
baseClass("Hello Base", a + b)
{
y = b;
}

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 24.06.2019 13:30, livie225
Type the correct answer in the box. spell all words correctly. what is the default margin width on all four sides of a document? by default, the document has a margin on all four sides.
Answers: 1
image
Computers and Technology, 24.06.2019 14:40, drecooks713
Create a function (prob3_6) that will do the following: input a positive scalar integer x. if x is odd, multiply it by 3 and add 1. if the given x is even, divide it by 2. repeat this rule on the new value until you get 1, if ever. your program will output how many operations it had to perform to get to 1 and the largest number along the way. for example, start with the number 3: because 3 is odd, we multiply by 3 and add 1 giving us 10. 10 is even so we divide it by 2, giving us 5. 5 is odd so we multiply by 3 and add one, giving us 16. we divide 16 (even) by two giving 8. we divide 8 (even) by two giving 4. we divide 4 (even) by two giving 2. we divide 2 (even) by 2 to give us 1. once we have one, we stop. this example took seven operations to get to one. the largest number we had along the way was 16. every value of n that anyone has ever checked eventually leads to 1, but it is an open mathematical problem (known as the collatz conjectureopens in new tab) whether every value of n eventually leads to 1. your program should include a while loop and an if-statement.
Answers: 3
image
Computers and Technology, 24.06.2019 15:00, MilanPatel
In excel, what happens to the cell contents when you click and drag a cell into multiple cells?
Answers: 1
image
Computers and Technology, 24.06.2019 20:30, glstephens04
How is energy expended in active transport
Answers: 1
Do you know the correct answer?
What is the output of the following C++ program?

#include
#include

u...

Questions in other subjects:

Konu
Mathematics, 20.09.2020 08:01
Konu
Mathematics, 20.09.2020 08:01
Konu
Mathematics, 20.09.2020 08:01