PDA

View Full Version : اشکال این برنامه کجاست؟؟؟



pooria_googooli
سه شنبه 06 بهمن 1388, 12:27 عصر
دوستانم این برنامه کاکل کامل فقط نمیونم چرا وقتی میخواد همه اسم هارو نشون بده قاطی میکنه . جوری نوشتم که بر اساس حروف الفبا مرتب کنه. تو رو قرآن کمکم کنید. خواهش میکنم.

/////////// ///////////
///////////THIS PROGRAM IS PRODUCED BY POORIA LAJEVARDY///////////

#include<iostream.h>
#include<string.h>
#include<conio.h>
#include<stdio.h>
int main()
{
int h,work=1;
int n=0;
char search[40];
char help[40];
char help1[40];
char help2[40];
char help3[40];
char name[7][40];
char family[7][40];
char tel[7][40];
char address[7][40];
char se2[40];
cout<<"Welcome too this program\nplease inter any key to continu";
while(work!=0)
{
while(work==1)
{
cin.getline(se2,40);


cout<<"inter the name of "<<(n+1)<<"th person"<<endl;
cin.getline(name[n],40);
cout<<"inter the family of "<<(n+1)<<"th person"<<endl;
cin.getline(family[n],40);
cout<<"inter the tel of "<<(n+1)<<"th person"<<endl;
cin.getline(tel[n],40);
cout<<"inter the address of "<<(n+1)<<"th person"<<endl;
cin.getline(address[n],40);
clrscr();

n++;

cout<<"insert 0 for quit\ninsert 1 too increase number\ninsert 2 too search\ninsert 3 to remove a number\ninsert 4 too clear all number\ninsert 5 too show all numbers"<<endl;
cin>>work;
}
while(work==2)
{
int o=0;
char se[40];
int save[20];
int snu;
cout<<"insert 0 for quit\ninsert 1 too search by name\ninsert 2 search by family\nisert 3 too search by address"<<endl;
cin>>snu;
if(snu==1)
{
scanf("%s",search);
char *pos;
char s1[90],s2[90];
for(int j=0;j<=10;j++)
{
//string s1 =address[i][];
//string s2 =search[];
strcpy(s1,name[j]);
strcpy(s2,search);
pos = strstr(s1,s2);
if(pos!=NULL)
{
h=j;
break;
}

}
cout<<"name is : "<<name[h]<<endl<<"family is : "<<family[h]<<endl<<"tel is : "<<tel[h]<<"address is : "<<address[h]<<endl<<"-----------"<<endl;



}
if(snu==2)
{
scanf("%s",search);
char *pos;
char s1[90],s2[90];
for(int j=0;j<=10;j++)
{
//string s1 =address[i][];
//string s2 =search[];
strcpy(s1,family[j]);
strcpy(s2,search);
pos = strstr(s1,s2);
if(pos!=NULL)
{
h=j;
break;
}

}
cout<<"name is : "<<name[h]<<endl<<"family is : "<<family[h]<<endl<<"tel is : "<<tel[h]<<"address is : "<<address[h]<<endl<<"-----------"<<endl;

}
if(snu==3)
{
scanf("%s",search);
char *pos;
char s1[90],s2[90];
for(int j=0;j<=10;j++)
{
//string s1 =address[i][];
//string s2 =search[];
strcpy(s1,address[j]);
strcpy(s2,search);
pos = strstr(s1,s2);
if(pos!=NULL)
{
h=j;
break;
}

}
cout<<"name is : "<<name[h]<<endl<<"family is : "<<family[h]<<endl<<"tel is : "<<tel[h]<<"address is : "<<address[h]<<endl<<"-----------"<<endl;

}
cout<<"insert 0 for quit\ninsert 1 too increase number\ninsert 2 too search\ninsert 3 to remove a number\ninsert 4 too clear all number\ninsert 5 too show all numbers"<<endl;
cin>>work;
}
while(work==3)
{
int rn,check=0;
char ch;
cout<<"which person do you want to remove?"<<endl;
while(check==0)
{
check=1;
cin>>rn;
if(rn>n)
{
cout<<"we havn't this number.pleas inter correct number"<<endl;
check=0;
}
}
cout<<"name is : "<<name[rn-1]<<endl<<"family is : "<<family[rn-1]<<endl<<"tel is : "<<tel[rn-1]<<"address is : "<<address[rn-1]<<endl;
cout<<"are you sure too remove this number? y/n";
cin>>ch;
if(ch=='y')
{
for(int i=rn;i<n;i++)
{
strcpy(name[rn-1],name[rn]);
strcpy(family[rn-1],family[rn]);
strcpy(tel[rn-1],tel[rn]);
strcpy(address[rn-1],address[rn]);
}
n--;
}
cout<<"insert 0 for quit\ninsert 1 too increase number\ninsert 2 too search\ninsert 3 to remove a number\ninsert 4 too clear all number\ninsert 5 too show all numbers"<<endl;
cin>>work;
clrscr();
}
if(work==4)
{
char ch;
cout<<"are you sure too remove these number?y/n";
cin>>ch;
const char *t="$";
if(ch=='y')
{
for(int i=0;i<n;i++)
{
strcpy(name[i],t);
strcpy(family[i],t);
strcpy(tel[i],t);
strcpy(address[i],t);
}
n=0;
}
cout<<"insert 0 for quit\ninsert 1 too increase number\ninsert 2 too search\ninsert 3 to remove a number\ninsert 4 too clear all number\ninsert 5 too show all numbers"<<endl;
cin>>work;
}
if(work==5)
{
clrscr();

for(int z=0;z<=7;z++)
{
for (int x=0;x<=7;x++)
{
if (strcmp(family[z],family[x])>0)
{
strcpy(help,name[z]);
strcpy(name[z],name[x]);
strcpy(name[x],help);
strcpy(help1,family[z]);
strcpy(family[z],family[x]);
strcpy(family[x],help1);
strcpy(help2,address[z]);
strcpy(address[z],address[x]);
strcpy(address[x],help2);
strcpy(help3,tel[z]);
strcpy(tel[z],tel[x]);
strcpy(tel[x],help3);
}
}
}

for(int i=0;i<n;i++)
{
cout<<(i+1)<<".name is : "<<name[i]<<endl<<(i+1)<<".family is : "<<family[i]<<endl<<(i+1)<<".tel is : "<<tel[i]<<endl<<".address is : "<<address[i]<<endl<<"-----------"<<endl;
}
cout<<endl<<endl;
cout<<"insert 0 for quit\ninsert 1 too increase number\ninsert 2 too search\ninsert 3 to remove a number\ninsert 4 too clear all books"<<endl;
cin>>work;

}
clrscr();
}

return 0;
}

Salar Ashgi
سه شنبه 06 بهمن 1388, 20:40 عصر
کدتون خیلی طولانی هستش ، ولی اولین اشکال عمده ای که هستش اینه که شما از یک آرایه دوبعدی بعنوان

یک آرایه تک بعدی استفاده کردید :



char name[7][40];
cin.getline(name[n],40);//Error

pooria_googooli
سه شنبه 06 بهمن 1388, 21:12 عصر
خب میخواستم رشته دریافت کنم. وقتی دو بعدی تعریف کردم, چجوری رشته از کاربر بگیرم؟

pooria_googooli
سه شنبه 06 بهمن 1388, 21:13 عصر
بعدم اونجاهاشو ارور نمیده. یعنی به هیچ جاش نه ارور میده نه مشکلی داره. فقط مرتب کردن مشکل داره. یعنی همون show all