首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

c++有关问题,大神们帮小弟我看看哪里出错了@_@

2013-06-26 
c++问题,大神们帮我看看哪里出错了@_@运行后弹框提示“program file does not exist”[解决办法]看了一下,cl

c++问题,大神们帮我看看哪里出错了@_@



运行后弹框提示“program file does not exist”
[解决办法]
看了一下,class people中的

//class people
virtual int csalary();//位定义


还有就是

#include <iostream>
#include <string>
using namespace std;
 
class people{
protected:
    string name;
    int age;
    double salary;
public:
    int workHour;
    people(string n , int a , double s):name(n),age(a),salary(s){}
    virtual ~people(){}
    virtual int csalary();
    string getname(){
        return name;
    }
    int getage(){
        return age;
    }


    double getsalary(){
        return salary;
    }
};
 
class teacher:public people{
public:
    teacher();
    virtual int csalary(){return 2000*workHour;}
};
 
class worker:public people{
public:
    worker();
    virtual int csalary(){return 800*workHour;}
};
 
class student:public people{
public:
    student();
    virtual int csalary(){return 200*workHour;}
};
 
int main() {
    int a,b,c;
    teacher *t;
    worker  *w;
    student *s;
    a=t->csalary();//t位初始化。。。
    b=w->csalary();//w也是
    c=s->csalary();//s也是
    people *p[3];
    people *x;
    cin>>x->workHour;
    p[0]=new people("张三",40,a);
    p[1]=new people("李四",30,b);
    p[2]=new people("王五",20,c);
    cout<<p[0]->getname()<<p[0]->getage()<<p[0]->getsalary()<<endl;
    cout<<p[1]->getname()<<p[1]->getage()<<p[1]->getsalary()<<endl;
    cout<<p[3]->getname()<<p[3]->getage()<<p[3]->getsalary()<<endl;
    return 0;
}


[解决办法]
#include <iostream>
#include <string>
using namespace std;

class people{
protected:
    string name;
    int age;
    double salary;
public:
    int workHour;
    people(string n , int a , double s):name(n),age(a),salary(s){}
    virtual ~people(){}
    virtual int csalary(){return 10000*workHour;};
    string getname(){
        return name;
    }
    int getage(){
        return age;
    }
    double getsalary(){
        return salary;
    }
};

class teacher:public people{
public:
    teacher(string n , int a , double s):people(n, a, s){};
    virtual int csalary(){return 2000*workHour;}
};

class worker:public people{
public:
    worker(string n , int a , double s):people(n, a, s){};
    virtual int csalary(){return 800*workHour;}
};

class student:public people{
public:
    student(string n , int a , double s):people(n, a, s){};
    virtual int csalary(){return 200*workHour;}


};

int main() {
    int a,b,c;
    teacher *t = new teacher("劳师",10,5);
    worker  *w = new worker("宫人",20,6);
    student *s = new student("薛生",30,7);
    a = t->csalary();
    b = w->csalary();
    c = s->csalary();
    people *p[3];
    people *x = new people("任民",40, 8);
    cin>>x->workHour;
    p[0]=new people("张三",40,a);
    p[1]=new people("李四",30,b);
    p[2]=new people("王五",20,c);
    cout<<p[0]->getname()<<p[0]->getage()<<p[0]->getsalary()<<endl;
    cout<<p[1]->getname()<<p[1]->getage()<<p[1]->getsalary()<<endl;
    cout<<p[2]->getname()<<p[2]->getage()<<p[2]->getsalary()<<endl;
    return 0;
}


[解决办法]

#include <iostream>
#include <string>
using namespace std;

class people{
protected:
string name;
int age;
double salary;
public:
int workHour;
people(string n , int a , double s):name(n),age(a),salary(s){}
virtual ~people(){}
virtual int csalary(){//这个函数没有定义。。
return 0;
}
string getname(){
return name;
}
int getage(){
return age;
}
double getsalary(){
return salary;
}
};

class teacher:public people{
public:
teacher()://这个函数没有定义。。
virtual int csalary(){return 2000*workHour;}
};

class worker:public people{
public:
worker();//这个函数没有定义。。
virtual int csalary(){return 800*workHour;}
};

class student:public people{
public:
student();//这个函数没有定义。。
virtual int csalary(){return 200*workHour;}
};

int main() {
int a,b,c;
    teacher *t = new teacher();//这里没有new对象。。
    worker  *w;//new
    student *s;//new
    a=t->csalary();
    b=w->csalary();
    c=s->csalary();
    people *p[3];
    people *x;//new
    cin>>x->workHour;
    p[0]=new people("张三",40,a);
    p[1]=new people("李四",30,b);
    p[2]=new people("王五",20,c);
    cout<<p[0]->getname()<<p[0]->getage()<<p[0]->getsalary()<<endl;
    cout<<p[1]->getname()<<p[1]->getage()<<p[1]->getsalary()<<endl;
    cout<<p[3]->getname()<<p[3]->getage()<<p[3]->getsalary()<<endl;
return 0;
}

热点排行