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
Trying to make the baseplate red and turn off can collide then the game waits 5 seconds and turns on can collide, making the bas
kenny6666 [7]

Answer:

Explanation:

yes

but dont forget to call makeBasePlateGreen

maybe you would call it at the end of the program?

by the way you have a typo at the end

make the O lowercase

myBlasePlate.BrickColor = BrickColor.Green()

and then add this to the end

makeBasePlateGreen()

so you call the function and actually use it.

4 0
3 years ago
HELP!!! What would var d=?
sergiy2304 [10]

Answer:

51015

Explanation:

Var b is a string, and it'll treat addition like <em>string concatenation </em>(aka just adding a message.) Since it's concatenation, it'll then turn the numbers/integers into strings.

This kind of behavior might be different depending on the language, though. Some languages might not allow this. (For example, C and C++)

7 0
3 years ago
Call 334-399-4201 to annoyed my mom
yaroslaw [1]

Answer: why...

Explanation:

3 0
4 years ago
A developer needs to create a visualforce page that displays case data. The page will be used by both support reps and support m
shutvik [7]

Answer:

B. Use a new support manager permission sets

Explanation:

According to the requirements, field level security is required so, 1st options is not suitable because it may reduce the maintenance cost but increase the risk of security.

By creating a separate page for each of the two, it will leads to increase in the maintenance cost of the system. So <u>Option C</u> is also not suitable.

Option B is more Suitable as compared to others, that <em>Create a new support manager permission set</em>, with the help of this, both of Support rep and Support manager can visualize their required information with the help of support manager permission. This solution will not compromise the security and not increase the maintenance cost.

7 0
3 years ago
When is an original work considered public domain?
Blababa [14]

The correct answer isn’t really a choice shown. I would choose D because if a work doesn’t have a copyright symbol that doesn’t mean it’s in the public domain. In a real life situation it would be best to ask the creator before you use their work. If they say it’s in the public domain then you’re fine, but even if they say you can use it that doesn’t mean it’s in the public domain, it just means that you have permission to use it.

7 0
3 years ago
Other questions:
  • It is generally safe to provide your social security number to
    7·2 answers
  • I need help answering these questions!
    11·1 answer
  • Stress results from _______. A. Outside stimulus b. Internal stimulus c. Outside calm d. Internal calm
    12·2 answers
  • What tool is provided in Windows to facilitate sharing data objects between applications and computers?
    8·1 answer
  • Computer design replaced ______________
    6·1 answer
  • Which command can be used to find errors on a hard drive​
    6·1 answer
  • Activity
    7·1 answer
  • What does IDLE stand for
    11·2 answers
  • Magbigay ng ibang produkto na ginagamitan ng kasanayan ng basic sketching shading at outlining ​
    12·1 answer
  • Explain the concepts of GIGO—garbage in, garbage out. Why do you think it’s a helpful concept in coding? How do you think it can
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!