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)
- Language=C++ Create an employee class. The member data should comprise an int for storing the employee number and a float for storing the employee’s compensation. Member functions should allow the user to enter this data and display it. Write a main() that allows the user to enter data for three employees and display it (Use Array of objects).arrow_forwardExplain why memberwise assignment in a class with a pointer member may create issues.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
- C++ program 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_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
- c++ languagearrow_forwardOperator______________ can be used to downcast base-class pointers safely.arrow_forwardChapter 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_forward
- C++ code to create a empty class.arrow_forwardAmong class data members, static members and non-static members are distinguished by the following characteristics: Provide an example of real-world application where you think a static data member would be useful.arrow_forwardPointers A pointer is basically a reference to an object or a function. In fact, it is a variable that holds memory address. This address is the location of some other variable or object in memory. For example, if one variable contains the address of another variable, first one is said to point to the second one. Pointers may have many uses, such as to make functions implement “call-by-reference” methodology and to construct dynamic arrays or structures at run-time. a) Write a complete C program that demonstrates the usage of call-by-reference technique needed for swapping. Develop a call-by-value version to see that changes done to the parameters inside the function are lost. b) Write a complete C program that implements below given user-defined function prototypes for arrays-of-integers. void input_1d_array( int*, int ); void output_1d_array( int*, int ); int sum_1d_array( int*, int ); float average_1d_array( int*, int ); Test each function separately! c) [if time allows]…arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,