Objective class hierarchy and polymorphism. Write a snippet of code to declare(
ID: 3834417 • Letter: O
Question
Objective class hierarchy and polymorphism. Write a snippet of code to declare( what would go into the .h file) and then implement ( what would go into the .cpp file) the family of classes in Quality Control domain, including:
*the base class called "Test"
*two derived classes corresponding to the specialized test: RegressionTest and LoadTest.
The base class should have a virtual Boolean method called run which is overridden in the sub-classes, where specific logic is placed (//some code), As an exercise, let the method return true/false randomly.
Then in main, declare a pointer to the base class Test and use it to instantiate and run LoadTest. Then use the same pointer to instantiate and run a RegressionTest.
2. objective: hierarchy and polymorphism. wate a snippet of codeto declare class (what would gointo the h file) and them implement (what would go into the gpg file) the family of dasses in Quality Control domain, including the base class called "Tast" two derived classes comesponding to the specialized tests RegssionTeat and LeadT et overridden The base class should have a virtual Boolean method called nam which is let in the sub-classes, where specific logic is placed (l aome code). As an exercise, the method petum true false randomly to instantiate and Then in main, declare a pointer to the base class Teat and ase it omToat tea Tort Then use the same pointer to instantiate and run a RegegExplanation / Answer
class Test {
public:
virtual bool run()=0;
};
class RegressionTest : public Test{
public:
bool run() {
return true;
}
};
class LoadTest : public Test{
public:
bool run() {
return false;
}
};
#include <iostream>
int main() {
Test *t = new LoadTest();
std::cout << t->run() << std::endl;
t = new RegressionTest();
std::cout << t->run() << std::endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.