天天看点

c语言程序中cost的作用,帮忙解释下面程序里res什么意思

已结贴√

问题点数:20 回复次数:2

c语言程序中cost的作用,帮忙解释下面程序里res什么意思
c语言程序中cost的作用,帮忙解释下面程序里res什么意思
c语言程序中cost的作用,帮忙解释下面程序里res什么意思
c语言程序中cost的作用,帮忙解释下面程序里res什么意思

帮忙解释下面程序里res什么意思

#include

#include

#include

typedef struct resisdent

{

long num;                       // 编号

char adress[50];                // 用户地址

char name[50];                  // 户名

long last_num;                  // 上次读数

long now_num;                   // 抄表读数

long cost_remain;               // 电费余额

struct resisdent *next;         // 下一个用户

} res;

void main()

{

// 函数声明

res *enter(); //就是这里    res *delete(res *);

res *alter(res *);

void display(res *);

void search(res *);

res *jiaofei(res *);

res *chaobiao(res *);

int menu_select();

// 变量初始化

// head 变量保存链表头指针

res *head=NULL;

res *p1,*p2,*p3;

int i,j,k;

for(;;)

{

switch(menu_select())

{

case 1: head=enter();break;

case 2: head=delete(head);break;

case 3: head=alter(head);break;

case 4: display(head);break;

case 5: search(head);break;

case 6: head=jiaofei(head);break;

case 7: head=chaobiao(head);break;

case 8: exit(0);

}

}

}

// 菜单选项

int menu_select()

{

int ch;

printf("***************Welcome to the eletronic system**********************************\n");

printf("\t1.Enter the static of the resisdent.\n");

printf("\t2.Delete the static of the resisdent.\n");

printf("\t3.Alter the static of the resisdent.\n");

printf("\t4.Display the static of the resisdent.\n");

printf("\t5.Search the static of the resisdent.\n");

printf("\t6.Hand up the cost.\n");

printf("\t7.Updata the reader.\n");

printf("\t8.Quit.\n");

printf("********************************************************************************\n");

do

{

printf("Make a chioce(1--8):");

scanf("%d",&ch);

} while(ch<1 || ch>8);

return(ch);

}

// 录入数据,当编号为 0 则退出

res *enter()

{

res *head = NULL;

res *p1 = NULL;

res *p2 = NULL;

res *p3 = NULL;

int n=0;

p1=p2=(res *) malloc (sizeof(res)); //还有这里  printf("Enter the static of the resisdent:\n");

printf("num:");

scanf("%ld",&p1->num);

if(p1->num==0)

goto end;

printf("adress:");

scanf("%s",p1->adress);

printf("name:");

scanf("%s",p1->name);

printf("The number of last time:");

scanf("%ld",&p1->last_num);

printf("The number of now:");

scanf("%ld",&p1->now_num);

printf("The cost remain:");

scanf("%ld",&p1->cost_remain);

while(p1->num!=0)

{

n=n+1;

// 如果计数为1,则置表头为p1,

// 否则将新建节点添加至上一节点(此时为p2)尾部

if(n==1)

head=p1;

else

p2->next=p1;

p2=p1;

p1=(res *) malloc (sizeof(res));

printf("num:");

scanf("%ld",&p1->num);

if(p1->num==0)

goto end;

printf("adress:");

scanf("%s",p1->adress);

printf("name:");

scanf("%s",p1->name);

printf("The number of last time:");

scanf("%ld",&p1->last_num);

printf("The number of now:");

scanf("%ld",&p1->now_num);

printf("The cost remain:");

scanf("%ld",&p1->cost_remain);

}

end:

p2->next=NULL;

return(head);

}

// 根据输入的编号删除对应项

// 返回更新后的链表表头指针

res *delete(res *head)

{

res *p1,*p2;

long num;

if(head==NULL)

printf("The list is empty.!\n");

else

{

printf("Enter the num to delete:");

scanf("%ld",&num);

p1=p2=head;

while(p1->num!=num && p1->next!=NULL)

{

p2=p1;

p1=p1->next;

}

if(num==p1->num)

{

if(head==p1)

head=p1->next;

else

p2->next=p1->next;

}

else

printf("Not found!\n");

}

return(head);

}

