-
c++ program
dear sir,
please send answer for the following program
write a program with a name class that can store any name in three parts
such as first name,middle name,surname. Use overloaded functions to display
the full name in any of several formats different formats such as the following:
John Paul Doe
J.P.Doe
Doe, John Paul
and any other formats you desire.
-
Re: c++ program
Well, your class interface could look something like this:
class Person
{
private:
std::string first;
std::string middle;
std::string last;
public:
Person(); //default ctr
Person(const std::string&, const std::string &, const std::string&); //ctr
//setter
void setfirst(const std::string&);
void setmiddle(const std::string&);
void setlast(const std::string&);
//getter
inline std::string getfirst() const {return first;}
//similar middle, last
std::string yieldname(const int formatflag) const;
}
This way you specify a format flag in a call to yieldname()
Chris
jithesh wrote:
> dear sir,
> please send answer for the following program
> write a program with a name class that can store any name in three parts
> such as first name,middle name,surname. Use overloaded functions to display
> the full name in any of several formats different formats such as the following:
>
> John Paul Doe
> J.P.Doe
> Doe, John Paul
> and any other formats you desire.
--
Ascent Software Limited Registered in Scotland: SC201671
www.ascent.zetnet.co.uk Bank Of Scotland Buildings
Lerwick, Shetland, ZE1 0EB
-
Re: c++ program
Agree, with only the following amplification....
Christopher Thomas McGinlay <ascent@zetnet.co.uk> wrote:
>Well, your class interface could look something like this:
>
>class Person
>{
>private:
> std::string first;
> std::string middle;
> std::string last;
>
>public:
> Person(); //default ctr
> Person(const std::string&, const std::string &, const std::string&); //ctr
>
>//setter
> void setfirst(const std::string&);
> void setmiddle(const std::string&);
> void setlast(const std::string&);
>
IMHO: If you are going to use "setters" then they should return a reference
to Person:
Person& setfirst(const std::string&);
Person& setmiddle(const std::string&);
Person& setlast(const std::string&);
>//getter
> inline std::string getfirst() const {return first;}
> //similar middle, last
> std::string yieldname(const int formatflag) const;
>}
>
>This way you specify a format flag in a call to yieldname()
>
>Chris
>
>jithesh wrote:
>
>> dear sir,
>> please send answer for the following program
>> write a program with a name class that can store any name in three parts
>> such as first name,middle name,surname. Use overloaded functions to display
>> the full name in any of several formats different formats such as the
following:
>>
>> John Paul Doe
>> J.P.Doe
>> Doe, John Paul
>> and any other formats you desire.
>
>
>--
>Ascent Software Limited Registered in Scotland: SC201671
>www.ascent.zetnet.co.uk Bank Of Scotland Buildings
> Lerwick, Shetland, ZE1 0EB
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks