Unit3--problem1掌握对象——动向

/*Univercity:烟台大学
*@Class</A>计134~4
*@Author:薛富磊
*@Time:2013-12-11
*@Function:掌握对象程序结构

 *@Args:
*@Return:
*/

#include <iostream>
#include <cstring>
using namespace std;
class Student
{
private:
    int num;
    char name[20];
    char sex;
public:
    void set_data(int n, char *p,char s)
    {
        num=n;
        strcpy(name,p);
        sex=s;
    }
    void display( )
    {
        cout<<"num: "<<num<<endl;
        cout<<"name: " <<name<<endl;
        cout<<"sex: " <<sex<<endl;
    }
};
int main()
{
    Student stud1,stud2;
    stud1.set_data(1,"He",'f');
    stud2.set_data(2,"She",'m');
    stud1.display();
    stud2.display();
    return 0;
}
Unit3--problem1掌握对象——动向_第1张图片
#include <iostream>
#include <cstring>
using namespace std;
class Student
{
public:
    void set_data(int n, char *p,char s);
    void display( );
private:
    int num;
    char name[20];
    char sex;
};
void Student::set_data(int n, char *p,char s)
{
    num=n;
    strcpy(name,p);
    sex=s;
}
void Student::display( )
{
    cout<<"num: "<<num<<endl;
    cout<<"name: " <<name<<endl;
    cout<<"sex: " <<sex<<endl;
}
int main()
{
    Student stud1,stud2;
    stud1.set_data(1,"He",'f');
    stud2.set_data(2,"She",'m');
    stud1.display();
    stud2.display();
    return 0;
}


Unit3--problem1掌握对象——动向_第2张图片

心得体会:

                  马上见对象

                  不要害羞哟

                   掌握对象趋势

                   provate和public

                   区别分家哟亲!!!

你可能感兴趣的:(Unit3--problem1掌握对象——动向)