其他分享
首页 > 其他分享> > 车类

车类

作者:互联网

function.h #include"members.h" #include<iostream> using namespace std;   Car::Car(double w, double s) {     weight = w;     speed = s; }
Car::Car (const Car &p) {     weight = p.weight;     speed = p.speed; }
void Car::print() {     cout<< "重量为" << weight << endl;     cout<< "速度为" << speed << endl; }     main.cpp #include"members.h" #include"function.h" #include<iostream>
using namespace std;
int main() {     Car car_3(1000.23, 3000.4);     car_3.print();     Car car_1(100.1, 100.3);     Car car_2(car_1);     car_1.print();     return 0; }   members.h // 类的定义 // 定义数据和成员函数 #ifndef  COMPLEX_H_ #define  COMPLEX_H_   #include<iostream> using namespace std;   class Car {     private:         double weight;         double speed;
    public:         Car (double, double);         Car (const Car &p);         void print(); }; #endif

标签:weight,Car,车类,double,car,include,speed
来源: https://www.cnblogs.com/brain-keep-burning-why/p/16421856.html