第三周

1.静态成员函数中不能使用this指针;静态成员函数并不具体作用于某个对象;

2.普通成员函数每个对象一个,静态成员函数所有对象共享一个;eg.A::f();//等于//  r1.f();

3.静态成员函数不需要通过对象就能访问;

4.静态成员变量和静态成员函数本质上是全局变量和全局函数;

5.必须在定义类的文件中对静态成员变量进行声明或初始化,否则编译能通过,链接不能通过;

6.静态成员函数中,不能访问非静态成员变量和非静态成员函数,因为不知道是哪个对象的;

7.有成员对象的类叫封闭类;封闭类应该通过(封闭类的构造函数的初始化列表)来进行初始化;

8.封闭类执行构造函数的顺序:成员函数-->封闭类;(engine-->car)封闭类执行析构函数的顺序:封闭类-->成员函数;(car-->engine)

9.友元函数:一个类的友元函数中,该类的对象可以访问该类的私有变量;//一般对象不能访问该类的私有变量,只能通过成员函数访问;

10.友元类:若A是B的友元类,那么A的成员函数可以访问B的私有变量;

11.常量成员函数:const A a;//常量对象只能构造函数,析构函数,以及有const说明的方法;

a.f();//error

void f() const{//常量成员函数//const A a;-->对象  void f() const{}-->函数

//内部不能改变属性的值,也不能调用非常量成员函数;

}

12.mutable int a;

可以在const 成员函数中修改a;

13.strtok()的用法

(1).char str[]="- this is, a girl, ok.";

char *p=strtok( str ," -.," );

while(p!=NULL){

cout<<p<<endl;

p=strtok(NULL," -.,");

}

(2). void input(){
                           char buf[210];
                           cin.getline(buf,200);
                           char * p=strtok(buf,",");
                           strcpy(name,p);
                           p=strtok(NULL,",");
                           age=atoi(p);
                           p=strtok(NULL,",");
                           id=atoi(p);
                           for(int i=0;i<MUN;i++){
                                   p=strtok(NULL,",");
                                   score[i]=atoi(p);
                                   }

                           }

001:(Program Completion) Student Information Processing

#include<cstdio>
#include<iostream>//cin cout
#include<string.h>//<string>ÊDz»¶ÔµÄ£¬Ó¦¸Ã¼Ó.h
#include<cstdlib>
#include<cmath>
#include<vector>//¶þάÊý×é
#include<algorithm>//
#include<set>//¼¯ºÏ
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;
const int maxn=1010;
const int inf=0x3fffffff;
const double minx=1e-8;                  
   
class student{
              
              private:
                      static const int MUN=4;
                      int age,id;
                      char name[20];
                      int score[MUN];
                      
              public:
              int calculate(){
                         int sum=0;
                         for(int i=0;i<MUN;i++){
                                 sum+=score[i];
                                 }
                         return sum/MUN;
                         }
                         
              void input(){
                           char buf[210];
                           cin.getline(buf,200);
                           char *p=strtok(buf,",");
                           strcpy(name,p);
                           p=strtok(NULL,",");
                           age=atoi(p);
                           p=strtok(NULL,",");
                           id=atoi(p);
                           for(int i=0;i<MUN;i++){
                                   p=strtok(NULL,",");
                                   score[i]=atoi(p);
                                   }
                           }
                           
              void output(){
                            cout<<name<<",";
                            cout<<age<<","<<id<<","<<calculate()<<endl;;
                            }
              
              };
                                                                            
int main(){
    student stu;
    stu.input();
    stu.calculate();
    stu.output();
    system("pause");
    return 0;        
}  



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值