Thread: Need help get this working

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    45

    Need help get this working

    It's probably an easy program to fix but as a newbie I'm having trouble understanding the concept of class.

    I'm supposed to 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.

    This is what I did so far, but I'm having trouble running it.
    Code:
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    
    using std::cout;
    using std::cin;
    using std::endl;
    using namespace std;
    
    class personType
    {
    public:
        void print() const;    
        void setName(string first, string last); 
       void getName(string& first, string& last); 
       personType(string first, string last);  //Constructor with parameters
    
    private:
       string firstName; //store the first name    
       string lastName;  //store the last name};
    };
    int Main ()
    {
    	personType();   	 //Default constructor;
    	{
      	     string firstName; //store the first name    
    	    string lastName;  //store the last name
    	}
    	 void personType::print() 
    	 {
    	cout<<firstName<<" "<<lastName;
    	 }
                    void personType::setName(string first, string last)
                     {
    		firstName = first;
    		lastName = last;
                      }
    
    return 0;
    }
    If anyone can explain what I'm doing wrong I would greatly appreciate it.
    Thanks
    Last edited by flicka; 10-22-2005 at 08:55 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function not working
    By sloopy in forum C Programming
    Replies: 31
    Last Post: 11-12-2005, 08:08 PM
  2. Program Not working Right
    By raven420smoke in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2005, 03:21 AM
  3. Trying to eject D drive using code, but not working... :(
    By snowfrog in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2005, 07:47 PM
  4. x on upper right corner not working
    By caduardo21 in forum Windows Programming
    Replies: 1
    Last Post: 02-20-2005, 08:35 PM
  5. cygwin -> unix , my code not working properly ;(
    By CyC|OpS in forum C Programming
    Replies: 4
    Last Post: 05-18-2002, 04:08 AM