Code-Student: Public Person

Source: Internet
Author: User
# Include <iostream>
# Include <cstring>
Using namespace STD;
Class person
{
Char * Name;
Int age;
Char * address;
Public:
Person ();
Person (char * Name, char * address, int age );
~ Person ();
Void introduce ();
};


Class student: Public Person
{
Char * studentno;
Public:
Student ();
Student (char * Name, char * address, int age, char * studentno );
~ Student ();
Void introduce ();
};


Person: Person ()
{
Cout <"calling the person constructor" <Endl;
}

Person: Person (char * Name, char * address, int age)
{
This-> age = age;
This-> name = new char [strlen (name) + 1];
This-> address = new char [strlen (Address) + 1];
Strcpy_s (this-> name, strlen (name), name );
Strcpy_s (this-> address, strlen (address), address );
}

Person ::~ Person ()
{
Cout <"calls the person destructor" <Endl;
}
Void person: Introduce ()
{
Cout <* P <Endl;
Cout <"name is" <name <Endl;
Cout <"Age is" <age <Endl;
Cout <"address is" <address <Endl;
}


Student: Student ()
{
Cout <"Call student's constructor \ n ";
}

Student: Student (char * Name, char * address, int age, char * studentno): Person (name, address, age)
{
This-> studentno = new char [strlen (studentno) + 1];
Strcpy_s (this-> studentno, strlen (studentno), studentno );
}
Student ::~ Student ()
{
Cout <"calls student's destructor \ n ";
}

Void Student: Introduce ()
{
Person: Introduce ();
Cout <"studentno is" <studentno <Endl;
}
Int main ()
{
Return 0;
}
Author: Lin yufei
Source: http://www.cnblogs.com/zhengyuhong/
The copyright of this article is shared by the author and the blog Park. You are welcome to repost it. However, you must keep the author's information without the author's consent and provide the original article connection clearly on the article page.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.