这是我们老师要求写的一个程序,可是关于后几个case要用到的sorting,他没教过
所以只好向各位求助了,如果可以的话麻烦帮忙写其中的一个就好了
还有就是case c 的for loop 不知道出了什么问题,麻烦帮忙修改~~~~~
//Program : MINI-PROJECT B
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
void main ()
{
char name[20],option=’any’;
char priority[99]={“”},name1[99][20]={“”},res=’any’,choice=’any’;
char delename[20];
char srchname[20],srchage;
int age,hp,i=0,age1[99]={“”},hp1[99]={“”},recno=0,srchhp;
printf(“Enter your name:”);
gets(name);
printf(“Enter your age:”);
scanf(“%d”,&age);
printf(“Enter your handphone number:”);
scanf(“%d”,&hp);
while(option!=’k’ &&option!=’K')
{
printf(“\n\t—————————————————”);
printf(“\n\tWelcome to the Simple Personal Organizer,%s!\n”,name);
printf(“\tChoose an option:\n”);
printf(“\t(a) Display personal information\n”);
printf(“\t(b) New contact entry\n”);
printf(“\t(c) Deletion of contact\n”);
printf(“\t(d) Search contact by name\n”);
printf(“\t(e) Search contact by age\n”);
printf(“\t(f) Search contact by handphone number\n”);
printf(“\t(g) Sort and list contacts by age\n”);
printf(“\t(h) Sort and list contacts by priority\n”);
printf(“\t(i) Sort and list contacts by name\n”);
printf(“\t(j) List the database\n”);
printf(“\t(k) Quit\n”);
printf(“\t—————————————————–”);
printf(“\n\tEnter Your Choice:”);
flushall();
scanf(“%c”,&option);
switch(option)
{
case ‘a’:
case ‘A’:printf(“\n\tName:%s”,name);
printf(“\n\tAge:%d”,age);
printf(“\n\tHandphone No:%d”,hp);
printf(“\n”);
system(“pause”);
break;
case ‘b’:
case ‘B’:res=’y';
while (res==’y'||res==’Y')
{
printf(“\n\tEnter the name[%d]:”,recno);
flushall();
gets(name1[recno]);
printf(“\tEnter the age[%d]:”,recno);
scanf(“%d”,&age1[recno]);
while (age1[recno]<1 ||age1[recno]>100)
{
printf(“\tInvalid value!\n”);
printf(“\tPlease enter again:”,recno);
scanf(“%d”,&age1[recno]);
}
printf(“\tEnter the handphone No[%d]:”,recno);
scanf(“%d”,&hp1[recno]);
printf(“\tWhat is the prioriry[%d] of this person?(High-H,Medim-M,Low-L):”,recno);
flushall();
scanf(“%c”,&priority[recno]);
recno=recno++;
printf(“\tDo you want to continue the new contact entry?(y/n)”);
flushall();
scanf(“%c”,&res);
}
printf(“\n\tNo. of contacts in the database:%d\n”,recno);
system(“pause”);
break;
case ‘c’:
case ‘C’:res=’y';
while (res==’y'||res==’Y')
{
printf(“\n\tName of the contact to be deleted:”);
flushall();
gets(delename);
for(i=0;i<recno;i++)
{
if(strcmp(name1[i],delename)==0)
{
strcpy(name1[i],”");
age1[i]=0;
hp1[i]=0;
strcpy(priority[i],”");
}
}
printf(“\tDo you want to continue?(y/n)”);
flushall();
scanf(“%c”,&res);
}
recno=recno-1;
printf(“\t%s removed from the list.Now there are %d coontacts.\n”,delename,recno);
system(“pause”);
break;
case ‘d’:
case ‘D’:res=’y';
while (res==’y'||res==’Y')
{
printf(“\n\tSearch contact by name\n”);
printf(“\tEnter Name to search:”);
flushall();
gets(srchname);
for(i=0;i<recno;i++)
{
if(strcmp(name1[i],srchname)==0)
{
printf(“\n\tName:%s”,name1[i]);
printf(“\n\tAge:%d”,age1[i]);
printf(“\n\tHandphone No:%d”,hp1[i]);
printf(“\n\tPriority:%c\n”,priority[i]);
}
/*else
{
printf(“\n\tNo such person!”);
}*/
}
printf(“\n\tDo you want to continue?(y/n)”);
flushall();
scanf(“%c”,&res);
}
system(“pause”);
break;
case ‘e’:
case ‘E’:res=’y';
while (res==’y'||res==’Y')
{
printf(“\n\tSearch contact by age\n”);
printf(“\n\tEnter Age to search:”);
scanf(“%d”,&srchage);
for(i=0;i<recno;i++)
{
if(age1[i]==srchage)
{
printf(“\n\tName:%s”,name1[i]);
printf(“\n\tAge:%d”,age1[i]);
printf(“\n\tHandphone No:%d”,hp1[i]);
printf(“\n\tPriority:%c\n”,priority[i]);
}
/*else
{
printf(“\n\tNo such person!”);
}*/
}
printf(“\n\tDo you want to continue?(y/n)”);
flushall();
scanf(“%c”,&res);
}
system(“pause”);
break;
case ‘f’:
case ‘F’:res=’y';
while (res==’y'||res==’Y')
{
printf(“\n\tSearch contact by Handphone No\n”);
printf(“\n\tEnter Handphone No to search:”);
scanf(“%d”,&srchhp);
for(i=0;i<recno;i++)
{
if(hp1[i]==srchhp)
{
printf(“\n\tName:%s”,name1[i]);
printf(“\n\tAge:%d”,age1[i]);
printf(“\n\tHandphone No:%d”,hp1[i]);
printf(“\n\tPriority:%c\n”,priority[i]);
}
/*else
{
printf(“\n\tNo such person!”);
}*/
}
printf(“\n\tDo you want to continue?(y/n)”);
flushall();
scanf(“%c”,&res);
}
system(“pause”);
break;
case ‘g’:
case ‘G’:printf(“\n\tSorting and list contacts by age.\n “);
break;
case ‘h’:
case ‘H’:
break;
case ‘i’:
case ‘I’:
break;
case ‘j’:
case ‘J’: printf(“\n\tNo\tName\tAge\tH/P\tPriority\n”);
printf(“\t********************************************\n”);
for (i=0;i<recno;i=i++)
{
printf(“\t%d\t%s\t%d\t%d\t%c\n”,i,name1[i],age1[i],hp1[i],priority[i]);
}
printf(“\t********************************************\n”);
system(“pause”);
break;
case ‘k’:
case ‘K’: printf(“\n\tThank you for using this program! “);
break;
default : printf(“\n\tNo such choice!Please check again.”);
printf(“\n”);
}
}
printf(“\n\n”);
}
>> 本文固定链接: http://www.vcgood.com/archives/3017
还有的就是case D、E、F中想做到找不到人时只出现一个“no such person”
不知道怎么改好
跪求帮助了
真的不知道怎么办好了
请帮忙
[;)]
将题目发上来吧
题目和上面程序中的选项一样,就是要做到可以满足选项的要求
麻烦帮忙看case C 中的for loop
还有介绍怎么做character的sorting
你还是发原题上来吧,很多数据类型你弄错了。
option=’any’也能通过?你用什么编译器的?
我大概明白题意了,不用原题了
哦
谢谢了
现在问题我解决了