i need ur help

Discussion in 'C' started by raz, Oct 30, 2009.

  1. raz

    raz New Member

    Joined:
    Oct 30, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    hello all..
    i have a programming homework for sunday, wish some will help me with this :)

    define a class person type to store the name of person and
    1: set the first name only
    2: set the last name only
    3: store and set the middle name
    4: check whether a given first name is the same as the first name of this person
    5: check whethter a given last name is the sane as the last name of this person


    write the definitions of the member function to implement the operations for this class. also write a program to test various operations on this class.


    plz helppppp
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Help you with it: yes. Do it for you: no.

    How far have you got with it and where are you stuck?
     
  3. dennyphilip

    dennyphilip New Member

    Joined:
    Oct 18, 2009
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    bengaluru
    u didn't specify the language !!
    i am just am going to try and use java here

    Code:
    //we declare our class person here
    class person
       {
        String first_name = new String(); //first name
        String middle_name = new String(); //middle name
        String last_name = new String(); //last name
       
       // constructor to create the object without inintialization
        person()
           {
           }
        //constructor which takes the first name middle name and last name
        person(string fname, string mname, string lname)
           {
             first_name =fname; //sets the first name
             middle_name =mname; //sets the middle name
             last_name =lname;  //sets the lastname
            }
    
       public void setfname(string fname)
         {
         first_name =fname; //sets the first name
         }
    
       public void setmname(string mname)
         {
         middle_name =mname; //sets the midddle name
         }
    
       public void setlname(string lname)
         {
         last_name =lname; //sets the last name
         }
      
         //method to check first name
         public void fname_check(string chk_firstname)
         {
         if (chk_firstname.equals(first_name))
            {
             System.out.println("The first name check : match")
             }
          else
            {
             System.out.println("The first name check: mismatch")
             }
        
         }
    
          //method to check last name
       public void lname_check(string chk_lastname)
         {
         if (chk_lastname.equals(last_name))
            {
             System.out.println("The last name check : match")
             }
          else
            {
             System.out.println("The last name check: mismatch")
             }
            }
    
        }
    
    class my class // main class
       {
       public static void main(string[] args)
         {
           string s1 = "jhn" 
           string s2 = "f"
           string s3 = "knnedy"
            person person1 = new person(s1,s2,s3);
            s1 = "john";
            person1.setfname(s1); //sets the first name to john
             s2 = "Fitzgerald";
            person1.setmname(s2);  //sets the middle name
             s3 = "kennedy";
            person1.setfname(s3);  //sets the last name
            person1.fname_check(s3); //this is true
            s2 ="f";
            person1.lname_check(s2); // this is false
         }
       }

    // please check the code ... i haven't checked it.. but this is one way of doing it
    // and last but not least dont forget to add the import statements at the start :)
    //as xpi0t0s said copying this wont do u good please work on it ...
     
    Last edited by a moderator: Oct 31, 2009
  4. raz

    raz New Member

    Joined:
    Oct 30, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    thank u so much
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice