Concept explainers
Explanation of Solution
Creating pointers to base class:
The pointer object can be created to a base class and it uses “*” before the object. This object can be assigned to the address of the derived class.
Program:
The below program explains the creation of pointer object to the base class.
/*Include required files*/
#include<iostream>
using namespace std;
/*Base Class*/
class One
{
/*Access specifier*/
protected:
/*Declare the variable "base_var" as "int"*/
int base_var;
/*Access specifier*/
public:
/*Constructor*/
One (int num = 10)
{
/*Assign val to base_var*/
base_var = num;
}
/*Function getValue()*/
int getValue()
{
/*Return the value of base_var*/
return base_var;
}
};
/*Derived class*/
class Two: public One
{
/*Access specifier*/
private:
/*Declare the variable "der_var" as "int"*/
int der_var;
/*Access specifier*/
public:
/*Constructor*/
Two(int num = 30 )
{
/*Assign “val” to “der_var” */
der_var = num;
}
/*Function getValue()�...
Want to see the full answer?
Check out a sample textbook solutionChapter 15 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
- C++ create a class with a static member item so that whenever a new object is created the total number of objects of the class can be reported.arrow_forwardFill-in-the-Blank A base class pointer needs a(n) _________ to be assigned to a derived class pointer.arrow_forwardWhen using pointers or references to a base class, how should software invoke the same virtual function in different forms and structures?arrow_forward
- Pointer and classImplement a class called Team as specified:data members:name - the name of the Team (defined as a dynamic variable)members - a dynamic array of stringsize - number of members in the team.functions:Course(): default constructor set name to “TBD”, and size to 0, members toempty listCourse(string): one argument constructor set name, and size to 0, members toempty listaccessor - an accessor for the name and size variablemutator - an mutator for the name variableUse following main() to test your class.int main() {Team a,b("Mets");cout<<a.getName()<<endl; // print TBDa.setName("Yankee");cout<<a.getName()<<endl; // print Yankeecout<<b.getName()<<endl; // print Metscout<<a.getSize()<<endl; // print 0return 0;}arrow_forwardExplain why memberwise assignment in a class with a pointer member may create issues.arrow_forwardplease assist me c++ language 1, employee and productionwork classes design a class named employee. the class should keep the following information: employee name employee number hire date write one or more constructors, and the appropriate access and mutator functions, for the classes. next write a class named production worker that is derived from the employee class. the product ionworker class should have member variables to hold the following information shift (an array) Hourly pay rate (a double) the workday is divided into two shifts: day and night. the shift variable will hold an integer value representing the shift that the employee works. the day shift is shift 1, and the night shift is shift 2. write one or more constructors, and the appropriate accessor and mutator functions, for the class. Demonstrate the classes by writing a program that uses a production worker object . note: please submit 3 files employee.h productionWorker.h cpp filearrow_forward
- Casting a base-class pointer to a derived-class pointer is called_______________arrow_forwardQuestion Object Oriented Programming c++ Write a program that defines a class with a data member to holds a "serial number" for each object created from the class. That is, the first object created will be numbered 1, the second 2, and so on. To do this, you'll need another data member that records a count of how many objects have been created so far. (This member should apply to the class as a whole; not to individual objects. What keyword specifies this?) Then, as each object is created, its constructor can examine this count member variable to determine the appropriate serial number for the new object. Add a member function that permits an object to report its own serial number. Then write a main() program that creates three objects and queries each about its serial number. They should respond I am object number 2, and so on.arrow_forwardWhat are the three tasks you must do for classes that include member variables that are pointers?arrow_forward
- Chapter 15 Customer Employee Creator Create an object-oriented program that allows you to enter data for customers and employees. The person related classes will be stored in a module separate from the main function application module. Console Customer/Employee Data Entry Customer or employee? (c/e): c DATA ENTRY First name: Frank Last name: Wilson Email: frank44@gmail.com Number: M10293 CUSTOMER Full name: Frank Wilson Email: Number: Continue? (y/n): y Customer or employee? (c/e): e DATA ENTRY First name: Joel Last name: Murach Email: joel@murach.com SSN: 123-45-6789 EMPLOYEE Full name: Joel Murach Email: SSN: Bye! frank44@gmail.com Continue? (y/n): n ● M10293 ● Specifications Create a Person class that provides attributes for first name, last name, and email address. Include a parameter for each attribute in the constructor method. This class will provide a property or method that returns the person's full name. ● ● ● ● joel@murach.com 123-45-6789 Create a Customer class that…arrow_forwardTrue or false The arguments passed to member functions by reference are considered as data members of class.arrow_forwardOperator______________ can be used to downcast base-class pointers safely.arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,