搜题
网友您好,请在下方输入框内输入要搜索的题目:
搜题
题目内容 (请给出正确答案)
提问人:网友abcbuzhiming 发布时间:2022-01-07
[主观题]

阅读程序。阅读下列C++程序,对每条语句进行注释,说明其作用。 #include <iostream> using na

阅读程序。阅读下列C++程序,对每条语句进行注释,说明其作用。 #include <iostream> using namespace std; class CTest { private: int x, y; public: CTest(int p1 = 0, int p2 = 0) { x = p1; y = p2; } CTest(CTest &p) { x = p.x; y = p.y; } void Show() { cout << x << “, “ << y << endl; } }; int main() { CTest obj1; obj1.Show(); CTest obj2(2, 5); obj2.Show(); CTest obj3(obj2); obj3.Show(); return 0; }

简答题官方参考答案 (由简答题聘请的专业题库老师提供的解答)
  抱歉!暂无答案,正在努力更新中……
更多“阅读程序。阅读下列C++程序,对每条语句进行注释,说明其作用。 #include <iostream> using na”相关的问题
第1题
●试题五

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

【程序说明】

本程序先从文件读入各考生的准考证号(设为整型数)及成绩,并将其存放在一棵检索二叉树上,二叉树结点的健值是成绩,每个结点带一链表,链表结点存放取得该成绩的考生的准考证号。然后,程序按中序遍历检索二叉树,从高分到低分输出结果,使每行输出成绩及其取得成绩的考生的准考证号。

【程序】

#include

typedef struct idnode {

int id;

struct idnode * next;

} IdNode;

typedef struct marknode {

int mark;

IdNode *head;

struct marknode *left, *right;

} MarkNode;

char fname [ ]="sp07.dat";

main()

{ int id, mark;

MarkNode *root=null;

FILE *fp=fopen(fname,"r");

if(!fp) {

printf("file%s open error.\n", fname);

exit(0);

}

while (!feop(fp)) {

fscanf(fp,"%d%d", &id, &mark);

btree(&root, id, mark);

}

fclose(fp);

print(root);

}

btree(MarkNod**mpptr, int id, int mark)

{ IdNode *ip;

MarkNode *mp=*mpptr;

if (1) {

if (mark==p->mark) addIdNODE ((2) , id);

else if (mark>mp->mark) btree (&mp->left, id, mark);

else btree(&mp->right, id, mark);

}else

{ mp=(marknode *) malloc(sizeo (marknode));

mp->mark=mark;

mp->left=mp->right=NULL;

(3)

addIdNode(&mp->head, id);

(4) ;

}

}

addIdNode(IdNode **ipp, int id)

{IdNode *ip=*ipp;

if ((5) )addIdNode ((6) ), id;

else{

ip=(IdNode *)malloc(sizeof(IdNode));

sp->id=id;

ip->next=NULL;

(7)

}

}

print(MarkNode *mp)

{ IdNode *ip, *ip0;

if (mp){

print (mp->left);

printf("%6d:\t",mp->mark);

ip=mp->head;

while(ip){

printf("%6d",ip->id);

ip0=ip;

ip=ip->next;

free(ip0);

}

printf("\n");printf(mp->right);free(mp);

}

}

点击查看答案
第2题
阅读程序。阅读下列C++程序。阅读后请说明程序的功能,并对每条语句进行注释,说明其作用。添加注释并提交源程序(请粘贴源代码或屏幕截图,不要上传附件)。 #include <iostream> using namespace std; int fun(char str[ ]) { int n = 0, num = 0; while (str[n] != ‘\0’) { if (str[n] >= ‘A’ && str[n] <= ‘z’ || str[n]>= ‘a’ && str[n] <= ‘z’) num++; n++; } return num; int main( ) { cout fun( “123 abc abc” endl; 0;>
点击查看答案
第3题
阅读以下程序说明和C++程序,将程序段中(1)~(5)空缺处的语句填写完整。

【说明】

以下【C++程序】实现一个简单的小型复数类MiniComplex,该复数类能进行输入、输出、复数的加法、减法、乘法和除法运算,还可以进行复数的相等比较。

【C++程序】

ifndef H_MiniComplex

define H_MiniComplex

include <iostream>

using namespace std;

class MiniComplex{

public: //重载流插入和提取运算符

(1) ostream&operator<<(ostream &osObject,const MiniComplex&complex){

osObject<<"("<<complex.realPart<<"+"<<complex.imagPart<<"i"<<")";

return osObject;

}

(2) istream&operator>>(istream&isObject, MiniComplex&complex){

char ch;

isObject >>complex.realPart>>ch>>complex.imagPart>>ch;

return isObject;

}

MiniComplex(double real=0,double imag=0); //构造函数

MiniComplex operator+(const MiniComplex&otherComplex)const; //重载运算符+

MiniComplex operator-(const MiniComplex&otherComplex)const; //重载运算符-

MiniComplex operator*(const MiniComplex&otherComplex)const; //重载运算符*

MiniComplex operator/(const MiniComplex&otherComplex)const; //重载运算符/

bool perator==(const MiniComplex&otherComplex)const; //重载运算符==

private :

double (3);

double imagPart;

};

end if

include "MiniComplex.h"

bool MiniComplex::operator==(const MiniComplex&otherComplex)const{

return(realPart==otherComplex.realPart&&imagPart==ortherComplex.imagPart);

}

MiniComplex::MiniComplex(double real,double imag){

realPart== real; imagPart==imagPart;

}

MiniComplex MiniComplex::operator+(const MiniComplex&otherComplex)const{

MiniComplex temp;

temp.realPart = realPart+ortherComplex. realPart;

temp.imagPart = imagPart +ortherComplex. imagPart;

return temp;

}

(4)

{ MiniComplex temp;

temp.realPart= realPart-ortherComplex. realPart;

temp.imagPart = imagPart-ortherComplex. imagPart;

return temp;

}

MiniComplex MiniComplex::operator*(const MiniComplex&otherComplex)const{

MiniComplex temp;

temp.realPart = (realPart*ortherComplex. realPart)-(imagPart *ortherComplex.imagPart);

temp.imagPart = (realPart*ortherComplex. imagPart)+(imagPart *ortherComplex.realPart);

return temp;

}

MiniComplex MiniComplex::operator/(const MiniComplex&otherComplex)const{

MiniComplex temp;

float tt;

tt=1/(ortherComplex.realPart*ortherComplex.realPart+ortherComplex.imagPart *ortherComplex. imagPart);

temp.realPart=((realPart*ortherComplex, realPart)+(imagPart *ortherComplex. imagPart))*tt;

temp.imagPart =((imagPart *ortherComplex. realPart)-(realPart*ortherComplex. imagPart))*tt;

return temp;

}

include <iostream>

include <MiniComplex.h>

using namespace std;

