answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ddd [48]
2 years ago
6

Write the printitem() method for the base class. sample output for below program: last name: smith first and last name: bill jon

es
Computers and Technology
2 answers:
Kipish [7]2 years ago
8 0

To print the last name as smith,  first and last name as bill jones, use the polymorphism property of OOPs. For this, define a base class and derive the child class from the base class that have the same property as base class have. Set the last name as given name and in the child class assign this value to first name. By using pointer one can call the values. Here I have used stack to store and retrieve the values. The complete code is given below in the further explanation section.

Further explanation:

Code:

The C++ code to print the last name as smith, first and last name as bill jones is as below:

#include <iostream>

#include <vector>

#include <string>

using namespace std;

//Define class  

class BaseClass {

public:

void SetLastName(string givenName) {

lastName =givenName;

}

// Define the print function to print the first name and last name

protected:

string lastName;

};

class DerivedClass : public BaseClass {

public:

void SetFirstName(string givenName) {

firstName = givenName;

}

void PrintItem() {

cout << " first and last name : ";

cout << firstName << " " << lastName << endl;

};

private:

string firstName;

};

int main() {

BaseClass* BaseClassPtr = 0;

DerivedClass* DerivedClassPtr = 0;

vector<BaseClass*> itemList;

int i = 0;

BaseClassPtr = new BaseClass();

BaseClassPtr->SetLastName("Smith");

DerivedClassPtr = new DerivedClass();

DerivedClassPtr->SetLastName("Jones");

DerivedClassPtr->SetFirstName("Bill");

itemList.push_back(BaseClassPtr);

itemList.push_back(DerivedClassPtr);

for (i = 0; i < itemList.size(); ++i) {

itemList.at(i)->PrintItem();

}

return 0;

}

Output:

last name: smith

first and last name: bill jones

Learn more:

1. A company that allows you to license software monthly to use online is an example of ? brainly.com/question/10410011  

2. How does coding work on computers?  brainly.com/question/2257971 

Answer details:

Grade: College Engineering

Subject: Computer Science

Chapter: C++  Programming

Keyword:

C++, input, output, programming, statements,  loops, if, else, statements, firstname, lastname, base class, derive class, vector, print

ella [17]2 years ago
7 0
The question involves basic polymorphism. The following is the partial flow of the program.

baseItemPtr = new BaseItem();
baseItemPtr.setLastName("Smith");

derivedItemPtr = new DerivedItem();
derivedItemPtr.setLastName("Jones");
derivedItemPtr.setFirstName("Bill");

itemList.add(baseItemPtr);
itemList.add(derivedItemPtr);

for (i = 0; i < itemList.size(); ++i) {
itemList.get(i).printItem();
}

return;
You might be interested in
Dante has a worksheet shared with multiple users. He would like the ability to approve or reject changes that are made. Which fe
Gemiola [76]

Answer:

Data Consolidation.

Explanation:

7 0
2 years ago
Select the correct text in the passage.
aliina [53]

Answer: When was admitted, hospital authorities recorded his medical history. Then, placed in an ICU where his vital signs were constantly monitored.

Explanation: With the help of computers, medical histories are often kept in the computer for future reference. Machines are connected to computers to record vital signs.

4 0
2 years ago
The problem solving process begins by first ______ the problem.
alexandr402 [8]

Answer:

identifying/acknowledging

Explanation:

7 0
2 years ago
Scenario 1: Richman Investments provides high-end smartphones to several employees. The value of each smartphone is $500, and ap
vfiekz [6]

Answer:

a). SLE =$37.5

b). ARO =75

c). ALE = $2,812.5

Explanation:

a).Single loss Expectancy (SLE) is starting point in determining the single loss of an asset that will occur and calculated this;

SLE = asset value * exposure factor.

Asset value =$500,

Exposure factor is simply the percentage of asset lost.

In this case out of 1000 phones, 75 were damaged or loss.

In percentage;

75 ÷ 1000 =0.075, 0.075×100=7.5%(exposure factor).

Therefore,

SLE = $500×7.5%= $37.5.

b). ARO - Annual Rate of Occurrence is the number of times a threat on a single asset is expected to occur in one year.

In the case the damage or loss occured in 75 devices in one year.

c). ALE - Annualized loss Expectancy is the product of SLE and ARO.

Therefore;

ALE = $37.5 × 75 = $2,812.5.

3 0
2 years ago
To finish creating a design for the webpage, use one shape to cut away part of the other. Create a 700 pixel by 700 pixel square
Flauer [41]

Answer:

Explanation:

1. select the rectangle 1 layer and then select the rectangle tool in the left tool bar

2. in the option bar along the top of the UI, select the path operations drop-down and choose subtract front shape.

3. click anywhere on the thin, white rectangle shape on the left side of the document

4. in the create rectangle dialog box, type 700 px for the height and 700 px for the width.

5. click the checkbox that says from center to ensdure the new shape is created from the center of the rectangle 6. click ok

6 0
2 years ago
Other questions:
  • 2. Because technology is always changing, there are new applications being developed constantly. (1 point)
    9·2 answers
  • Why is continual user involvement a useful way to discover system requirements? Under what conditions might it be used? Under wh
    5·1 answer
  • What happened if the offshore team members are not able to participate in the iterations demo due to timezone/infrastructure iss
    12·1 answer
  • Security measures are sometimes described as a combination of physical, technical, and administrative (PTA) safeguards. Which of
    12·1 answer
  • (NumberFormatException)Write the bin2Dec(String binaryString) method to convert a binary string into a decimal number. Implement
    11·1 answer
  • Write a program that reads the lengths of the sides of a triangle from the user. Compute the area of the triangle using Heron's
    8·1 answer
  • Which among the following enhances WS-Security to facilitate a mechanism for issuing, renewing, and validating security tokens?
    13·1 answer
  • . Electricians will sometimes call ______ "disconnects" or a "disconnecting means."
    12·1 answer
  • Write a method so that the main() code below can be replaced by simpler code that calls method calcMilesTraveled(). Original mai
    11·1 answer
  • Write a class named Employee that has private data members for an employee's name, ID_number, salary, and email_address. It shou
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!