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
JulsSmile [24]
3 years ago
8

Define a member function PrintAll() for class PetData that prints output as follows. Hint: Make use of the base class' PrintAll(

) function.
Name: Fluffy, Age: 5, ID: 4444
Given this code:

#include
#include
using namespace std;

class AnimalData {
public:
void SetName(string givenName) {
fullName = givenName;
};
void SetAge(int numYears) {
ageYears = numYears;
};
// Other parts omitted

void PrintAll() {
cout << "Name: " << fullName;
cout << ", Age: " << ageYears;
};

private:
int ageYears;
string fullName;
};

class PetData: public AnimalData {
public:
void SetID(int petID) {
idNum = petID;
};

// FIXME: Add PrintAll() member function

/* Your solution goes here */

private:
int idNum;
};

int main() {
PetData userPet;

userPet.SetName("Fluffy");
userPet.SetAge (5);
userPet.SetID (4444);
userPet.PrintAll();
cout << endl;

return 0;
}
Computers and Technology
1 answer:
PilotLPTM [1.2K]3 years ago
8 0

Answer:

Following are the program in the C++ Programming Language.

//set header file

#include <iostream>

//set header file for string

#include <string>

//set namespace

using namespace std;

//define class

class AnimalData

{

//set access modifier

public:

//define function

void SetName(string givenName)

{

//initialize the value of function's argument

fullName = givenName;

};

//define function

void SetAge(int numYears)

{

//initialize the value of function's argument

ageYears = numYears;

};  

//here is the solution

//define function

void PrintAll()

{

//print output with message

cout << "Name: " << fullName<<endl;

//print output with message

cout << "Age: " << ageYears<<endl;

};

//set access modifier

private:

//set integer data type variable

int ageYears;

//set string data type variable

string fullName;

};

//define class and inherit the parent class

class PetData: public AnimalData

{

//set access modifier

public:

//define function

void SetID(int petID)

{

idNum = petID;

};

//override the function for print id

void PrintAll()

{

AnimalData::PrintAll();

cout << "ID: " <<idNum ;

};

//set access modifier

private:

//set integer type variables

int idNum,fullName,ageYears;

};

//define main method

int main()

{

//create object of the child class

PetData userPet;

//call function through object

userPet.SetName("Fluffy");

//call function through object

userPet.SetAge (5);

//call function through object

userPet.SetID (4444);

//call function through object

userPet.PrintAll();

cout << endl;

return 0;

}

<u>Output</u>:

Name: Fluffy

Age: 5

ID: 4444

Explanation:

<u>Following are the description of the program</u>:

  • Set required header file and namespace.
  • Define class 'AnimalData' and inside the class, set integer data type variable 'ageYears', string data type variable 'fullName'.
  1. Then, define function 'SetName()' with string data type argument 'givenName' and initialize the value of argument in the string variable.
  2. Then, define function 'SetAge()' with integer data type argument 'numYears' and initialize the value of the argument in the integer variable.
  3. Define function 'PrintAll()' to print the value of the following variables with message.
  • Define class 'PetData' and inherit the parent class in it, then set integer data type variable 'idNum'.
  1. Then, define function 'SetID()' with integer data type argument 'petID' and initialize the value of the argument in the integer variable.
  2. Override the function 'PrintAll()' to print the value of the following variable with message.

Finally, define main method and create the object of the child class, then call the following functions through the class object.

You might be interested in
You configure a Windows laptop for a user who frequently travels and must connect to several wireless networks. While at a new b
aliina [53]

Answer:

Turn on file and printing sharing for all networks.

Explanation:

Windows has several security features when connecting to a network. In the control panel, you can access to Network and internet > Network and sharing center > Advanced sharing options. There you will see 3 different profiles, one for private networks, one for guest or public networks, and one for all networks.

You should take one of the 2 options. Enable file and printer sharing for all networks, so he can just print without doing anything more. Or keeping the print sharing just for private networks, and adding his new branch office's network to the private networks list.

8 0
3 years ago
Apakah maksud input dan output ?<br>​
Nana76 [90]

INPUT ADALAH KOMPONEN PIRANTI KERAS YANG MEMUNGKINKAN USER ATAU PENGGUNA MEMASUKKAN DATE KE DALAM KOMPUTER ATAU BISA JUGA DISEBUT SEBAGAI OUTPUT ADALAH DATA YANG TELAH DIPROSES MENJADI BENTUK YANG DAPAT DIGUNAKAN!

4 0
3 years ago
Which format is used for audio files?
Arisa [49]
Audio format is used for audio files
7 0
3 years ago
Read 2 more answers
Website reputation is an important part of page quality (PQ) rating. Reputation can justify the Highest rating and the Lowest ra
Sergio039 [100]

Answer:

The given statement is false.

Explanation:

  • A Website reputation seems to be a built-in feature or tool. It retains knowledge about users, through visiting pages. The committed resources for this site depending on either the website as well as the basic details about its design.
  • The reputation including its Website has been used to strengthen the safety of phishing attacks or malicious content.

Therefore the solution given above is the right one.

4 0
3 years ago
What are some industries of aerodynamics and hydrodynamics? explain each one in detail.
maria [59]
Aerodynamic- Wind turbine, computational fluid dynamics, and Wind power

Hydrodynamics- Computational Fluid Dynamics, Hydraulics, and Microfluidics
3 0
2 years ago
Read 2 more answers
Other questions:
  • In the belt drive mechanism, what happens when the belt is crossed instead of open?
    14·1 answer
  • When using a file name you have to use only lower case letters<br>true or false
    11·1 answer
  • Explain what it means to have good file management skills.
    10·1 answer
  • PLEASE HELPPPPPPPPPPPPPPPPPPPPPPPP LASTTTTT QUESTION FINALLLY :)))))
    12·1 answer
  • Login
    11·1 answer
  • 1. Which sentence best expresses the main idea
    12·1 answer
  • 7.3 Code Practice edhesive
    12·2 answers
  • 23. ____________ is a slide that is used as the base design theme for other slides.​
    11·1 answer
  • Dynamics
    11·1 answer
  • Question 7 Consider the following code:
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!