| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 512 人关注过本帖
标题:怎么样把三个程序以组合成一个程序啊(以命令菜单方式供用户选择实现每个程 ...
只看楼主 加入收藏
我爱下载102
Rank: 2
等 级:论坛游民
帖 子:15
专家分:10
注 册:2013-1-5
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:5 
怎么样把三个程序以组合成一个程序啊(以命令菜单方式供用户选择实现每个程序的功能)
三个程序都能运行成功的   就是不知道怎么


第一个程序  是数字菱形排列
#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;
 }
}
搜索更多相关主题的帖子: include 用户 
2013-01-07 12:49
我爱下载102
Rank: 2
等 级:论坛游民
帖 子:15
专家分:10
注 册:2013-1-5
收藏
得分:0 
不好意思    第三个程序是如下这个   上面的那个头文件没打出来  
#include <stdio.h>
#include<stdlib.h>
#include<conio.h>
#include <string.h>
#include <io.h>
#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;
 }
}
2013-01-07 12:50
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:10 
你的代码是自己写的吗
能正确运行吗  


DO IT YOURSELF !
2013-01-07 15:27
我爱下载102
Rank: 2
等 级:论坛游民
帖 子:15
专家分:10
注 册:2013-1-5
收藏
得分:0 
回复 3楼 wp231957
前两个是自己写的   后一个贴到这论坛里问别人的

就是不知道这三个程序怎么连起来
2013-01-07 16:59
李军威
Rank: 2
等 级:论坛游民
帖 子:4
专家分:22
注 册:2013-1-7
收藏
得分:10 
使用SWITCH CASE,根据不同条件调用下
2013-01-07 17:11
我爱下载102
Rank: 2
等 级:论坛游民
帖 子:15
专家分:10
注 册:2013-1-5
收藏
得分:0 
回复 5楼 李军威
我来试试
2013-01-07 19:26
快速回复:怎么样把三个程序以组合成一个程序啊(以命令菜单方式供用户选择实现每 ...
数据加载中...
 
   



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

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