Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2009
    Posts
    8

    Unanswered: c++ class problems

    Hello!
    Can someone help with this simple class. I'm getting a bunch of errors. What am I doing wrong?

    thanks,
    Dave
    -------------
    //Student.h
    class Student
    {
    public:

    //initialize default constructor
    Student(const char ln[]="",const char fn[]="", int a[]=0);

    void setLastName(const char ln[]);
    void setFirstName(const char fn);
    void setAge(int a[]=0);

    const char getLastName() const;
    const char getFirstName() const;
    int getAge() const;

    private:
    char lname[25]; 25 characters max for last name
    char fname[25]; 25 characters max for first name
    int age[3]; 3-digit max for age
    }

    //Student.cpp
    //default constructor
    Student:tudent(const char ln[], const char fn[], int a[])
    {
    setLastName(ln);
    setFirstName(fn);
    setAge(a);

    }

    void Student::setLastName(const char ln[])
    {
    if (lname != NULL) //if last name has garbage
    delete[] lname; //clear it

    lname = new char[strlen(ln)+1];
    assert (lname != NULL);
    strcpy (lname, ln);
    }

    void Student::setFirstName(const char fn[])
    {
    if (fname != NULL) //if first name has garbage
    delete[] fname; //clear it

    fname = new char[strlen(fn)+1];
    assert (fname != NULL);
    strcpy (fname, fn);
    }


    void Student::setAge(int a)
    {
    age=a;
    }


    const char Student::getLastName()const
    {
    return lname;
    }
    const char Student::getFirstName()const
    {
    return fname;
    }

    int Student::getAge()const
    {
    return age;
    }

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    It does help if you provide details of the errors......
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Mar 2009
    Posts
    8
    after 3 long hours of frustration, i finally got it to compile without errors.

    thanks again for the reply.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •