正在加载图片...
面向对象程序设计 例1:定义并实现类 student #include<iostream. h> class student∥定义类 i public 类的公有成员 void input(float s)score=s 堂提要 id modify(float s)score=s; 1 void display) 第6章类与对象 i cout <<"n score: <<score;) 6.1类定义与对象声明 private:类私有成员 62对象的使用 float score 63对象成员 64友员 friend void main()∥主函数 6.5静态成员和对象组 student ss;∥声明对象 织 SS. Input(88.5);∥调用成员函数 6.6模板 6.7应用举例 SS display ;i第 6 章 类与对象 6.1 类定义与对象声明 6.2 对象的使用 6.3 对象成员 6.4 友员 friend 6.5 静态成员和对象组 织 6.6 模板 6.7 应用举例 例 1:定义并实现类 student #include<iostream.h> class student //定义类 { public: //类的公有成员 void input(float s) {score=s;} void modify(float s) {score=s;} void display( ) { cout << " \n score: "<< score; } private: //类私有成员 float score; }; void main( ) //主函数 { student ss; //声明对象 ss.input(88.5); //调用成员函数 ss.display( ); }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有