首页 > 计算机等级考试
题目内容 (请给出正确答案)
[单选题]

有以下程序#include<string.h>main(){ char p[]={′a′, ′b′, ′c′},q[10]={ ′a′, ′b′, ′c′};printf("%d%d\n",strlen(p),strlen(q));}以下叙述中正确的是

A.在给p和q数组置初值时,系统会自动添加字符串结束符,故输出的长度都为3

B.由于p数组中没有字符串结束符,长度不能确定,但q数组中字符串长度为3

C.由于q数组中没有字符串结束符,长度不能确定,但p数组中字符串长度为3

D.由于p和q数组中都没有字符串结束符,故长度都不能确定

查看答案
答案
收藏
如果结果不匹配,请 联系老师 获取答案
您可能会需要:
您的账号:,可能还需要:
您的账号:
发送账号密码至手机
发送
安装优题宝APP,拍照搜题省时又省心!
更多“有以下程序 #include<string.h> main(…”相关的问题
第1题
有以下程序:#include<iostream>#include<string>usxng namespace std;int main(){ char p[] = "a

有以下程序: #include <iostream> #include <string> usxng namespace std; int main() { char p[] = "abcdefgh"; cout<<strlen(strcpy(p,"12345"))<<end1; return 0; } 执行后输出的结果是()。

A.8

B.12

C.5

D.7

点击查看答案
第2题
有以下程序:#include <iostream>#include <string>using namespace std;int main (){ char s[]="

有以下程序: #include <iostream> #include <string> using namespace std; int main () { char s[]="\n123\\"; cout<<strlen (s) <<", "<<sizeof (s) <<end1; return 0; }

A.赋初值的字符串有错

B.6,7

C.5,6

D.6,6

点击查看答案
第3题
有以下程序#include<stdio.h>#include<string.h>main(){char x[]=“STRING”;x[0]=0;

有以下程序

#include<stdio.h>

#include<string.h>

main()

{char x[]=“STRING”;

x[0]=0;x[1]=’\0’;x[2]=’0’;

printf(”%d%d\n”,sizeof(x),strlen(x));

}

程序运行后的输出结果是()。

A.6 1

B.7 0

C.6 3

D.7 1

点击查看答案
第4题
有以下程序#include <iostream>#include <string>using namespace std;class base{private:char

有以下程序 #include <iostream> #include <string> using namespace std; class base { private: char baseName[10]; public: base () { strcpy(baseName,"Base"); } virtual char *myName() { return baseName; } char *className() { return baseName; } }; class Derived : public base { private: char derivedName[10]; public: Derived() { strcpy(derivedName,"Derived"); } char *myName() { return derivedName; } char *className() { return derivedName; } }; void showPtr(base &p) { cout<<p.myName () <<" "<<p.className (); } int main () { base bb; Derived dd; showPtr(dd); return 0; } 运行后的输出结果为

A.Derived Base

B.Base Base

C.Derived Derived

D.Base Derived

点击查看答案
第5题
有以下程序#include<iostream>#include<string>using namespace std;class base{private:charbas

有以下程序 #include<iostream> #include<string> using namespace std; class base { private: charbaseName[10]; public: base() { strcpy(baseName,"Base"); } virtual char*myName() return baseName; } char *className() { return baseName; } }; class Derived: public base { private: char derivedName[10]; public: Derived() { strcpy(derivedName,"Derived"); } char *myName() { return derivedName; } char *className() { return derivedName; } }; void showPtr(base &p) { cout<<p.myName0<<" "<<p.className(); } int main() { base bb; Derived dd; showPtr(dD) ; retum 0; } 动行后的输出结果为

A.Derived Base

B.Base Base

C.Derived Derived

D.Base Derived

点击查看答案
第6题
若输入bcdefgh、m、abcdefg,以下程序的输出结果为()。#include<stdio.h>#include<string.h>main(){i

若输入bcdefgh、m、abcdefg,以下程序的输出结果为()。 #include<stdio.h> #include<string.h> main() { int i; char string[20],str[3][20]; for(i=0;i<3;i++)gets(str[i]); if(strcmp(str[0],str[1])>0) strcpy(string,str[0]); else strcpy(string,str[1]); if(strcmp(str[2],string)>0) strcpy(string,str[2]); printf("%s",string); }

A.bcdefgh

B.m

C.abcdefg

D.bcdefgh或abcdefg

点击查看答案
第7题
以下程序中函数scmp的功能是返回形参指针s1和s2所指字符串中较小字符串的首地址。#include<string

以下程序中函数scmp的功能是返回形参指针s1和s2所指字符串中较小字符串的首地址。 #include<string> char*scmp(char*s1,char*s2) { if(strcmp(s1,s2)<0) return(s1); else retrun(s2); } main() { int i;char string[20],str[3][20]; for(i=0;i<3;i++)gets(str[i]); strcpy(string,scmp(str[0],str[1]);//库函数strcpy对字符串进行复制 strcpy(string,scmp(string,str[2])); puts(string) } 若运行时依次输出:abcd、abba和abc三个字符串,则输出结果为()。

A.abcd

B.abba

C.abc

D.abca

点击查看答案
第8题
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【说明】 字符串在程序设计中扮演着重要

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。

【说明】

字符串在程序设计中扮演着重要角色。现需要设计字符串基类string,包含设置字 符串、返回字符串长度及内容等功能。另有一个具有编辑功能的串类edlt_string,派生于string,在其中设置一个光标,使其能支持在光标处的插入、删除操作。

