Thread: Help ~~ (please!)

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    1

    Help ~~ (please!)

    Create a person class to represent a person. (You may call the class personType.) To simplify things, have the class have 2 variable members for the person's first and last name. Include 2 constructors. One should be a default constructor and the other should be one with parameters. Include respective functions for:
     setting the name,
     getting the name, and
     printing the name on the screen.

    Have your main program call these functions to demonstrate how they work.
    Explain how you can replace both constructors with one constructor by using a single constructor with default parameters.

    Code:
    #ifndef personType_H
    #define personType_H
    #include <string> 
    
    using namespace std; 
    
    class personType 
    {
    public: 
    	personType( const string & ,  const string & ); 
    	
    	void setFirstname (const string & ); 
    	string getFirstname() const; 
    
    	void setLastname (const string & );
    	string getLastname() const; 
    
    private: 
    	string firstName; 
    	string lastName; 
    }; 
    
    #endif
    
    
    #include <iostream> 
    #include "personType.h" 
    
    using namespace std; 
    
    //constructor 
    personType::personType ( const string &first, const string &last )
    
    {
    	firstName = first; 
    	lastName = last; 
    }
    
    // set first name 
    void personType::setFirstName ( const string &first ) 
    
    {
    	firstName=first; 
    }
    string personType::getFirstName() const
    {
    	return firstName; 
    }
    
    void personType::setLastName ( const string &last) 
    {
    	lastName=last; 
    }
    
    void personType::print() const
    {
    	cout<<"Who's your Daddy?:" << firstName << '' << lastName
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    OK, and your question is what exactly?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472

    .

    cout<<"Who's your Daddy?:" << firstName << '' << lastName
    Does this mean you are pleased because you think you nailed the assignment? And that is why you posted without any question / problem?

    Or does your program literally request the name of the users Father?

    Without any other info then its hard to help
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. run-time errors ~~
    By crazy in forum C Programming
    Replies: 14
    Last Post: 01-01-2008, 09:44 AM
  2. passing counters between function
    By BungleSpice in forum C Programming
    Replies: 18
    Last Post: 02-21-2004, 06:16 PM