1answer.
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]
3 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]3 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]3 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
What form of contacts can be shared in Outlook 2016?
ArbitrLikvidat [17]

Answer:

shared contacts

Explanation:

5 0
3 years ago
Read 2 more answers
This standard library function returns a random oating-point number within a specied range of values.
IgorLugansk [536]

Answer:

Uniform

Explanation:

The uniform is a standard library function in python that returns a random floating number withing a specified range of values. Floating numbers which are integer numbers separated by a dot or decimal point from the fractional part. It is part of the random module. it is implemented as

Because it is defined in the random module, random module needs to be imported for uniform to be available for use.

import random

random.uniform(lowest point or highest number, highest point or highest number)

5 0
3 years ago
1-5 Safety measures in the use of kitchen tools and equipment.​
gladu [14]

Answer:

Safety measures are as follows;

Explanation:

  • Hold the delicate instruments cautiously to use them.
  • Require appropriate use of the equipment in the kitchen.
  • Users should remove these defective instruments or discard of them.
  • During and before use, check that perhaps the resources that will be used are indeed safe.
  • In a cold and dry spot, all equipment must be kept.
4 0
3 years ago
I don’t understand how to make a hyperlink or put an image in an html file
Mademuasel [1]

To use image as a link in HTML, use the <img> tag as well as the <a> tag with the href attribute. The <img> tag is for using an image in a web page and the <a> tag is for adding a link. Under the image tag src attribute, add the URL of the image. With that, also add the height and width.

-tutorialspoint

8 0
3 years ago
On an LG phone, will a factory reset stop a message from sending/cancel a message? ​
daser333 [38]

Answer:

No

Explanation:

Your SIM card will still have the information that you're service provider needs to stop allow you to text

3 0
3 years ago
Other questions:
  • All of the following statements correctly describe an advantage or disadvantage associated with the use of Monte Carlo Analysis
    9·1 answer
  • Without a(n) ____, a computer cannot function.
    8·2 answers
  • What is the difference between images and pictures
    6·1 answer
  • Byron wants to use Quick Parts to insert reusable content into a company Word document. Where will he access this option? Design
    11·2 answers
  • 1. Give one reason why data is represented in binary in a computer
    15·1 answer
  • Suppose I create a new kind of Java object, called "Kangaroo". Further suppose that at any given time, all instances of this new
    6·1 answer
  • Which of the following is something all models use to determine relationships?
    7·1 answer
  • Complete the code to finish this program to analyze the inventory for a store that sells purses and backpacks.
    7·1 answer
  • The TCP congestion control measure techniques fall into two categories: retransmission timer management and ________ management
    13·1 answer
  • What is the difference between an html opening tag and a closing tag?.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!