/*
* Copyright (c) 2013, 烟台大学计算机学院
* All rights reserved.
* 作 者:马广明
* 完成日期:2014 年 3 月 11 日
* 版 本 号:v1.0
* 输入描述: 无
* 问题描述:运用面向对象输出
*/
#include <iostream>
#include<cstring>
using namespace std;
class Student
{
public:
void set_date(int n,char *p,char s);
void display();
private:
int num;
char name[20];
char sex;
};
void Student::set_date(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_date(1,"He",'f');
stud2.set_date(2,"She",'m');
stud1.display();
stud2.display();
return 0;
}
面向对象输出
最新推荐文章于 2021-09-29 13:02:59 发布