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]
2 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]2 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
What does the following loop do?
Vinvika [58]

Answer:

Option 3: Counts the even elements in a.

Explanation:

The for-loop will traverse through each of the number in array, <em>a</em>. Within the for-loop, each number is modulus with 2 to check if it is equal to zero. Any number modulus 2 that result in zero is an even number. Based on this condition, the <em>x </em> count value will be incremented by one whenever an even number is detected from the array.

At last, display the <em>x</em> count value after completion of the for-loop.

8 0
3 years ago
Create a query that shows columns employee last name, job title and hire date for those employees who joined the company on or a
yawa3891 [41]

Answer:

SELECT last_name, job_title, hire_date FROM employee WHERE hire_date>="01-12-2016" AND job_title != "STOCK CLERK" ORDER BY job_title DESC;

Explanation:

The SQL code queries the employee table returning records of the last_name, job_title, and hire_date columns matching the employees hired on or after December 2016 and job titles that are not stock clerks in the employee table.

The WHERE and AND clause is responsible for the condition while the ORDER BY clause returns the query result in the of the job title in descending order.

3 0
2 years ago
Hiiiiiiiiihwdawdfgthnythgrfergthyjuhgfd
Lilit [14]

Answer:

Your answer would be gas.

Explanation:

Steam is just water just evaporated.

3 0
2 years ago
Read 2 more answers
JAVA Question!
dybincka [34]
I don't see any error on your code, everything is well written and simple. Except trying putting PUBLIC on your Class displayer. If you encounter the same problem again try to rebuild your whole code and try to recompile the whole code. Even try restarting your personal computer.
5 0
3 years ago
Write the interface (.h file) of a class Counter containing: A data member counter of type int. A data member named counterID of
OlgaM077 [116]

Explanation:

See the attached image for The interface (.h file) of a class Counter

8 0
3 years ago
Other questions:
  • You need to put cabling for connecting two new computers in a room, which did not have any network infrastructure. Because of th
    9·2 answers
  • Which of the following is a Microsoft solution that runs on a Microsoft Terminal Services server but appears, to end users, as i
    10·1 answer
  • A user calls the help line and ask for some help installing a new keyboard. He isn't sure how to plug the keyboard into the comp
    15·1 answer
  • If you are trying to improve your budget and spending, which option would save you the most money?
    13·2 answers
  • Write a function namedmake_complex that stores its twoarguments (both of type double) in acomplex structure, then returns thestr
    12·1 answer
  • A program that doesn’t work properly needs to be debugged. true or false
    8·1 answer
  • What is the setting an alarm clock output??
    10·1 answer
  • Juhfvehrfwhedfhwkefhkujhiuyuiyuiyiyh
    6·1 answer
  • To behave ethically means
    7·1 answer
  • 3. It is important to make certain that your employees are aware of the work ethic
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!