首页 > 编程语言 > 详细

面向对象C++ 学生类1

时间:2021-05-30 20:36:59      阅读:25      评论:0      收藏:0      [点我收藏+]

使用类内的成员函数给类内的私有成员赋值,并且成员函数在类内声明,类外定义

#include <iostream>
#include <string.h>
using namespace std;
class Student{
      private:
      string name;
      float math;
      float chinese;
      public:
      float average;
      void setname();
      void setmath();
      void setchinese();
      float show_average();
      float show_sum() ;
      };


void Student::setname ()

{cin>>name ;}


void Student::setmath ()

{cin>>math;}



void Student::setchinese ()

{cin>>chinese;}



float Student::show_average ()

{cout<< (math+chinese)/2<<endl;}



float Student::show_sum()

{cout<<math + chinese<<endl;}

main(){

    Student a;
    a.setname();
    a.setmath();
    a.setchinese();
    a.show_average();
    a.show_sum();
    return 0;
    }

 

面向对象C++ 学生类1

原文:https://www.cnblogs.com/Atsuhiro/p/14828476.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!