网友您好, 请在下方输入框内输入要搜索的题目:
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。
[说明]
下面程序是为汽车市场编制的一个程序的一部分。其中automobile是基类。
[C++程序]
//Auto.h
ifndef AUTO_H
define AUTO_H
class automobile
{
(1):
int miles_per_gallon; //汽车每加仑行驶公里数
float fuel_capacity; //油箱容积
public:
void initialize(int in_mpg,int in_fuel);
int get_mpg(void);
float get_fuel(void);
float travel_distance(void);
}
endif
//Auto.cpp
include"auto.h"
void automobile::initialize(int in_mpg,float in fuel)
{
miles_per_gallon=in_mpg;
fuel_capacity=in_fuel;
)
int automobile::get_mpg() //提供一辆特定汽车每加仑公里数
{return miles per_gallon;}
float automobile::get_fuel() //提供油箱容积
{return fuel_capacity;}
float automobile::travel_distance()
{return (2) }
//car.h
ifndef CAR_H
define CAR_H
include"auto.h"
class car: (3)
{
int Total_doors;
public:
void initialize(int in_mpg,float in_fuel,int doors=4);
int doors(void);
};
endif
//car.cpp
include"car.h"
void car::initialize(int in_mpg,float in_fuel,int door)
{
Total_doors=door;
miles_per_galion=in_mpg;
fuel_capacity=in_fuel;
}
int car::doors(void)
{return Total doors;}
//Allauto.cpp
include
include"auto.h"
include"car.h"
int main()
{
car sedan;
sedan.initialize(24,20.0,4);
tout<<"The sedan can travel"<< (4) <<"miles.\n";
cout<<"The sedan has"<< (5) <<"doors.\n";
return 0;
}
参考答案