类的声明及定义

来源:互联网 发布:妇科炎症发病率数据图 编辑:程序博客网 时间: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