首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include using namespace std; class Goods{//货物类 double unit_price;//单价 int quantity;//数量 public: Goods(double u=0.0,int q
有如下程序: #include using namespace std; class Goods{//货物类 double unit_price;//单价 int quantity;//数量 public: Goods(double u=0.0,int q
admin
2021-02-22
74
问题
有如下程序:
#include
using namespace std;
class Goods{//货物类
double unit_price;//单价
int quantity;//数量
public:
Goods(double u=0.0,int q=0):unit_price(u),quantity(q){}
double getPrice()const{return unit_price;}//返回单价
int getQuantity()const{return quantity;}//返回数量
//增加数量
Goods operator+(int q)const{return Goods(unit_price,quantity+q);}
};
//增加数量
Goods operator+(__________){return g+q;}
//输出货物信息
ostream& operator<<(ostream& os,Goods g){
cout<<’’单价:’’<
return os;
};
int main(){
Goods g(35.6,100);
cout<
return 0;
}
若运行后的输出结果是:
单价:35.6,数量:100
单价:35.6,数量:133
单价:35.6,数量:125
则程序中下划线处缺失部分应该是( )。
选项
A、Goods q,Goods g
B、Goods g,Goods q
C、int q,Goods g
D、Goods g,int q
答案
C
解析
程序中,语句Goods g(35.6,100);定义了Goods类的对象g,通过构造函数可知单价unit_price赋值为35.6,数量quantity赋值为100,所以cout<
转载请注明原文地址:https://kaotiyun.com/show/Dhfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
请打开考生文件夹下的解决方案文件proj1,此工程包含有一个源程序文件proj1.cpp。其中位于每个注释“//ERROR****found****”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为:(4,4)注意:只修改注释“//ERROR
下列函数的运行结果是()。#include<iostream.h>intadd(inta,intB.;voidmain(){externintx,y;cout<<add(x,y)<<end
在声明派生类时,如果不显示地给出继承方式,缺省的类继承方式是私有继承private。已知有如下类定义:classTestClass{protected:voidfun(){}};classT
下列关于对象概念的描述中,正确的是()。
若有如下程序:#include<iostream>usingnamespacestd;ints=0:classsample{staticintn;public:sa
若有以下程序:#include<iostream>usingnamespacestd;classA{public:A(inti,intj){a=i;b=j;
使用VC6打开考生文件夹下的源程序文件modi2.cpp。请完成函数fun(char*s),该函数完成以下功能:(1)把s中的大写字母转换成小写字母,把其中的小写字母转换成大写字母。并且在函数中调用写函数WriteFile()将结果输出到modi
下列叙述中正确的是()。
下列模式中,能够给出数据库物理存储结构与物理存取方法的是()。
下列二叉树描述中,正确的是()。
随机试题
1967年在美国上映的影片《毕业生》的主题曲为《斯卡布罗集市》,其演唱者为()。
关于X线的叙述,正确的是
治疗青霉素所致的速发型过敏反应应立即选用
下列哪项对急性肝炎的早期诊断有意义
属于潴留性囊肿的是()
现行宪法规定,地方各级人民法院对()
公路桥梁的组成包括()。
三农问题是关系到国计民生的根本性问题,三农是指()。
甲乙签订合同,约定甲向乙出售家具。在履行合同过程中的下列何种情况下,甲可以将家具提存?()
Whichofthefollowingwouldbethemostappropriatetitleforthepassage?Accordingtothepassage,whathappenswhenthete
最新回复
(
0
)