| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 937 人关注过本帖
标题:有没有高手在线?
只看楼主 加入收藏
概率
Rank: 1
来 自:江西省奉新县
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-6-18
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:12 
有没有高手在线?
我想在线请教高手一个程序的错误问题。在线等。谢哈!
搜索更多相关主题的帖子: 在线 
2011-06-19 10:25
try_catch
Rank: 2
等 级:论坛游民
帖 子:32
专家分:82
注 册:2011-6-17
收藏
得分:4 
直接发出来。。或者提问把
2011-06-21 05:54
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:4 
嗯,同意二楼。在线等效率也不是很高。
2011-06-21 07:49
概率
Rank: 1
来 自:江西省奉新县
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-6-18
收藏
得分:0 
这个程序是这样的,我改了N久,也请教了身边的同学,还是有两个错改不出来,希望各位大侠帮帮忙,看看还有救不?
#include<iostream.h>
#include<string.h>
class wang
{
public:
friend int main();
wang();
wang(wang&s);
wang operator=(wang&s);
wang operator==(wang&s);
wang operator<(wang&s);
wang operator>(wang&s);
wang operator+(wang&s);
chuanchang(wang&s);
char *charu(char *s1,char *s2,int a);
shanchu(wang&s);
zichuan(wang&s);
void GetNext(char *t,int *next);
private:
    char s;
}
wang operator==(wang&s1,wang&s2)
{
s1=s;
cout<<"请输入要比较的字符串s2:"<<endl;
cin>>s2;
if((s2)==0)
return true;
else
return false;
}
wang operator<(wang&s1,wang&s2)
{
s1=s;
cout<<"请输入要比较的字符串s2:"<<endl;
cin>>s2;
if((s2)<0)
return true;
else
return false;
}
wang operator>(wang&s1,wang&s2)
{
s1=s;
cout<<"请输入要比较的字符串s2:"<<endl;
cin>>s2;
if((s2)>0)
return true;
else
return false;
}
wang operator+(wang&s1,wang&s2)
{
s1=s;
cout<<"请输入想要连接的字符串:"<<endl;
cin>>s2;
char*temp;
temp=new char[strlen(s1)+strlen(s2)+1];
strcpy(temp,s1);
strcat(temp,s2);
wang result(temp);
return result;
}
chuanchang(wang&s)
{
s1=s;
cout<<"该字符串的长度是:"<<strlen(s1)<<endl;
}
char *charu(char *s1,char *s2,int a)
{
int a;
s1=s;
cout<<"请输入要插入的字符串:"<<endl;
cin>>s2;
cout<<"输入插入处的下标:"<<endl;
cin>>a;
for(int m = 0;s1[m] != '\0';m++);
for(int n = 0;s2[n] != '\0';n++);
char *ch = new char [m + n];
int i,j;
for(i = 0;i <= a;i++)
ch[i] = s1[i];
for(j = 0;s2[j] != '\0';j++,i++)
ch[i] = s2[j];
for(j = a + 1;s1[j] != '\0';i++,j++)
ch[i] = s1[j];
ch[i] = '\0';
char *p = charu(s1,s2,a);
cout<<"插入后的字符串为:"<<p<<endl;
}
shanchu(wang&s)
{
s1=s;
int i,j;
for(i=0,j=0;s[i]!=0;i++,j++)if(s[j]>='0'&&s[j]<'10')
i--;elses[i]=s[j];cout<<"字符串删除后输出是:"<<s<<endl;}
zichuan(wang&s)
{
s1=s;
int start,n,s3;
cout<<"请输入字串的起始位置:"<<endl;
cin>>start;
cout<<"请输入子串的长度:"<<endl;
cin>>n;
s3=s1.assign(s1,start-1,n);
cout<<s3.data()<<endl;
}
void GetNext(char *s2,int *next)
{
s1=s;
cout<<"请输入s2串:"<<endl;
cin>>s2;
int i = 1,j = 0;//设置初始下标i和j
int n = strlen(s2);//s2串的长度为n
next[0] = -1;
next[1] = 0;
while(i < n)
{
if((j == -1) || (s2[j] == s2[i]))
{next[++i] = ++j;}
else
{j = next[j];}
int KMP(char *s1,char *s2)
{
int n = strlen(s1);  //输入s1串的长度n
int m = strlen(s2);  //输入s2串的长度m
int *next = new int[m];
GetNext(s2,next);
for(int i=0,j=0;i<n&&j<m;)//循环直到串s1中所剩字符长度小于s2的长度或s2中所有字符均比较完;
{
if((j == -1)||(s1[i] == s2[j]))
{
i++;
j++;
}
else
{j = next[j];}
}
return (j==m?i-j:-1);
}

int pos;//中间量,判断是否在s1串中找到s2串
pos = KMP(s1,s2); //调用kmp算法
if(pos != -1)//pos等于-1,说明没有在s1串中找到s2串
{
int i = 0;
cout<<"匹配成功!"<<endl;
cout<<"找到s2串:";
while(i < strlen(s2))
{   
cout<<s1[pos+i];
i++;
}
cout<<endl;
}
else  
{
cout<<"在串s1中没有找到s2串!"<<endl;
}
return 0;
}
}
void main()
{
int num=0,s;
cout<<"请输入一个字符串s:"<<endl;
cin>>s;
while(num!=10)
{
cout<<"请选择功能序号:"<<endl;
cout<<"1>比较是否相等       2>比较是否小于       3>比较是否大于       4>连接       5>求串长       6>串插入       7>串删除       8>求子串       9>串匹配       10>退出"<<endl;
cin>>num;
if(num==1)bool operator==(wang&s1,wang&s2);
if(num==2)bool operator<(wang&s1,wang&s2);
if(num==3)bool operator>(wang&s1,wang&s2);
if(num==4)bool operator+(wang&s1,wang&s2);
if(num==5)chuanchang(wang&s);
if(num==6)char *charu(char *s1,char *s2,int a);
if(num==7)shanchu(wang&s);
if(num==8)zichuan(wang&s);
if(num==9)void GetNext(char *t,int *next);
}
}
2011-06-21 09:15
kelas
Rank: 6Rank: 6
等 级:侠之大者
帖 子:176
专家分:434
注 册:2010-5-28
收藏
得分:4 
既然都贴了、为什么不连同错误信息都贴出来呢
2011-06-21 11:07
概率
Rank: 1
来 自:江西省奉新县
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-6-18
收藏
得分:0 
不好意思啊,情急就忘了,错误是这样的
Compiling...
15.cpp
C:\Users\Administrator\Desktop\新建文件夹\15.cpp(20) : error C2143: syntax error : missing ';' before '=='
C:\Users\Administrator\Desktop\新建文件夹\15.cpp(20) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

