问题描述
- 求解答,问题出在那里,木有编译错误
-
// shiyan66.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include"iomanip"
#include"iostream"
using namespace std;
class Employee{ public:
Employee(const long n,const char* N){number=n,*name=*N;};
virtual~Employee(){};const char* getName(long n) const{};
const long getNumber() const{};
virtual double eamings() const=0;virtual void print() const{cout<<"编号:"< protected:
long number;
char name;
};
class Manager: public Employee
{ public:
Manager(const long n,const char N,double u ):Employee(n, N){monthlySalary=u;}
~Manager(){};
void setMonthlySalary(long n){number=n;};
virtual double eamings() const{return 0;};
virtual void print() const{cout private:
double monthlySalary;
};
class HourlyWorker: public Employee
{ public:
HourlyWorker(const long n,const char* N,double=0.0, int=0):Employee(n, N){number=n,*name=*N;};
~HourlyWorker(){}
void setWage(double h){hours=h;};
void setHours(int w){wage=w;};
virtual double eamings() const{return hours*wage; };
virtual void print() const{cout private:
double wage;
double hours;
};
class PieceWorker: public Employee
{ public:
PieceWorker(const long n,const char* N,double=0.0, int=0):Employee(n, N){number=n,*name=*N;};
~PieceWorker(){}
void setWage(double w){wagePerPiece=w;};
void setQuantity(int q){quantity=q;};
virtual double eamings() const{return wagePerPiece*quantity;};
virtual void print() const{cout private:
double wagePerPiece;
int quantity;
};
int main()
{ cout Manager m1(10135,"Cheng ShaoHua", 1200) ;
Manager m2(10201,"Yan HaiFeng",1000);
m2.setMonthlySalary ( 5300) ;
HourlyWorker hw1(30712,"Zhao XiaoMing",5,8*20) ;
HourlyWorker hw2(30649,"Gao DongSheng" ,6,98*8) ;
hw2.setWage(4.5) ;
hw2.setHours(10*30) ;
PieceWorker pw1(20382,"Xiu LiWei",0.5,2850) ;
PieceWorker pw2(20496,"Huang DongLin" ,1,23*10) ;
pw2.setWage(0.75);
pw2.setQuantity (1850);
Employee*basePtr;
basePtr=&m1 ; basePtr=&m2; basePtr=&hw1 ; basePtr=&hw2 ; basePtr=&pw1 ; basePtr=&pw2 ;
basePtr->print(); basePtr->print(); basePtr->print(); basePtr->print(); basePtr->print(); basePtr->print();
return 0;
}
解决方案
你这还没有编译错误么?一坨一坨的错误,你到底用的哪家的编译器?蓝翔的吗?还木有编译错误
解决方案二:
错误太多了,帮你修改没有语法错误了。剩下的逻辑错误自己完成吧。
#include "stdafx.h"
#include
#include
using namespace std;
class Employee
{ public:
Employee(const long n,const char* N){number=n,name=new char[strlen(N) + 1]; memset(name, 0, strlen(N) + 1); memcpy(name, N, strlen(N));}
virtual ~Employee(){if(NULL != name) {delete[] name; name = NULL;}}
const char* getName(long n) const{return name;}
const long getNumber() const{return number;}
virtual double eamings() const=0;
virtual void print() const{cout<<"编号:";}
protected:
long number;
char* name;
};
class Manager: public Employee
{
public:
Manager(const long n,const char* N,double u ):Employee(n, N){monthlySalary=u;}
~Manager(){};
void setMonthlySalary(long n){number=n;}
virtual double eamings() const{return 0;};
virtual void print() const{cout<<"" ;}
private:
double monthlySalary;
};
class HourlyWorker: public Employee
{
public:
HourlyWorker(const long n,const char* N,double w, int h):Employee(n, N){wage = w; hours = h;}
~HourlyWorker(){}
void setWage(double h){hours=h;}
void setHours(int w){wage=w;}
virtual double eamings() const{return hours*wage; };
virtual void print() const{cout<<"";}
private:
double wage;
double hours;
};
class PieceWorker: public Employee
{
public:
PieceWorker(const long n,const char* N,double piece, int count):Employee(n, N){wagePerPiece = piece; quantity =count;}
~PieceWorker(){}
void setWage(double w){wagePerPiece=w;};
void setQuantity(int q){quantity=q;};
virtual double eamings() const{return wagePerPiece*quantity;};
virtual void print() const{cout<<"";}
private:
double wagePerPiece;
int quantity;
};
int main()
{
Manager m1(10135,"Cheng ShaoHua", 1200) ;
Manager m2(10201,"Yan HaiFeng",1000);
m2.setMonthlySalary ( 5300) ;
HourlyWorker hw1(30712,"Zhao XiaoMing",5,8*20) ;
HourlyWorker hw2(30649,"Gao DongSheng" ,6,98*8) ;
hw2.setWage(4.5) ;
hw2.setHours(10*30) ;
PieceWorker pw1(20382,"Xiu LiWei",0.5,2850) ;
PieceWorker pw2(20496,"Huang DongLin" ,1,23*10) ;
pw2.setWage(0.75);
pw2.setQuantity (1850);
Employee*basePtr;
basePtr=&m1 ; basePtr=&m2; basePtr=&hw1 ; basePtr=&hw2 ; basePtr=&pw1 ; basePtr=&pw2 ;
basePtr->print(); basePtr->print(); basePtr->print(); basePtr->print(); basePtr->print(); basePtr->print();
return 0;
}
解决方案三:
错误好多,怎么没有编译错误。
解决方案四:
可以先换一个编译器试试,你这个编译器似乎简单的错都查不出。。。。