// 输入编号,修改对应项

// 返回表头指针

res *alter(res *head)

{

res *p1,*p2;

long num;

if(head==NULL)

printf("Null list.\n");

else

{

printf("Enter the num to alter:");

scanf("%ld",&num);

p1=head;

while(p1->num!=num &&p1->next!=NULL)

p1=p1->next;

if(num==p1->num)

{

printf("new num:");

scanf("%ld",&p1->num);

printf("new adress:");

scanf("%s",p1->adress);

printf("new name:");

scanf("%s",p1->name);

printf("The number of last time:");

scanf("%ld",&p1->last_num);

printf("The number of now:");

scanf("%ld",&p1->now_num);

printf("The cost remain:");

scanf("%ld",&p1->cost_remain);

}

else

printf("Not found!\n");

}

return(head);

}

// 显示表中所有项目

void display(res *head)

{

res *p1,*p2;

p1=p2=head;

printf("********************************************************************************\n");

printf("\tNUM\tADRESS\tNAME\tNUMBER_LAST\tNUMBER_NOW\tCOST_REMAIN\n");

while(p1!=NULL)

{

printf("\t%-3ld\t%-6s\t%-4s\t%-11ld\t%-10ld\t%-5ld\n",p1->num,p1->adress,

p1->name,p1->last_num,p1->now_num,p1->cost_remain);

p1=p1->next;

}

printf("********************************************************************************\n");

}

// 查询

void search(res *head)

{

res *p1,*p2;

char ser[50];

int n;

printf("1.search by adress.\n");

printf("2.search by name.\n");

printf("choose 1 || 2:\n");

scanf("%d",&n);

if(head==NULL)

printf("NULL list.\n");

switch(n)

{

case 1:

printf("input the adress:");

scanf("%s",ser);

p1=p2=head;

while(strcmp(p1->adress,ser)!=0 &&p1->next!=NULL)

p1=p1->next;

if(strcmp(p1->adress,ser)==0)

{

printf("\tNUM\tADRESS\tNAME\tLAST_NUM\tNOW_NUM\tCOST_REMAIN\n");

printf("\t%-3ld\t%-6s\t%-4s\t%-11ld\t%-10ld\t%-5ld\n",p1->num,p1->adress,p1->name,

p1->last_num,p1->now_num,p1->cost_remain);

}

else

printf("Not found!\n");break;

case 2:

{

printf("input the name:");

scanf("%s",ser);

p1=p2=head;

while(strcmp(p1->name,ser)!=0 && p1->next!=NULL)

p1=p1->next;

if(strcmp(p1->name,ser)==0)

{

printf("\tNUM\tADRESS\tNAME\tLAST_NUM\tNOW_NUM\tCOST_REMAIN\n");

printf("\t%-3ld\t%-6s\t%-4s\t%-11ld\t%-10ld\t%-5ld\n",p1->num,p1->adress,p1->name,

p1->last_num,p1->now_num,p1->cost_remain);

}

else

printf("Not found!\n");break;

}

default:break;

}

}

res *jiaofei(res *head)

{

res *p1,*p2;

char adress[50];

long cost;

printf("input the adress:");

scanf("%s",adress);

if(head==NULL)

printf("NULL list!\n");

else

{

p1=head;

while(strcmp(p1->adress,adress)!=0 && p1->next!=NULL)

p1=p1->next;

if(strcmp(p1->adress,adress)==0)

{

printf("input the number of the cost:");

scanf("%ld",&cost);

p1->cost_remain+=cost;

}

else

printf("Not found!\n");

}

return(head);

}

res *chaobiao(res *head)

{

res *p1,*p2;

char adress[50];

if(head==NULL)

printf("NULL list!\n");

else

{

printf("input the adress:");

scanf("%s",adress);

p1=head;

while(strcmp(p1->adress,adress)!=0 && p1->next!=NULL)

p1=p1->next;

if(strcmp(p1->adress,adress)==0)

{

p1->last_num=p1->now_num;

printf("input the num:");

scanf("%ld",&p1->now_num);

}

else

printf("Not found!\n");

}

return(head);

}

搜索更多相关主题的帖子:

解释 res