#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<<endl;
}
int main()
{
Student stud1,stud2;
stud1.set_data(1,"John",'f');
stud2.set_data(2,"Mary",'m');
stud1.display();
stud2.display();
return 0;
}
C++语言基础 例程 基于对象的程序的执行过程
原创sxhelijian ©著作权
©著作权归作者所有:来自51CTO博客作者sxhelijian的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
java和C++之间的调用
java和C++之间的调用其实和C差不多,只是有几点不一样 区别: 包名.类名.h 这个头文件必须有且必须在JNI目录里 后缀不需要修改
java 头文件 #ifdef #endif #ifndef -
微观的C/C++编译执行过程
前言 C语言 --》 .exe几个过程: 预处理:展开
c语言 c++ 编译器 目标文件 可执行文件 -
c++执行python脚本 c++ 调用python
请注明转自:想造轮子的刘大胆:C++调用python方法及环境配置(Windows环境、VS工具) c++和python使用混合编程,有四种方式来实现:(1)C++调用python(2)直接调用python文件并执行(3)3.使用Cpython:这是一个第三方库,可以将python代码直接变成c代码(4)使用pybind11库(建议),网址:pybind/pybind1 在这里描述VS写C++中调
c++执行python脚本 c++ 调用python c++调用python c调用system curl finalize方法