N
nvangogh
Hi,
I am reading c++ primer.
Exercise 7.4:
Write a class named person that represents the name and address of a
person. Use a string to hold each of these elements. Subsequent
exercises will incrementally add features to this class.
Exercise 7.5:
Provide operations in your person class to return the name and address.
Should these functions be const? Explain your choice.
So I have completed exercise 7.5 in this way:
// a class named person with operations
#include <string>
class Person
{
std::string name() const { return first_name;}
std::string addr() const { return address;}
// data members
std::string first_name;
std::string address;
};
Is this correct?
I am reading c++ primer.
Exercise 7.4:
Write a class named person that represents the name and address of a
person. Use a string to hold each of these elements. Subsequent
exercises will incrementally add features to this class.
Exercise 7.5:
Provide operations in your person class to return the name and address.
Should these functions be const? Explain your choice.
So I have completed exercise 7.5 in this way:
// a class named person with operations
#include <string>
class Person
{
std::string name() const { return first_name;}
std::string addr() const { return address;}
// data members
std::string first_name;
std::string address;
};
Is this correct?