C++问题 C2264函数定义或声明中有错误 C2084函数已有主体
#include<iostream>#include<math.h>usingnamespacestd;enumCPU_Rank{p1=1,p2,p3,p4,p5,p6,...
#include<iostream>#include <math.h>using namespace std;enum CPU_Rank{p1=1,p2,p3,p4,p5,p6,p7};class CPU{private: CPU_Rank rank; int frequency; float voltage;public: CPU(CPU_Rank r, int f, float v) { rank = r; frequency = f; voltage = v; cout << "构造了一个CPU!" << endl; } ~CPU() { cout << "析构了一个CPU!" << endl; } CPU_Rank getRank()const { return rank; } int getFrequency()const { return frequency; } float getVoltage()const { return voltage; } void setRank(CPU_Rank r){ rank = r;} void setFrequency(int f) { frequency = f;} void setVoltage(float v) { voltage = v; } void Run() { cout << "CPU开始运行!" << endl; } void Stop() { cout << "CPU停止运行!" << endl; }};class point {private: int x, y;public: point(int xx = 0, int yy = 0) :x(xx), y(yy) {} point(point &t) :x(t.x), y(t.y) { cout << "复制构造函数被调用" << endl; } ~point() {} int getx() {} int gety() {} void show();};void point::show() { cout << "x=" <<x << "y=" << y << endl;}class point1{private: int i_x; int i_y; int i_z;public: point1(); point1(int x, int y, int z); point1(point1 &pt); ~point1(); int getx(); int gety(); int getz();};point1::point1(){ cout << "调用无参构造函数,输入点坐标:\n"; cin >> i_x >> i_y >> i_z;}point1::point1(int x, int y, int z){ cout << "调用有参构造函数\n"; i_x = x; i_y = y; i_z = z;}point1::point1(point1 &pt){ cout << "调用复制构造函数\n"; i_x = pt.i_x; i_y = pt.i_y; i_z = pt.i_z;}point1::~point1(){ cout << "调用析构函数!\n"; }point1::point1(){}int point1::getx() { return i_x; }int point1::gety() { return i_y; }int point1::getz() { return i_z; }int main(){ CPU cpu(p6, 300, 2.8); cpu.Run(); cpu.Stop(); point a(1, 2); point b(a); a.show(); b.show(); cout << a.getx() <<": " << a.gety() << endl; double x, y, z, length; point1 p1; point1 p2(3, 4, 5); point1 p3(p1); x = p2.getx() - p3.getx(); y = p2.gety() - p3.gety(); z = p2.getz() - p3.getz(); length = sqrt(x*x + y*y + z*z); cout << "the length:" << length << endl; return 0;}
展开
2个回答
展开全部
#include <iostream>
#include <math.h>
using namespace std;
enum CPU_Rank{p1=1,p2,p3,p4,p5,p6,p7};
class CPU{
private:
CPU_Rank rank;
int frequency;
float voltage;
public:
CPU(CPU_Rank r, int f, float v) {
rank = r;
frequency = f;
voltage = v;
cout << "构造了一个CPU!" << endl;
}
~CPU() {
cout << "析构了一个CPU!" << endl;
}
CPU_Rank getRank()const { return rank; }
int getFrequency()const { return frequency; }
float getVoltage()const { return voltage; }
void setRank(CPU_Rank r){ rank = r;}
void setFrequency(int f) { frequency = f;}
void setVoltage(float v) { voltage = v; }
void Run() { cout << "CPU开始运行!" << endl; }
void Stop() { cout << "CPU停止运行!" << endl; }
};
class point {
private:
int x, y;
public:
point(int xx = 0, int yy = 0) :x(xx), y(yy) {}
point(point &t) :x(t.x), y(t.y) {
cout << "复制构造函数被调用" << endl;
}
~point() {}
int getx() {}
int gety() {}
void show();
};
void point::show() {
cout << "x=" <<x << "y=" << y << endl;
}
class point1{
private:
int i_x;
int i_y;
int i_z;
public:
point1();
point1(int x, int y, int z);
point1(point1 &pt);
~point1();
int getx();
int gety();
int getz();
};
point1::point1(){ //AAAA:这里已经定义了无参数的point1构造,下面不需要再重复了
cout << "调用无参构造函数,输入点坐标:\n";
cin >> i_x >> i_y >> i_z;
}
point1::point1(int x, int y, int z){
cout << "调用有参构造函数\n";
i_x = x;
i_y = y;
i_z = z;
}
point1::point1(point1 &pt){
cout << "调用复制构造函数\n";
i_x = pt.i_x;
i_y = pt.i_y;
i_z = pt.i_z;
}
point1::~point1(){
cout << "调用析构函数!\n";
}
//point1::point1(){}//这个与上面4A处重复,去掉这行就OK了
int point1::getx() { return i_x; }
int point1::gety() { return i_y; }
int point1::getz() { return i_z; }
int main(){
CPU cpu(p6, 300, 2.8);
cpu.Run();
cpu.Stop();
point a(1, 2);
point b(a);
a.show();
b.show();
cout << a.getx() <<": " << a.gety() << endl;
double x, y, z, length;
point1 p1;
point1 p2(3, 4, 5);
point1 p3(p1);
x = p2.getx() - p3.getx();
y = p2.gety() - p3.gety();
z = p2.getz() - p3.getz();
length = sqrt(x*x + y*y + z*z);
cout << "the length:" << length << endl;
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询