网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

3、使用进制转换函数: def toStr2(n,base): convertString='0123456789ABCDEF' if n == 0: return '' return toStr2(n // base, base) + convertString[n % base] 将数字135转换为三进制“12000”的过程中,函数共被调用了多少次(包含初始调用)?

A.3

B.4

C.5

D.6


参考答案和解析
6
更多 “3、使用进制转换函数: def toStr2(n,base): convertString='0123456789ABCDEF' if n == 0: return '' return toStr2(n // base, base) + convertString[n % base] 将数字135转换为三进制“12000”的过程中,函数共被调用了多少次(包含初始调用)?A.3B.4C.5D.6” 相关考题
考题 试题四阅读以下说明和C代码,将应填入 (n) 处的字句写在答题纸的对应栏内。[说明]函数MultibaseOutput(long n, int B)的功能是:将一个无符号十进制整数n转换成B(2≤B≤16)进制数并输出。该函数先将转换过程中得到的各位数字入栈,转换结束后再把B进制数从栈中输出。有关栈操作的诸函数功能见相应函数中的注释。C代码中的符号常量及栈的类型定义如下:#define MAXSIZE 32typedef struct {int *elem; /* 栈的存储区 */int max; /* 栈的容量,即栈中最多能存放的元素个数 */int top; /* 栈顶指针 */}Stack;[C代码]int InitStack(Stack *S, int n) /* 创建容量为n的空栈 */{ S-elem = (int *)malloc(n * sizeof(int));if(S-elem == NULL) return -1;S-max = n; (1) = 0 ; return 0;}int Push(Stack *S, int item) /* 将整数item压入栈顶 */{ if(S-top == S-max){ printf("Stack is full!\n"); return -1;}(2) = item ; return 0;}int StackEmpty(Stack S) { return (!S.top) ? 1 : 0; } /* 判断栈是否为空 */int Pop(Stack *S) /* 栈顶元素出栈 */{ if(!S-top) { printf("Pop an empty stack!\n"); return -1;}return (3) ;}void MultibaseOutput(long n, int B){ int m; Stack S;if (InitStack(S, MAXSIZE)) {printf("Failure!\n"); return;}do {if (Push(S, (4) )) {printf("Failure!\n"); return;}n = (5) ;}while(n != 0);while(!StackEmpty(S)) { /* 输出B进制的数 */m = Pop(S);if(m 10) printf("%d", m); /* 小于10,输出数字 */else printf("%c", m + 55); /* 大于或等于10,输出相应的字符 */}printf("\n");}

考题 ●试题二阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明2.1】以下C语言函数用二分插入法实现对整型数组a中n个数的排序功能。【函数2.1】void fun1(int a[]){int i,j,k,r,x,m;for(i=2;i=n;i++){ (1) ;k=1;r=i-1;while(k=r){m=(k+r)/2;if(xa[m])r=m-1;else (2) ;}for(j=i-1;j=k;j--)a[j+1]=a[j];(3) ;}}【说明2.2】以下程序可以把从键盘上输入的十进制数(1ong型)以二~十六进制形式输出。【程序2.2】#includestdio.hmain(){char b[16]={′0′,′1′,′2′,′3′,′4′,′5′,′6′,′7′,′8′,′9′,′A′,′B′,′C′,′D′,′E′,′F′};int c[64],d,i=0,base;long n;printf(″enter a number:′n″);scanf(″%1d″,n);printf(″enter new basc:kn″);scanf(″%d″,base);do{c[i]= (4) ;i++;n=n/base;}while(n!=0);printf("transmite new base:\n");for(--i;i=0;--i){ d=c[i];printf("%c", (5) );}}

考题 有如下程序:#includeusing namespace std;class Base{public:void funl(){cout"Base\n";}virtual void fun2(){cout"Base\n";}};class Derived:public Base{public:void funl(){cout"Derived\n";}void fun2(){cout"Derived\n";}};void f(Base B . {b.funl();b.fun2();}, lt;, /Pint main(){Derived obj;f(obj);return 0;}执行这个程序的输出结果是A . Base BaseB . Base DerivedC . Derived BaseD . Derived Derived

考题 ( 21 )计算斐波那契数列第 n 项的函数定义如下:Int fib(int n){if (n == 0) return 1;else if (n == 1) return 2;else return fib(n-1)+fib(n-2);}若执行函数调用表达式 fib(2) ,函数 fib 被调用的次数是A ) 1B ) 2C ) 3D ) 4

