首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用“答题”菜单或使用VC6打开考生文件夹projl下的工程projl,此工程包含程序文件main.cpp,其中有类TimesTable(“乘法口诀表”)的定义和主函数main的定义。程序中位于每个//ERROR **********found*****
请使用“答题”菜单或使用VC6打开考生文件夹projl下的工程projl,此工程包含程序文件main.cpp,其中有类TimesTable(“乘法口诀表”)的定义和主函数main的定义。程序中位于每个//ERROR **********found*****
admin
2019-05-14
30
问题
请使用“答题”菜单或使用VC6打开考生文件夹projl下的工程projl,此工程包含程序文件main.cpp,其中有类TimesTable(“乘法口诀表”)的定义和主函数main的定义。程序中位于每个//ERROR **********found**********下的语句行有错误,请加以改正。更正后程序的输出应该是:
1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
1*4=4 2*4=8 3*4=12 4*4=16
1*5=5 2*5=10 3*5=15 4*5=20 5*5=25
1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36
1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49
1*8=82*8=16 3*8=24 4*8=32 5*8=加6*8=48 7*8=56 8*8=64
1*9=92*9=18 3*9=27 4*9=36 5*9=45 6*9=547*9=63 8*9=72 9*9=81
注意:只能修改每个//ERROR **********found**********下的那一行,不要改动程序中的其他内容。
#include
#include
using namespace std;
class TimesTable//乘法口诀表
{
public:
//ERROR **********found**********
TimesTable(int n=9){count:n;)
void Print()const;
private:
const int count;
};
//ERROR **********found**********
void Print()const
{
int i,j;
//ERROR **********found**********
for(i=1;i
{
for(J=1;j<=i;j++)
cout<
left<
cout<
}
}
int main()
{
TimesTable obj;
obj,Print();
return 0;
}
选项
答案
(1)TimesTable(int n=9):count(n){} (2)void TimesTable::Print()const (3)for(i=1;i<=count;i++)
解析
主要考查类中成员函数,在类定义的外部来实现。成员函数后附加const的作用
【解题思路】
(1)const为只读变量,const变量应该在成员初始化列表中赋初值,否则C++认为是语法错误,可知成员变量count,定义const类型,不能在构造函数中赋值。
(2)类中的成员函数,在类外部定义,必须附加域说明符,来表示该函数属于某个类的。
(3)根据题设值,计算出从1一n的乘法口诀表,包括n在内,因此使用“<=”运算符。
转载请注明原文地址:https://kaotiyun.com/show/uE8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
在下面的类定义中,横线处应填入的内容是()。classFred{public:voidprint(){cout<<data<<end1;}voidsetData(doubled}{data
运算符函数调用格式的表达式“y/x++”与表达式“y.operator/(operator++(x,0))”的含义相同,由此可看出()。
有如下程序:#include<iostream>usingnamespacestd;classAA{intn;public:AA(intk):n(k){}intget(){retur
有如下程序:#include<iostream>usingnamespacestd;classTestClass{public;~TestClass(){cout<<"BASE:;}};cla
若有如下程序段:#include<iostream>usingnamespacestd;intmain(){char*p="abcdefgh",*r;r=p;cout<<*r<<end1;
阅读以下程序:#include<iostream.h>voi6main(){staticinta[][2]={5,3,1,2};inti,j,s1=0;for(i=0;i<2;i++)for(
执行以下程序后,输出结果第二行的内容是______。#include<iostream>usingnamespacestd;classTestClass{public:virtualvoidwho(
有如下程序:#include<iostream>usingnamespacestd;classCon{charID;public:Con():ID(’A’){cout<<1;}Con(
随机试题
Couldyoursmartphonepreventacarfromhittingyou?GeneralMotorsandotherresearchersthinkthat’sapossibility【C1】_______
完成相互依存的任务,实现共同使命的一群人是指()
有关孕期检查的四步触诊法,下列错误的是
高血压同时伴有2型糖尿病,尿蛋白(+)。选择最佳降压药物为()
人区别于动物的重要标志是(),它是把平凡的人培养成出色的人的可能性或前提条件。
质点沿半径为R的圆周按s=v0t-bt2的规律运动,式中s为质点离圆周上某点的弧长,v0、b都是常量,求:t时刻质点的加速度。
教育对经济发展的促进功能表现为()
Apilotnoticedaballoonwhichseemedtobe【K1】______(make)foraRoyalAirForceStationnearby.Heinformedthestationaton
Light,heatandcoldhadnothingtodowiththepowerofrays.______iftheuraniumwascombinedwithsomethingelse.
Theloudestoutcryaboutpovertyseemedtocomeinthewealthiestcountrybyfarintheworld.Accordingtomostcalculations,【C
最新回复
(
0
)