Programming Q uestion: a) Write the definition of a class“Person”that contains a
ID: 3849160 • Letter: P
Question
Programming
Q
uestion:
a)
Write the definition of a class“Person”that contains a“name”field oftype String and an“age”feld of type int. Then define two classes,“Dancer”and“DonutMaker”,that extend“Person”such that“Dancer”has an additionalfield called“company”of type String, and“DonutMaker”has an additionalfield called“shop”of type String.
b)Define a class“Counting”that contains a method“DancersAges(Person[a])”, such that DancersAgesreturns the sum of the agefields of the “Dancer”objectsreferenced by the array a. There is no need for an object of class“Counting” to becreated in order for“DancersAges”to be called.
c)Define a class“MainClass”containing the“main”method (for the entireprogram).The “main”should create an array with 10 elements, namely 5“Dancer”objects and 5“
DonutMaker”objects in alternating order, and passthe array to the“DancersAges”method, above. You can initialize the fieldsof the objects as you see fit.
Explanation / Answer
a)
#include <iostream>
#include<map>
#include<stack>
#include<vector>
#include<algorithm>
#include <fstream>
#include<cstdlib>
using namespace std;
class person
{
public:
string name;
int age;
}
class Dancer:public person
{
string company;
}
class DonutMaker:public person
{
string shop;
}
int main()
{
return 0;
}
b)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.