int main(){

MiniComplex numl(23, 34),num2(56, 35);

cout<<"Initial Value of num1="<<num1<<"\n Initial Value of num2="<<num2<<end1;

cout<<num1<<"+"<<num2<<"="<<num1+num2<<end1; //使用重载的加号运算符

cout<<num1<<"-"<<num2<<"="<<num

点击查看答案
第4题
阅读下列程序说明和C代码,填入(n)处。

【说明】

幼儿园有n(<20)个孩子围成一圈分糖果。老师先随机地发给每个孩子若干颗糖果,

然后按以下规则调整:每个孩子同时将自己手中的糖果分一半给坐在他右边的小朋友。如共有8个孩子,则第1个将原有的一半分给第2个,第2个将原有的一半分给第3个,……,第8个将原有的一半分给第1个,这样的平分动作同时进行。若平分前,某个孩子手中的糖果是奇数颗,则必须从老师那里要一颗,使他的糖果数变成偶数。小孩人数和每个小孩的初始糖果数由键盘输入。下面的程序可求出经过多少次上述这样的调整,使每个孩子手中的糖果—样多,调整结束时每个孩子有糖果多少颗,在调整过程中老师又新增发了多少颗糖果。

【程序】

include

define N 20

int allEqual (int a[ ],int n) /*检查每个孩子手中的糖果是否一样多*/

{ iht i;

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

if(a[O]!=a[i]) return O;

return 1;

}

int a[N], b[N];

void main ()

{ int i, n, addk, loopc;

printf("Enter n((20)\n"); scanf("%d", &n);

printf ("Enter data\n");

for(i=O; i(n; i++) scanf("%d", &a[i]);

addk=O;(1);

while (2){ /*平分循环*/

loopc++;

for (i=O; i (n; i++){ /*为一次调整作准备*/

if(a[i]%2) { a[i]++;(3); }

if (i<n-1) b[i+1]=a[i]/2; else(4)

a[i]/=2;

}

for(i=O; i<n; i++)(5); /*完成一次调整*/

}

printf("调整%d次\n", loopc); printf("每个孩子有%d颗糖果\n", a[0]);

printf("调整过程中新增发%d颗糖果。\n", addk); }

点击查看答案
第5题
程序填空。程序功能:将一组整数从大到小排序。 #include <stdio.h> #define N 5 void main( ) { int i, j, temp, score[N] = {12,4,25,8,3}; for ( i=0 ;i<n-1;i++) { for (j="i+1;__________;" j++) if(score[i] score[j]) temp="score[i];" score[i]="score[j];" score[j]="temp;" } ( i="0;i&lt;N;i++)" printf("%d\t", score[i]); 上面程序代码中空白处所填语句正确的为(> A、j<n<br> B、j<n-1<br> C、j<=n<br> D、j<n-1-i<br>
点击查看答案
第6题
●试题四

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

【程序4.1说明】

"背包问题"的基本描述是:有一个背包,能盛放的物品总重量为S,设有N件物品,其重量分别为w1,w2,...,wn,希望从N件物品中选择若干件物品,所选物品的重量之和恰能放入该背包,即所选物品的重量之和等于S。

如下程序均能求得"背包问题"的一组解,其中程序4.1是"背包问题"的递归解法,而程序4.2是"背包问题"的非递归解法。

【程序4.1】

#include

#define N 7

#define S 15

int w[N+1]={0,1,4,3,4,5,2,7};

int knap(int s,int n)

{ if(s==0)return 1;

if (s<0||(s>0& &n<1))return 0;

if((1) )){

printf(″%4d″,w[n]);return 1;

}return (2) ;

}

main(){

if(knap(S,N))printf(″OK!\n″);

else printf(″N0!\n″);

}

【程序4.2】

#include

#define N 7

#define S 15

typedef struct {

int s;

int n:

int job;

} KNAPTP;

int w[N+1]={0,1,4,3,4,5,2,7};

int knap (int s,int n);

main() {

if (knap (S,N)) printf (″OK!\n″);

else printf (″NO!\n″);}

int knap (int s,int n)

{ KNAPTP stack[100],x;

int top,k,rep;

x.s=s;x.n=n;

x.job=0;

top=l;stack[top]=x;

k=0;

while((3) ) {

x=stack [ top ];

rep=1;

while (!k && rep ) {

if (x.s==0)k=1;/*已求得一组解*/

else if (x.s<0 || x.n <=0)rep=0;

else{x.s= (4) ;x.job=1;

(5) =x;

}

}

if(!k){

rep=1;

while(top>=1&&rep){

x=stack[top--];

if(x.job==1){

x.s+=w[x.n+1];

x.job=2;

stack[++top]=x;

(6) ;

}

}

}

}

if(k){/*输出一组解*/

while(top>=1){

x=stack[top--];

if(x.job==1)

printf(″%d\t″,w[x.n+1]);

}

}

return k;

}

点击查看答案
第7题

对程序功能的描述,其中正确的是()。#include <stdio.h> #include <stdlib.h> int main() { FILE *in, *out; char infile[20],outfile[20]; scanf("%s",infile); scanf("%s",outfile); if ((in=fopen(infile,"r"))==NULL) { printf("cannot open infile\n"); exit(0); } if ((out=fopen(outfile,"w"))==NULL) { printf("cannot open outfile\n"); exit(0); } while(!feof(in)) fputc(fgetc(in),out); fclose(in); fclose(out); return 0; }

A、程序完成将磁盘文件的信息在屏幕上显示的功能

B、程序完成将两个磁盘文件合二为一的功能

C、程序完成将一个磁盘文件复制到另一个磁盘文件中的功能

D、程序完成将两个磁盘文件合并且在屏幕上输出的功能

点击查看答案
第8题
编写程序。编写一个关于圆形的C++程序。要求用定义一个圆形类Circle,其中包含如下成员: 1) 1个私有数据成员(半径)。 2) 3个公有函数成员(设置半径、计算面积、计算周长)。 3) 3个构造函数(不带参数的构造函数、带参数的构造函数和拷贝构造函数)。 主函数main使用圆形类Circle创建圆形对象,要求: 1) 定义一个圆对象c1,从键盘输入一个值x并将其设定为c1的半径,计算并显示c1的面积和周长 2) 再定义一个圆对象c2,并将半径初始化为2x,计算并显示c2的面积和周长 3) 再定义一个圆对象c3,并用c1初始化c3,计算并显示c3的面积和周长
点击查看答案
第9题
习题2.1 2,7,8,9 习题2.2 3,6,7,8 习题2.3 3,4,5,8
点击查看答案
第10题
习题3-1 3,4,5,8 习题3-2 1,2 习题3-3 1,2,5,8
点击查看答案
重要提示: 请勿将账号共享给其他人使用,违者账号将被封禁!
查看《购买须知》>>>
重置密码
账号:
旧密码:
新密码:
确认密码:
确认修改
购买搜题卡查看答案
购买前请仔细阅读《购买须知》
请选择支付方式
微信支付
支付宝支付
点击支付即表示你同意并接受《服务协议》《购买须知》
立即支付
搜题卡使用说明

1. 搜题次数扣减规则:

功能 扣减规则
基础费
(查看答案)
加收费
(AI功能)
文字搜题、查看答案 1/每题 0/每次
语音搜题、查看答案 1/每题 2/每次
单题拍照识别、查看答案 1/每题 2/每次
整页拍照识别、查看答案 1/每题 5/每次

备注:网站、APP、小程序均支持文字搜题、查看答案;语音搜题、单题拍照识别、整页拍照识别仅APP、小程序支持。

2. 使用语音搜索、拍照搜索等AI功能需安装APP(或打开微信小程序)。

3. 搜题卡过期将作废,不支持退款,请在有效期内使用完毕。

请使用微信扫码支付(元)

订单号:

遇到问题请联系在线客服

请不要关闭本页面,支付完成后请点击【支付完成】按钮
遇到问题请联系在线客服
恭喜您,购买搜题卡成功 系统为您生成的账号密码如下:
重要提示:请勿将账号共享给其他人使用,违者账号将被封禁。
发送账号到微信 保存账号查看答案
怕账号密码记不住?建议关注微信公众号绑定微信,开通微信扫码登录功能
警告:系统检测到您的账号存在安全风险

为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!

- 微信扫码关注简答题 -
警告:系统检测到您的账号存在安全风险
抱歉,您的账号因涉嫌违反简答题购买须知被冻结。您可在“简答题”微信公众号中的“官网服务”-“账号解封申请”申请解封,或联系客服
- 微信扫码关注简答题 -
请用微信扫码测试
欢迎分享答案

为鼓励登录用户提交答案,简答题每个月将会抽取一批参与作答的用户给予奖励,具体奖励活动请关注官方微信公众号:简答题

简答题官方微信公众号

简答题
下载APP
关注公众号
TOP