第二个面向对象的程序
来源:互联网 发布:淘宝网中老年唐装 编辑:程序博客网 时间:2024/06/05 04:56
Copyright (c) 2013, 烟台 All rights reserved. 作者:石晓涛 完成日期:2013 年3月15日 版本号:v1.0 输入描述: 问题描述: 程序输出: 算法设计:
#include <iostream> 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; }