Not really understanding the concept, why did they use "Person *pPerson = new Person("Susan Wu", 32);" and where did ".length();" come from? Also when "Rectangle *pRect" is put into a parameter, pRect is pointing at the address of the object rect, right?
#include <iostream>
#include <string>
using namespace std;
class Person
{
private:
string name;
int age;
public:
Person(string name1, int age1)
{
name = name1;
age = age1;
}
int getAge() { return age; }
string getName(){ return name; }
};
struct Rectangle
{
int width, height;
};
void magnify(Rectangle *pRect, int mfactor);
int lengthOfName(Person *p);
void output(Rectangle *pRect);
int main()
{
Rectangle rect;
rect.width = 4;
rect.height = 2;
cout << "Initial size of rectangle is ";
output(&rect);
magnify(&rect, 3);
cout << "Size of Rectangle after magnification is ";
output(&rect);
Person *pPerson = new Person("Susan Wu", 32);
cout << "The name " << pPerson->getName()
<< " has length " << lengthOfName(pPerson) << endl;
return 0;
}
void output(Rectangle *pRect)
{
cout << "width: " << pRect->width << " height: " << pRect->height << endl;
}
int lengthOfName(Person *p)
{
string name = p->getName();
return name.length();
}
void magnify(Rectangle *pRect, int factor)
{
pRect->width = pRect->width * factor;
pRect->height = pRect->height * factor;
}