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
Using range(1,101), make two list, one containing all even numbers and other containing all odd numbers. How can I do this on Py
jeka94

Answer:

even = []

odd = []

for i in range(1,101):

if i % 2 == 0:

even.append(i)

else:

odd.append(i)

4 0
1 year ago
Design a flowchart or pseudocode for a program that accepts three numbers from a user and displays a message if the sum of any t
Keith_Richards [23]

Answer:

Hi there! Pseudocode is the process of writing out the high-level structure of the program in simple English terms which acts as a blueprint of how the program will work. The pseudocode for this question is written below.

Explanation:

Prompt user for input 1

Validate input 1

Prompt user for input 2

Validate input 2

Prompt user for input 3

Validate input 3

Perform checks:

If  

 1 and 2 equals 3

 Or

 1 and 3 equals 2

 Or

 2 and 3 equals 1

Display message to user

6 0
2 years ago
Mavis is considering signing up for a hosted enterprise software solution for her small business. She recognizes that an advanta
babymother [125]

Since Mavis is considering signing up for a hosted enterprise software solution for her small business, an advantage of the software is <u>lower cost</u>.

A hosted enterprise software solution is typically hosted off-site and in a private server that is owned by a third party. It's vital for organizations as it can be used in managing daily business activities.

The advantages of a hosted software model include reliable backup, reduction in IT costs, scalability of computing resources, etc. It is also necessary for managing critical business processes.

Read related link on:

brainly.com/question/25526416

6 0
1 year ago
Which security control is most helpful in protecting against eavesdropping on wireless LAN (WLAN) data transmissions that would
3241004551 [841]

Answer:

D. Applying strong encryption

Explanation:

Strong cryptography or cryptographic-ally strong are general terms applied to cryptographic systems or components that are considered highly resistant to cryptanalysis.One cryptographic cipher has been mathematically proven to be unbreakable when it is used correctly, but it is only very rarely used.

6 0
2 years ago
Which of the following type of online advertising intermediaries decide the placement and pricing of online display ads by using
dedylja [7]

Answer:

e. Ad exchanges

Explanation:

The ad exchange is a form of an online strategy that promotes the transaction of media advertising inventory from numerous ad networks. Here, prices for the inventory are defined through the supply and demand in a real-time auction system.

Hence, in this case, the correct answer is that the type of online advertising intermediaries is generally referred to as Ad Exchanges.

5 0
2 years ago
Other questions:
  • Which is true for a hosted blog software
    15·2 answers
  • Write an if-else statement that prints "Goodbye" if userString is "Quit", else prints "Hello". End with newline.
    11·2 answers
  • A(n) ______of the audio or video clip makes the content easily accessible to people with hearing disabilities.
    10·2 answers
  • Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both doubles) as input, and output the g
    12·2 answers
  • In your own words, what is pair-programming? What is the role of the driver? What is the role of the navigator? What are some be
    15·1 answer
  • 1. Write the Python code needed to perform the following:2. Calculate state withholding tax (stateTax) at 6.5 percent3. Calculat
    9·1 answer
  • In this problem, we want to compare the computational performance of symmetric and asymmetric algorithms. Assume a fast public-k
    11·1 answer
  • Describe the indicators and hazards of a metal deck roof fire in an unprotected steel joist warehouse as well as the techniques
    6·1 answer
  • 15 points. Please give an actual answer and not some random thing. this is not just free points. Correct answer will receive bra
    12·2 answers
  • How can migrating to an enterprise platform solution help a business improve employee productivity?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!