我的作业,1个C++改错题目,一个数据结构的冒泡题目,都是简单的,帮帮忙呀!

来源:百度知道 编辑:UC知道 时间:2024/06/06 11:51:04
C++:分析下列程序中的错误,并说明出错原因。

# include
class base {
const int n;
public:
base() { cout < <”Initializing default\n”; }
base(int m) { cout < <”Initializing\n”; n=m; }
~base() { cout < <”Destroying\n”; }
};
void main()
{ base x=1;
base y=x;
}

数据结构:用冒泡排序法对输入的10个字符从小到大的顺序排序。请将程序补充完整并调试运行
#define N 10
char str[N]
main()
{int i,flag;
for(flag=1; flag=1;)
{printf(“\n 请输入10人字符:\n”);
scanf(“%s”,&str);
if(strlen(str)>N)
printf(“超出规定长度,请重新输入!”);
else
flag=0;
}
sort(str);
printf(“\n the answer is :”;
for(i=0;i <N;i++)
printf(“%c”,str[i])
}
sort(str)
char str[N];
{int I, j;
char t;
/*请在此处将函数补充完整*/
}
晚上结贴 明天要交了。

谢谢 dousion的,我再看看还又没有其他的,没有的话就是你了。

说老实话,我是写了第二题,才看的第一题。我真服了你基础差了。抄题好象抄的都不对。第二题前面我也给你改了些地方。你注意看下。

第一题大概:
类里的那个n,如果设成const,以后就不能对它赋值了。

再就是没有重载运算符,所以在主函数中的那两条语句都是错的。

其他的问题,我就也当你是抄错题了,这两个是最明显错的。

第二题
#include <stdio.h>
#include <string.h>
#define N 10
char str[N];
sort(str);
main()
{
int i,flag;
for(flag=1; flag==1;)
{
printf("\n 请输入10个字符:\n");
scanf("%s",&str);
if(strlen(str)>N)
printf("超出规定长度,请重新输入!");
else
flag=0;
}
sort(str);
printf("\n the answer is :");
for(i=0;i <N;i++)
printf("%c",str[i]);
}
sort(char str[])
{
int i, j;
char t;
for(i=0;i<N;i++)
for(j=0;j<N-i;j++)
if(str[j-1]>str[j])
{
t=str[j-1];
str[j-1]=str[j];
str[j]=t;
}
}

第一题,const i