【程序】

include <iostream.h>

include <stdio.h>

include <string.h>

class string

{

int length;

char *data;

public:

int get_length() {return length;}

char *get_data() {return data;}

~string() {delete data;}

int set data(int in_length, char *in_data);

int set_data(char *data);

void print() {cout<<data<<endl;}

};

class edit_string: public string

{

int cursor;

public:

int get_cursor() {return cursor;}

void move_cursor(int dis) {cursor=dis;}

int add_data(string *new_data);

void delete_data(int num);

};

int string::set_data(int in_length,char *in_data)

{

length=in_length;

if(!data)

delete data;

(1)

strcpy(data,in_data);

return length;

}

int string::set data(char *in_data)

{

(2)

if(!data)

delete data;

(1)

strcpy(data,in_data);

return length;

}

int edit_string::add_data(string *new_data)

{

int n,k,m;

char *cp,*pt;

n=new_data->get_length();

pt=new_data->get_data();

cp=this->get_data();

m=this->get_length();

char *news=new char[n+m+1];

for(int i=0; i<cursor; i++)

news[i]=cp[i];

k=i;

for(int j=0; j<n; i++,j++)

news[i]=pt[j];

cursor=i;

for(j=k; j<m; j++,i++)

(3)

news[i]='\0';

(4)

delete news;

return cursor;

}

void edit string::delete_data(int num)

{

int m;

char *cp;

cp=this->get_data();

m=this->get_length();

for(int i=cursor; i<m; i++)

(5)

cp[i]='\0';

}

点击查看答案
第9题
请读程序: # includde<stdio.h> # include<string.> void fun(char * s) {char a[10]; str

请读程序: # includde<stdio.h> # include<string.> void fun(char * s) {char a[10]; strcpy(a,"STRING"); s=a; } main() { char*p; fun(p); print{("%s\n",p); } 上面程序的输出结果(表示空格) ()

A.STRING

B.STRING

C.STRING

D.不确定的值

点击查看答案
第10题
试题五(共15分) 阅读以下说明和 C++代码,将应填入 (n) 处的语句或语句成分写在答题纸的对应栏内。

试题五(共15分)

阅读以下说明和 C++代码,将应填入 (n) 处的语句或语句成分写在答题纸的对应栏内。

【说明】

某数据文件students.txt的内容为100名学生的学号和成绩,下面的程序将文件中的数据全部读入对象数组,按分数从高到低进行排序后选出排名前 30%的学生。

【C++代码】

#include <iostream>

#include <fstream>

#include <string>

using namespace std;

class Student {

private:

string sNO; //学号

int credit; //分数

public:

Student(string a,int b) { sNO = a; credit = b;}

Student(){}

int getCredit();

void out();

};

(1) ::getCredit() {

return credit;

}

(2) ::out() {

cout << "SNO: " << sNO << ", Credit=" << credit << endl;

}

class SortStudent {

public:

void sort(Student *s, int n);

SortStudent(){}

};

void SortStudent::sort(Student *s,int n) {

for(int i = 0; i < n-1; i++) {

for(int j = i+1; j < n; j++) {

if(s[i]. (3) < s[j]. (4) ) {

Student temp = s[i]; s[i] = s[j]; s[j] = temp;

}

}

}

}

int main(int argc, char* argv[])

{

const int number = 100; //学生总数

ifstream students;

students.open("students.txt");

if(!students.is_open()) {

throw 0;

}

Student *testStudent = (5) [number];

int k = 0;

string s;

while (getline(students,s,'\n')) { //每次读取一个学生的学号和成绩

Student student(s.substr(0,s.find(',')), atoi(s.substr(s.find(',')+1).c_str()));

testStudent[k++] = student;

}

students.close();

(6) ;

ss.sort(testStudent,k);

cout <<"top 30%: "<<endl;

for(k = 0; k < number * 0.3; k++) {

testStudent[k].out();

}

delete []testStudent;

return 0;

}

点击查看答案
第11题
阅读下列程序说明和C代码,将应填入(n)处的字句写在对应栏内。[函数2.1说明] 函数void find(int *a

阅读下列程序说明和C代码,将应填入(n)处的字句写在对应栏内。

[函数2.1说明]

函数void find(int *a, int n, int * max, int * min)的功能是在长度为n的整型数组a中,查找最大元素和最小元素的下标。main()中给出了调用find函数的一个实例。

[函数2.1]

include<stdio.h>

void find(int *a, int n,int *max,int * min)

{ int i;

*max =* min=0;

for(i=1;i<n;i+ +)

if(a[i]>a[* max]) (1);

else if(a[i]<a[*min]) (2);

return;

main()

{ int a[]={4,6,8,9,0,6},max,min;

find(a,6,(3));

printf("%5d%5d\n", max,min);

}

[函数2.2说明]

以下程序用来对从键盘上输入的两个字符串进行比较,然后输出两个字符串前端的公共部分。例如:输入的两个字符串分别是abcdefg和abceef,则输出为abc。

[函数2.2]

include <stdio.h>

main()

{ char str1[100],str2[100],str[100],c;

int i=0,s;

printf("\nInput string 1:");gets(str1);

printf("\nInput string 2:");gets(str2);

while(((4))&&(str1[i]!='\0')&&(str2[i]!='\0')){

(5);

i++;

}

printf("%s\n",str);

}

点击查看答案
退出 登录/注册
发送账号至手机
密码将被重置
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改