怎么样把三个程序以组合成一个程序啊(以命令菜单方式供用户选择实现每个程序的功能)
三个程序都能运行成功的 就是不知道怎么第一个程序 是数字菱形排列
#include
void main()
{
int t,k,a,n,m;
printf("Input n:");
scanf("%d",&n);
for(int i=0;i0;a--)printf("%c",' ');
}
printf("\n");
}
}
第二个程序是扑克牌的自动发放
#include
#include
#include
#include
#include
#define CARD_NUM_OF_A_PACK 52
#define NUM_OF_PLAYERS 4
#define NUM_ONEPACK_OF_PLAYER (CARD_NUM_OF_A_PACK/4)
#define SIZE (sizeof(Card_t)*CARD_NUM_OF_A_PACK)
typedef struct tagCard
{
char value; char color;
}
Card_t;
void CardInit(Card_t **pInCard)
{
Card_t *pCard = *pInCard;
Card_t *pTempCard = NULL;
int i;
int j;
memset(pCard,0,SIZE);
pTempCard = pCard;
for(j = 1;j <= 4;j++)
{
for (i = 1;i <= CARD_NUM_OF_A_PACK/4;i++)
{
if (1 == j)
{
pTempCard->color = 'S';
}
else if (2 == j)
{
pTempCard->color = 'H';
}
else if (3 == j)
{
pTempCard->color = 'D';
}
else if (4 == j)
{
pTempCard->color = 'C';
}
if (i <= 10)
{
pTempCard->value = i;
}
else if(i == 11)
{
pTempCard->value = 'J';
}
else if(i == 12)
{
pTempCard->value = 'Q';
}
else if(i == 13)
{
pTempCard->value = 'K';
}
pTempCard++;
}
}
return;
}
void CardFree(Card_t **pCard)
{
if (*pCard)
{
free(*pCard);
*pCard = NULL;
}
}
void Deal(Card_t **pInCard)
{
Card_t players[NUM_OF_PLAYERS][CARD_NUM_OF_A_PACK/NUM_OF_PLAYERS];
int i;
int j;
int k;
int temp;
long cardUsedNum = 0;
int packOfCard = 0;
int playerNo = 0;
int playerCardNo = 0;
Card_t tempCard = {0};
int CartCount = 0;
Card_t *pCard = *pInCard;
int run = 1;
int cCount[NUM_OF_PLAYERS];
int hCount[NUM_OF_PLAYERS];
int dCount[NUM_OF_PLAYERS];
int sCount[NUM_OF_PLAYERS];
char c[NUM_OF_PLAYERS][CARD_NUM_OF_A_PACK/NUM_OF_PLAYERS];
char h[NUM_OF_PLAYERS][CARD_NUM_OF_A_PACK/NUM_OF_PLAYERS];
char d[NUM_OF_PLAYERS][CARD_NUM_OF_A_PACK/NUM_OF_PLAYERS];
char s[NUM_OF_PLAYERS][CARD_NUM_OF_A_PACK/NUM_OF_PLAYERS];
CartCount = CARD_NUM_OF_A_PACK; memset(players,0,sizeof(players));
memset(c,0,sizeof(c));
memset(h,0,sizeof(h));
memset(d,0,sizeof(d));
memset(s,0,sizeof(s));
if (NULL == pCard)
{
return;
}
srand((int)time(0));
while(run)
{
temp = (int)(CartCount*rand()/(RAND_MAX+1.0));
players[playerNo][playerCardNo].color = pCard[temp].color;
players[playerNo][playerCardNo].value = pCard[temp].value;
pCard[temp].color = pCard[CartCount-1].color;
pCard[temp].value = pCard[CartCount-1].value;
pCard[CartCount-1].color = players[playerNo][playerCardNo].color;
pCard[CartCount-1].value = players[playerNo][playerCardNo].value;
CartCount-=1;
if (CartCount < 0)
{
packOfCard++;
if(packOfCard >= 1)
{
run = 0;
}
CartCount = CARD_NUM_OF_A_PACK;
}
playerCardNo+=1;
if (playerCardNo >= NUM_ONEPACK_OF_PLAYER)
{
playerNo+=1;
playerCardNo = 0;
}
}
for(i = 0;i < NUM_OF_PLAYERS;i++)
{
sCount[i] = 0;
hCount[i] = 0;
dCount[i] = 0;
cCount[i] = 0;
for (j = 0;j < NUM_ONEPACK_OF_PLAYER;j++)
{
if ('S' == players[i][j].color)
{
s[i][sCount[i]] = players[i][j].value;
sCount[i]++;
}
else if ('H' == players[i][j].color)
{
h[i][hCount[i]] = players[i][j].value;
hCount[i]++;
}
else if ('D' == players[i][j].color)
{
d[i][dCount[i]] = players[i][j].value;
dCount[i]++;
}
else if ('C' == players[i][j].color)
{
c[i][cCount[i]] = players[i][j].value;
cCount[i]++;
}
}
}
for (i = 0;i < NUM_OF_PLAYERS;i++)
{
for (j = 0;j < cCount[i] ;j++)
{
for(k = 1;k < cCount[i]-j;k++)
{
if(c[i][j] > c[i][k])
{
temp = c[i][j];
c[i][j] = c[i][k];
c[i][k] = temp;
}
}
}
}
for (i = 0;i < NUM_OF_PLAYERS;i++)
{
for (j = 0;j < hCount[i] ;j++)
{
for(k = 1;k < hCount[i] -j;k++)
{
if(h[i][j] > h[i][k])
{
temp = h[i][j];
h[i][j] = h[i][k];
h[i][k] = temp;
}
}
}
}
for (i = 0;i < NUM_OF_PLAYERS;i++)
{
for (j = 0;j < dCount[i] ;j++)
{
for(k = 1;k < dCount[i] -j;k++)
{
if(d[i][j] > d[i][k])
{
temp = d[i][j];
d[i][j] = d[i][k];
d[i][k] = temp;
}
}
}
}
for (i = 0;i < NUM_OF_PLAYERS;i++)
{
for (j = 0;j < sCount[i] ;j++)
{
for(k = 1;k < sCount[i] - j;k++)
{
if(h[i][j] > h[i][k])
{
temp = s[i][j];
s[i][j] = s[i][k];
s[i][k] = temp;
}
}
}
}
for (i = 0;i < NUM_OF_PLAYERS;i++)
{
printf("Player:%d\n",i+1);
printf("S:");
for (j = 0;j < sCount[i];j++)
{
if (s[i][j] <= 10)
printf("%d ",s[i][j]);
else
printf("%c ",s[i][j]);
}
printf("\nH:");
for (j = 0;j < hCount[i];j++)
{
if (h[i][j] <= 10)
printf("%d ",h[i][j]);
else
printf("%c ",h[i][j]);
}
printf("\nD:");
for (j = 0;j < dCount[i];j++)
{
if (d[i][j] <= 10)
printf("%d ",d[i][j]);
else
printf("%c ",d[i][j]);
}
printf("\nC:");
for (j = 0;j < cCount[i];j++)
{
if (c[i][j] <= 10)
printf("%d ",c[i][j]);
else
printf("%c ",c[i][j]);
}
printf("\n");
}
}
int main()
{ Card_t *pCard = NULL;
pCard = (Card_t *)malloc(SIZE);
if (NULL == pCard)
{
printf("error");
return;
}
CardInit(&pCard);
Deal(&pCard);
free(pCard);
}
第三个是
#include
#include
#include
#include
#include
#define NULL 0
#define LEN sizeof(struct student)
struct student
{
long int num;
char name[20];
int age;
char sex[4];
char address[30];
long int tele_num;
char E_mail[20];
struct student *next;
};
int TOTAL_NUM = 0;
struct student *head = NULL;
void record();
void insert(struct student *stu);
void display(struct student *stu);
void displayAll();
void query();
void query_by_num();
void freeAll();
void devise(struct student *p);
//系统主菜单
void main()
{
int choice;
choice = -1;
do
{
printf("\n\n\n");
printf("\t\t\t--------------------------------\n");
printf("\t\t\t| 学生信息管理系统 |\n");
printf("\t\t\t--------------------------------\n");
printf("\t\t\t+ [1]----录入学生信息 +\n");
printf("\t\t\t+ [2]----浏览学生信息 +\n");
printf("\t\t\t+ [3]----查询学生信息 +\n");
printf("\t\t\t+ [0]----退出系统 +\n");
printf("\t\t\t+*·*·*·*·*·*·*·*·*·*·+\n");
printf("\t\t\t--------------------------------\n");
printf("请输入您的选择:");
scanf("%d", &choice);
switch(choice)
{
case 0:
freeAll();
break;
case 1:
record();
break;
case 2:
displayAll();
break;
case 3:
query_by_num();
break;
default:
printf("\n无效选项!");
break;
}
}
while(choice != 0);
}
//录入学生信息
void record()
{
int i=0;
struct student *p0,*head;
char a;
do
{
p0 = (struct student *)malloc(LEN);
printf("请输入学生的学号:");
scanf("%ld",&p0->num);
fflush(stdin);
printf("请输入学生的姓名:");
scanf("%s",p0->name);
fflush(stdin);
printf("请输入学生的年龄:");
scanf("%d",&p0->age);
fflush(stdin);
printf("请输入学生的性别:");
scanf("%s",p0->sex);
fflush(stdin);
printf("请输入学生的籍贯:");
scanf("%s",p0->address);
fflush(stdin);
printf("请输入学生的电话:");
scanf("%f",&p0->tele_num);
fflush(stdin);
printf("请输入学生的E-mail:");
scanf("%s",p0->E_mail);
fflush(stdin);
insert(p0);
printf("\n是否继续输入另外一个学生信息?(y/n)");
a=getchar();
i++;
}
while(a=='y' && i<=50);
TOTAL_NUM=i;
head=p0;
}
void insert(struct student *stu)
{
struct student *p0, *p1, *p2;
p1 = head;
p0 = stu;
if(head == NULL)
{
head = p0;
p0->next = NULL;
}
else
{
while((p0->num > p1->num)&&(p1->next != NULL))
{
p2 = p1;
p1 = p1->next;
}
if(p0->num <= p1->num)
{
if(head == p1)
head = p0;
else
p2->next = p0;
p0->next = p1;
}
else
{
p1->next = p0;
p0->next = NULL;
}
}
TOTAL_NUM++;
}
void display(struct student *p)
{
printf("%ld\t%s\t%d\t%s\t%s\t%ld\t%s\n", p->num, p->name, p->age, p->sex,p->address, p->tele_num, p->E_mail);
}
//浏览学生信息
void displayAll()
{
struct student *p;
printf("学生总数:%d\n", TOTAL_NUM);
if(head != NULL)
{ p=head;//少了这个
do
{
printf("%10d%10s%10d%10s%10s\n",p->num,p->name,p->age,p->sex,p->E_mail);
p=p->next;
} while(p!=NULL);
}
printf("\n");
}
//查询学生信息
void query()
{
int choice;
choice = -1;
do
{
printf("\n");
printf("+--------------------+\n");
printf("| 按学号查询 请按 1 |\n");
printf("| 取消 请按 0 |\n");
printf("+--------------------+\n");
printf("请输入您的选择:");
scanf("%d", &choice);
switch(choice)
{
case 0:
return;
case 1:
query_by_num();
break;
default:
printf("\n无效选项!");
break;
}
}
while(choice != 0);
}
//按学号查询学生信息
void query_by_num()
{
int num;
struct student *p1;
printf("请输入学生的学号:");
scanf("%ld", &num);
if(head==NULL)
{
printf("无学生记录!\n");
return;
}
p1=head;
while(num!=p1->num && p1->next!=NULL)
p1=p1->next;
if(num == p1->num)
{
printf("\n学 号\t姓 名\t年 龄\t性 别\t地址\t 电话\t E-mail\n");
printf("------------------------------------------------------------------------------- ");
display(p1);
}
else
printf("没有该学生记录,请检查!");
}
void freeAll()
{
struct student *p1, *p2;
p1=p2=head;
while(p1)
{
p2=p1->next;
free(p1);
p1=p2;
}
}