15.obj - 2 error(s), 0 warning(s)
麻烦各位帮帮忙哈
2011-06-21 14:10
lz1091914999
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:四川
等 级:贵宾
威 望:37
帖 子:2011
专家分:5959
注 册:2010-11-1
收藏
得分:4 
class wang
{
public:
friend int main();
wang();
wang(wang&s);
wang operator=(wang&s);
wang operator==(wang&s);
wang operator<(wang&s);
wang operator>(wang&s);
wang operator+(wang&s);
chuanchang(wang&s);
char *charu(char *s1,char *s2,int a);
shanchu(wang&s);
zichuan(wang&s);
void GetNext(char *t,int *next);
private:
    char s;
}; // 这里要有分号

My life is brilliant
2011-06-21 15:20
概率
Rank: 1
来 自:江西省奉新县
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-6-18
收藏
得分:0 
不对诶,我加分号以后错误更多了,还请各位弄到c++里面运行下,感激不尽!
2011-06-21 16:16
specilize
Rank: 4
等 级:业余侠客
帖 子:126
专家分:247
注 册:2011-2-20
收藏
得分:4 
看了一下,错了一大堆啊,举个例子,wang operator==(wang&s1,wang&s2)这个函数又不是成员函数,你这样写s1=s;肯定是不对的啊,而且我发现楼主返回void类型都不写的,这样不太好吧,而且为什么要用<iostream.h>不用<iostream>,楼主还是慢慢看着提示的错误改正吧
2011-06-21 20:28
概率
Rank: 1
来 自:江西省奉新县
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-6-18
收藏
得分:0 
这么长的程序我改不来啊,所以才请教的。。。。。。这个程序已经摧残我几天了,希望大家耐心的指点指点咯。。。。。。
2011-06-21 20:33
快速回复:有没有高手在线?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028625 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved