Sunday, May 11, 2014

simple class

Newsgroup: comp.lang.c++

Subject: simple class

From: nvangogh <nvangogh@...>

Date: Fri, 09 May 2014 14:53:51 +0100



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?









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1l7kTAL

View all the progranning help forums at:

http://ift.tt/1dP9txN

No comments:

Post a Comment