考题 以下程序可把输入的十进制数以十六进制数的形式输出,请填空。main(){char b[17]={"0123456789ABCDEF"};int c[64],d,i=0,base=16;long n;printf("Enter a number:\n");scanf("%ld",n);do{c[i]=【17】;i++;n=n/base;}while(n!=0);printf("Transmite new base:\n");for(--i;i=0;--i){d=c[i];printf("%c",b【18】);}printf("\n");}

考题 有如下类声明: class Base{ protected: int amount; public: Base(int n=0):araount(n){ } int getAmount( )const{retum amount;} }; class Derived:public Base{ protected; int value; public: Derived(int m,int n):value(n1),Base(n){ } int getData( )const{return value+amount;} }; 已知x是一个Derived对象,则下列表达式中正确的是A.x.value+x.getAmount( )B.x.getData( )-x.getAmount( )C.x.getData( )-x.amountD.x.value+x.amount

考题 有如下程序:includeusing namespace std;class Base{int x;public:Base(int n=0):x(n 有如下程序: #include<iostream> using namespace std; class Base{ int x; public: Base(int n=0):x(n){cout<<n;} int getX( )const{return x;} }; class Derived:public Base{ int y; public: Derived(int m,int n):y(m),Base(n){tout<<m;} Derived(int m):y(m){cout<<m;} }; int main( ){ Derived dl(3),d2(5,7); return 0; } 程序的输出结果是A.375B.357C.0375D.0357

考题 有下列程序,功能是把输入的十进制长整型数以十六进制的形式输出,完成程序#include "stdio.h"main(){char b[17]={"0123456789ABCDEF"};int c[50],d,i=0,base=16;long n;scanf("%ld",n);do{c[i]=n%base;i++;n= 【14】 ;}while(n!=0);for(--i;i=0;--i){d= 【15】 ;printf( "%c",b[d]);}printf("H\n");}

考题 有如下程序:includeusing namespace std;class Base{private:char c;piblic:Base(cha 有如下程序: #include<iostream> using namespace std; class Base { private: char c; piblic: Base(char n):c(n){} ~Base() { cout<<C; } }; class DeriVed:public Base { private: char c; public: Derived(char n):Base(n+1),c(n){} ~Derived() { cout<<c; } }; int main() { Derived obj('x'); return 0; } 执行上面的程序将输出A.xyB.yxC.xD.y

考题 以下程序可把输入的十进制数以十六进制数的形式输出。请在横线上填上适当的内容并把横线删除,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。试题程序;main (){char b[17]={"0123456789ABCDEF"};int c[64] ,d,i=0,base=16;long n;printf("Enter a number:\n");scanf ("%ld", n);do {/*****************found****************/c[i]=______; i++; n=n/base; }while (n!=0);printf("Transmite new base:\n");for(--i;i>=0;--i)/***************found*******************/{ d=c[i];printf("%c",b______);}printf("\n");}

考题 阅读下列函数说明和C代码,将应填入(n)处的字句写在对应栏内。【说明2.1】以下C语言函数用二分插入法实现对整型数组a中n个数的排序功能。【函数2.1】void fun1 (int a[]){ int i,j,k,r,x,m;for(i=2;i<=n;i++){ (1);k=1;r=i-1;while(k<=r){ m=(k+r)/2;if(x<a[m])r=m-1;else (2);}for(j=i-1;j>=k;j--)a[j+l]=a[j];(3);}}【说明2.2】以下程序可以把从键盘上输入的十进制数(long型)以二~十六进制形式输出。【程序2.2】include<stdio.h>main(){ charb[16]={'0','l','2','3 ,4,'5','6','7','8','9','A','B','C','D','E','F'};int c[64],d,i=0,base;long n;printf("enter a number:\n");scanf("%1d",n);printf("enter new basc:\n");scanf("%d", base);do{ c[i]=(4);i++; n=n/base;} while(n!=0);printf("transmite new base:\n");for(--i;i>=0;--i){ d=c[i];printf("%c",(5));}}

考题 有如下程序:includeclass Base{protected:int i;public:int j;};class Derived:pub 有如下程序: #include<iostream.h> class Base { protected:int i; public:int j; }; class Derived:public Base { int m; public:int n; }; int main() { Derived d; d.i=0; //[1]d.j=0; //[2]d.m=0; //[3]d.n=0; //[4]return 0; } 其中主函数中有两个赋值语句有错,这两个错误的赋值语句是( )。A.[1]和[2]B.[1)和[3]C.[2]和[3]D.[2]和[4]

考题 有如下程序:includeusing namespace std;class Base{protected:int i;public:int j;} 有如下程序: #include<iostream> using namespace std; class Base{ protected:int i; public:int j; }; class Derived:public Base{ int m; public:int n; }; int main( ){ Derived d; d.i=0; //[1] d.j=0; //[2] d.n1=0; //[3] d.n=0; //[4] return 0; } 其中主函数中有两个赋值语句有错,这两个错误的赋值语句是A.[1]和[2]B.[1]和[3]C.[2]和[3]D.[2]和[4]

考题 下列程序的输出结果是【 】。includeiostreamusing namespace std;class Base{public:int m,n;Base(int i,int j):m(i),n(j){}};class Derived:public Base{public:int m,k,;Derived(int i,int j):Base(i,j),m(i+1),k(j+1){}};int main(){Derived d(1,5);coutd.md.kd.n;return 0;}

考题 有如下程序: include using namespace std; class Base{ public: int m,n; }; class D 有如下程序:include<iostream>using namespace std;class Base{public:int m,n;};class Derived1:【 】Base{};class Derived2:public Derived1{public:void SetMN(int M,int N){m=M;n=N;}int GetSumMN(){return(m+n);}};int main() {Derived2 objD;ohjD. SetMN(3,4);cout<<"M+N="<<objD, m+objD, n<<endl;return 0}编译时只有“cout<<"M+N"<<objD.m+objD.n<<endl;”有语法错误,程序的其他地方没有语法错误。请判断下划线处使用的关键字是什么。

考题 计算斐波那契数列第n项的函数定义如下: intfib(intn){ if.(n==0)return1; elseif(n==1)return2: elsereturnfib(n-1)+fib(n-2); } 若执行函数调用表达式fib(2),函数fib被调用的次数是( )。A.1B.2C.3D.4

考题 有如下类的声明: class Base{ protected: int amount; public: Base(int n=0):amount(n){} int getAmount()const{return amount;} }; class Derived:public Base{ protected: int value public: Derived(int m,int n):value(m),Base(n){} int getData()const{return value+amount;} };已知x是一个Derived对象,则下列表达式中正确的是A.x. value+x. getAmount()B.x. getData()-x. getAmount()C.x. getData()-x. amountD.x. value+x. amount

考题 有如下程序: include using namespace std; class Base{ int x; pu 有如下程序: #include<iostream> using namespace std; class Base{ int x; public: Base(int n=0):x(n){cout<<n;) int getX()const{return x;} }; class Derived:public Base{ int y; public: Derived(int m,int n):y(m,)Base(n){cout<<m;} Derived(int m):y(m){cout<<m;} }; int main(){ Derived d1(3),d2(5,7) return 0; }运行时的输出结果是A.375B.357C.375D.357

考题 有如下类声明: class Base{ protected: int amount; public: Base(int n=0):amount(n){} int getAmountconst{retum amount;} }; class Derived:public Base{ protected: int value; public: Derived(int m,int n):value(m),Base(n){} int getDataconst{return value+amount;} }: 已知x是一个Derived对象,则下列表达式中正确的是( )。A.x.value+X.getAmountB.x.getData一x.getAmountC.x.getData一x.amountD.x.value+X.amount

考题 阅读下列函数说明和C函数,将应填入(n)处的字句写在对应栏内。[函数2.1说明]下面程序的功能是:将由键盘输入的某个十进制数转换成对应的R进制数并输出。这里R是 2到16的整数,由键盘输入。例如,输入n=128,base=13后的输出为9B。[函数2.1]include <stdio.h>main(){ char b[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};int c[64],n,i=0,base;printf("Enter a number:");scaaf("%d",n);printf("Enter new base:");scanf("%d",base);do{c[i]=(1);i++;n=n/base;}while((2));printf("Transmit new base:");for(- -i;i>=0;- -i)printf("%c",(3));}[函数2.2说明]所谓回文字符中是指正序和逆序拼写相同的字符串,例如astrtsa,adgdtdgda等。下面函数int fun(char *str)的功能是判断字符串str是否是回文,当字符串是回文时,函数返回1,否则返回0。[函数2.2]int fun(char *str){ int i,j,l;for(i=0;str[i]! ='\0';i++);l=i/2;for(j=0,i- -;j<=1;(4))if((5)) return 0;return 1;}

考题 有如下程序: #includeiostream using namespace std; class Base { public: void funl{cout”Base\n”;} virtual void fun2{eout”Base\n”;} }; class Derived:public Base{ public: void funl{eout”Derived、n”;} void fura{eout.”Derived\n”;} }; void f(BaseB.}b.funl;b.ftm2;} int main { Derived obj; f(obj); return 0; } 执行这个程序的输出结果是( )。A.Base BaseB.Base DerivedC.Derived BaseD.Derived Derived

考题 有以下程序include using namespace std:class Base{private:char c;public:Base(cha 有以下程序#include <iostream>using namespace std:class Base{private: char c;public: Base(char n) :c(n) {} ~Base ( ) { cout<<c; }}; class Derived : public Base{private: char c;public: Derived(char n):Base (n+1),c(n) {} ~Derived() { cout<<c; }};int main(){ Derived obj('x'); return 0;} 执行后的输出结果是A.xyB.yxC.xD.y

考题 有如下程序:include using namespace std;class Base{private:charc;public:Base(cha 有如下程序:#include <iostream>using namespace std;class Base{private: char c;public: Base(char n) :c(n){} ~Base() { cout<<c; } };class Derived: public Base{private: char c; public: Derived(char n):Base(n+1),c(n) {} ~Derived() { cout<<c; }};int main (){ Derived obj ('x'); return 0;}执行上面的程序净输出A.xyB.yxC.xD.y

考题 有如下程序:nclude using namespace std;class Base{public:void fun1() {cout 有如下程序:#nclude <iostream>using namespace std;class Base{ public:void fun1() {cout << "Base\n"; }virtual void fun2() {cout << "Base\n"; }};class Derived: public Base{ public:void fun1() {cout << "Derived\n"; }void fun2() {cout << "Derived\n"; }} void f(Base b) { B. fun1(); B. fun2(); }int main(){Derived obj;f(obj);return 0;}A.Base BaseB.Base DerivedC.Derived BaseD.Derived Derived

考题 有如下程序: #include 〈iostream〉 using namespace std; class Base { private: char c; public: Base(char n) :c(n) {} ~Base ( ) { cout〈〈c; } }; class Derived : public Base { private: char c; public: Derived(char n) :Base(n+1),c(n) { } ~Derived () { cout〈〈c; } }; int main ( ) { Derived obj ('x'); return 0; } 执行上面的程序将输出( )。A.xyB.yxC.xD.y

考题 有如下程序: #includeiostream using namespace std; class Base{ int x: public: Base(int n=0):x(n){coutn;} int getXconst{return x;} }; cjass Derived:public Base{ int Y:. J;;Iublic: Derived(int m,int n):y(m),Base(n){coutm;} Derived(int m):Y(m){coutm;} }; int main { Derived dl(3),d2(5,7); retum 0; } 执行这个程序的输出结果是( )。A.375B.357C.0375D.0557

考题 有以下程序includeusing namespace std;class Base{private:char c;public:Base(char 有以下程序 #include<iostream> using namespace std; class Base { private: char c; public: Base(char n):c(n){} ~Base() { cout<<c; } }; class Derived:public Base { private: char c; public: Derived(char n):Base(n+1),c(n){} ~Derived() { cout<<c; } }; int main() { Derived obj('x'); return 0; } 执行后的输出结果是A.xyB.yxC.xD.y

考题 下列程序的输出结果是______。 include using namespace std; class base { public: in 下列程序的输出结果是______。include<iostream>using namespace std;class base{public:int n;base(int x){n=x;}virtual void set(int m){n=m;cout<<n<<'';}};class deriveA:public base{public:deriveA(int x):base(x){}void set(int m){n+=m;cout<<n<<'';}};class deriveB:public base{public:deriveB(int x):base(x){}void set(int m){n+=m;cout<<n<<'';}};int main( ){deriveA d1(1);deriveB.d2(3);base*pbase;pbase=d1;pbase->set(1);pbase=d2;pbase->set(2);return 0;}