类的声明及定义
来源:互联网 发布:妇科炎症发病率数据图 编辑:程序博客网 时间:2024/05/17 07:48
employee1.h文件
#ifndef EMPLOYEE#define EMPLOYEE#include <string>using namespace std;class Employee{public:Employee();void readInfo();bool isSentinel() const;void printOut() const;void getCopyof(const Employee& other);bool makesMoreThan(const Employee& other) const;private:string name;double grossPay;const static string EMPTY_STRING;const static string NAME_SENTINEL;const static double GROSS_PAY_SENTINEL;};#endif
employee1.cpp文件
#include <iostream>#include "employee1.h"Employee::Employee(){name=EMPTY_STRING;grossPay=0.00;}void Employee::readInfo(){const string NAME_AND_PAY_PROMPT="Pls enter name and pay, to quit,enter";cout<<NAME_AND_PAY_PROMPT<<NAME_SENTINEL<<" "<<GROSS_PAY_SENTINEL;cin>>name>>grossPay;}bool Employee::isSentinel() const{if(name==NAME_SENTINEL&&grossPay==GROSS_PAY_SENTINEL)return true;return false;}void Employee::printOut() const{cout<<name<<grossPay<<'\n';}void Employee::getCopyof(const Employee& other){name=other.name;grossPay=other.grossPay;}bool Employee::makesMoreThan(const Employee& other) const{return grossPay>other.grossPay;}const string Employee::EMPTY_STRING="";const string Employee::NAME_SENTINEL="";const double Employee::GROSS_PAY_SENTINEL=-1.0;
test.cpp文件
#include "employee1.h"int main(){Employee test;test.readInfo();test.printOut();}
0 0
- 类的声明及定义
- 类的声明、定义及应用
- 类的声明,定义及使用
- Java类的定义、声明及使用
- 链表类的声明及定义
- template模板的声明及定义
- Jsp的定义及作用还有声明
- 二维数组的声明,定义及应用
- C++变量定义及声明的区别
- 类的定义与声明
- 类的声明与定义
- 类的定义和声明
- 类的声明与定义
- 类的声明与定义
- 类的声明、定义、初始化
- 类的声明与定义
- C++声明、定义及初始化
- 类的声明和定义的区别
- ppt修改母版格式
- xStream完美转换XML、JSON
- jetty命令行方式启动jetty-runner.jar 容器
- android 水平进度条 背景设置问题
- 房价会打架撒黄金的撒谎的撒
- 类的声明及定义
- Hadoop拷贝文件到hdfs时出错:could only be replicated to 0 nodes, instead of 1
- mysql查询同一个字段的三个count值
- C语言内存管理-字符数组与字符指针
- Springmvc请求接收参数的几种方法
- C# windows 服务
- rsync异常
- *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit
- Linux虚拟化带库——mhvtl