Challenge 70

Description

The purpose of this challenge is to implement classes with inheritance relationships

This challenge simulates the creation of Form Entry controls as what might be used to display form data on a text-based screen.

 Requirements

  1. Define a class called Control as below
    class Control 
    {
      protected: 
        string text;
    
      public:
    };
  2. Add an overloaded constructor to the Control class to set the value of the protected text data member.
  3. Create a new class called Checkbox. This new class will inherit from the Control class; use public inheritance. The Checkbox class will introduce a private boolean property called checked.
  4. Create an overloaded constructor for Checkbox. This constructor will be used to initialize the inherited text data member as well as its own checked data member. Use an initializer list to invoke the overloaded parent constructor from the Control class.
  5. Add a getter function called display(). This function will return a string that looks like a checkbox. If checked is true, then the text will be displayed with an X. If checked is false, then the text will be displayed without an X. See below:
      Example output for a checked Checkbox:  
        [X] Employed
    
      Example output for an unchecked Checkbox:
        [ ] Employed
    
      In this example, "Employed" is the value of data member "text"
  6. Create a new class called Textbox. This new class will inherit from the Control class; use public inheritance. The Textbox class will introduce a private string property called caption.
  7. Create an overloaded constructor for Textbox. This constructor will be used to initialize the inherited text data member as well as its own caption data member. Use an initializer list to invoke the overloaded parent constructor from the Control class.
  8. Add a getter function called display(). This function will return a string that looks like a filled textbox. If text is empty, then display it as “N/A”. Otherwise, see the examples below:
      Example output for a Textbox with "text" containg valid data
        First Name: Marco
    
      Example output for a Textbox with "text" containing no data:
        First Name: N/A
    
      In this example, "First Name" is the value of "caption", and Marco (or N/A) is the value of "text"
  9. You can use the main() given below. You can add as much driver code as you want to test the classes above.

Sample main()

int main()
{
  Textbox t1("First Name", "Marco");
  Textbox t2("Middle Name", "");
  Textbox t3("Last Name", "Polo");
 
  Checkbox c1("Employed", true);
  Checkbox c2("Student", false);

  cout << t1.display() << endl;
  cout << t2.display() << endl;
  cout << t3.display() << endl;
  cout << endl; 
  cout << c1.display() << endl;
  cout << c2.display() << endl;

  return 0;
}

Sample Output

First Name: Marco
Middle Name: N/A
Last Name: Polo

[X] Employed
[ ] Student

LEGEND
PROGRAM OUTPUT
USER INPUT
FROM INPUT

CATALOG ID: CPP-CHAL0070

Print Requirements