# include "stdlib.h"
# include "string.h"
# define NULL 0
struct xiangcun
{
char num[4]//乡村的编号
char name[20] //村名
int people //总人数
int relieve//救济人数
float amount //救济总金额
struct xiangcun *next
}
struct jiating
{
char num[10] //乡村编号
char candidate[20] //身份z号码
char fname[20]//户主名字
char sex[2] //性别
int fpeople //家庭人数
float insert //年收入
int time //接受救助次数
struct jiating * next
}
struct out
{
char candidate[20]//户主身份z号码
char goodsname[20] //商品名字
char date[15]//发放日期
char unit[10] //单位
float price //单价
int count//发放数量
float money //金额
struct out *next
}
struct xiangcun *h1,*tail1
struct jiating *h2,*tail2
struct out *h3,*tail3
struct xiangcun * rebuilt1() //构建乡村链表
{
int n1=0
struct xiangcun *p1,*p2,*head
p1=p2=(struct xiangcun *)malloc(sizeof(struct xiangcun))
printf("\n\n\n\n\n\n 请输入以下信息:\n 乡村的编号:\n 村名:\n 总人数:\n 救济人数:\n 就系总金额:\n")
scanf("%s%s%d%d%f",p1->num,p1->name,&p1->people,&p1->relieve,&p1->amount)
while(strcmp(p1->num,"0")!=0)
{
n1++
if(n1==1)
h1=p1
else
p2->next=p1
p2=p1
p1=(struct xiangcun *)malloc(sizeof(struct xiangcun))
scanf("%s%s%d%d%f",p1->num,p1->name,&p1->people,&p1->relieve,&p1->amount)
}
p2->next=NULL
return h1
}
struct jiating * rebuilt2() //构建家庭信息链表
{
int n2=0
struct jiating *p1,*p2,*head
p1=p2=(struct jiating *)malloc(sizeof(struct jiating))
printf("\n\n\n\n\n\n 请输入以下信息:\n乡村名字: \n户主身份z号码: \n 户主名字:\n 户主性别:\n 家庭人数:\n 年收入:\n 接受救助的次数:\n")
scanf("%s%s%s%s%d%f%d",p1->num,p1->candidate,p1->fname,p1->sex,&p1->fpeople,&p1->insert,&p1->time)
while(strcmp(p1->candidate,"0")!=0)
{
n2++
if(n2==1)
h2=p1
else
p2->next=p1
p2=p1
p1=(struct jiating *)malloc(sizeof(struct jiating))
scanf("%s%s%s%s%d%f%d",p1->num,p1->candidate,p1->fname,p1->sex,&p1->fpeople,&p1->insert,&p1->time)
}
p2->next=NULL
return h2
}
struct out * rebuilt3() //构建物资信息链表
{
struct out *p1, *p2,*head
int n3=0
p1=p2=(struct out *)malloc(sizeof(struct out))
printf("\n\n\n\n\n\n 请输入以下信息:\n 户主身份z号码:\n 商品名字:\n 发放日期:\n 单位:\n 单价:\n 发放数量:\n 金额:\n")
scanf("%s%s%s%s%f%d%f",p1->candidate,p1->goodsname,p1->date,p1->unit,&p1->price,&p1->count,&p1->money)
while(strcmp(p1->candidate,"0")!=0)
{
n3++
if(n3==1)
h3=p1
else
p2->next=p1
p2=p1
p1=(struct out *)malloc(sizeof(struct out))
scanf("%s%s%s%s%f%d%f",p1->candidate,p1->goodsname,p1->date,p1->unit,&p1->price,&p1->count,&p1->money)
}
p2->next=NULL
return h3
}
int change1(xiangcun *head1,char *num) //对乡村信息的修改
{
struct xiangcun *p
p=head1->next
printf("\n\n\n\n\n\n")
while(1)
{
if(p==NULL)
{
return 1
}
if(strstr(p->num,num))
{
printf(" 请重新输入要修改乡村的各项:")
scanf("%s%s%d%d%d",p->num,p->name,&p->people,&p->relieve,&p->amount)
return 1
}
p=p->next
}
}
int change2(jiating *head2,char *num) //对家庭信息的修改
{
struct jiating *p
p=head2->next
printf("\n\n\n\n\n\n")
while(1)
{
if(p==NULL)
{
return 1
}
if(strstr(p->fname,num))
{
printf(" 请重新输入要修改家庭的各项:")
scanf("%s%s%s%s%d%f%d",p->num,p->candidate,p->fname,p->sex,&p->fpeople,&p->insert,&p->time)
return 1
}
p=p->next
}
}
int change3(out *head3,char *name) //对物资信息的修改
{
struct out *p
p=head3->next
printf("\n\n\n\n\n\n")
while(1)
{
if(p==NULL)
{
return 1
}
if(strstr(p->goodsname,name))
{
printf(" 请重新输入要修改物资的各项:")
scanf("%s%s%s%s%f%d%f",p->candidate,p->goodsname,p->date,p->unit,&p->price,&p->count,&p->money)
return 1
}
p=p->next
}
}
void Csearch(xiangcun* head1) /* 查询全部乡村中每个村的救济总户数*/
{
struct xiangcun *p
p=head1->next
printf("\n\n\n\n\n\n")
if(p==NULL)
{
printf(" 全乡没有被救济的人!\n")
return
}
while(p!=NULL)
{
printf(" %s救济人数为:%d\n",p->name,p->relieve)
p=p->next
}
return
}
int Esearch(xiangcun * head1,char *name) /*查询全部乡村中某个村的村救济总金额*/
{
struct xiangcun *p
p=head1->next
while(1)
{
if(p==NULL)
{
return 0
}
if(strstr(p->name,name))
{
printf("\n\n\n\n\n\n %s的受救济总金额是:%g\n",p->name,p->amount)
return 1
}
p=p->next
}
}
int Fsearch(jiating* head2,char * name) /*查询某救济户 (如:张三)基本信息*/
{
struct jiating *p
p=head2->next
while(1)
{
if(p==NULL)
{
return 0
}
if(strstr(p->fname,name))
{
printf("\n\n\n\n\n\n 户主的乡村编号:%s\n 户主的身份z号码:%s\n",p->num,p->candidate)
printf(" 户主名字是:%s\n 户主性别是:%s\n",p->fname,p->sex)
printf(" 家庭人数:%d\n 年收入:%g\n /接受救助次数:d\n",p->fpeople,p->insert,p->time)
return 1
}
p=p->next
}
}int frelieve(jiating *head2,out *head3,char * name)/*查询某救济户 (如:张三)救济户物资发放的全部信息*/
{
struct jiating * p
p=head2->next
while(1)
{
if(p==NULL)
{
return 0
}
if(strstr(p->fname,name))
{
struct out *p1
p1=head3->next
printf("\n\n\n\n\n\n %s的物资信息:\n",p->fname)
while(1)
{
if(p1==NULL)
{
return 1
}
if(strstr(p->candidate,p1->candidate))
{
printf("物资名字:%s\n发放日期:%s\n物资的量的单位:%s\n",p1->goodsname,p1->date,p1->unit)
printf("物资单价:%g\n 发放数量:%d\n发放金额:%g\n",p1->price,p1->count,p1->money)
}
p1=p1->next
}
}
p=p->next
}
}
int Relieve(jiating * head2,out *head3,char * name,char *name2)/*查询某救济户 (如:张三)是否发放了某种救济物资 (如:矿泉水)的信息*/
{
struct jiating * p
p=head2->next
while(1)
{
if(p==NULL)
{
return 0
}
if(strstr(p->fname,name))
{
out *p1
p1=head3->next
while (1)
{
if(strstr(p->candidate,p1->candidate)&&strstr(p1->goodsname,name2))
{
return 1
}
p1=p1->next
if(p1==NULL)
{
return 0
}
}
}
p=p->next
}
}
void tprint(xiangcun * head1)/*统计并输出全乡的人口总数、救济总户数、救济总金额*/
{
int peo_sum=0,re_sum=0
float re_cost=0
xiangcun *p=h1
while(p!=NULL)
{
peo_sum+=p->people
re_sum+=p->relieve
re_cost+=p->amount
p=p->next
}
printf("\n\n\n\n\n\n 人口总数:%d\n 救济总户数:%d\n救济总金额:%g\n",peo_sum,re_sum,re_cost)
}
输出是LBLMNP,所以D正确,选D。
执行完strcat(a,b)后,a的内容是ABLMNP,b的内容仍为LMNP。
while(a[i++]!= '\0') b[i]=a[i]是把a的内容向b拷贝,但是到执行b[i]=a[i]时whiler ()中的a[i++]!= '\0'中i++已经生效了,所以从a[1]开始拷贝到b[1],所以只把a中的BLMNP依次向b[1]开始的元素拷贝。那么,b[1]及以后的内容就是BLMNP了,但b[0]的内容仍然是原来的L。所以b的最后内容就是LBLMNP。
puts输出b内容LBLMNP后还要自动加一个回车。
# include "iostream"# include "String.h"
using namespace std
struct List
{
char name[20]
int NO
}
template <class List>
struct Node
{
List data
Node<List>*next
}
template <class List>
class Student
{
Node<List>*head
public:
Student(int m)
void Setdata(int n)
void PrintStudent()
int Get(char b[])
void Delete(int i)
void Insert(int i,List item)
void Change(char a[],int num)
~Student()
}
template <class List>
Student<List>::Student(int m)
{
Node<List>*r,*s
head = new Node<List>
r = head
for (int i = 0i <mi++)
{
s = new Node<List>
r->next = s
r = s
}
r->next = NULL
}
template <class List>
void Student<List>::Setdata(int n)
{
Node<List>*p
p = head->next
for(int i = 0i <ni++)
{
cout<<"请输入姓名:"
cin>>p->data.name
cout<<"请输入身份z号码:"
cin>>p->data.NO
p = p->next
}
}
template <class List>
void Student<List>::PrintStudent()
{
Node<List>*p
p = head->next
while (p)
{
cout<<p->data.name<<","<<p->data.NO<<endl
p = p->next
}
}
template <class List>
int Student<List>::Get(char b[])
{
Node<List>*p
p = head->next
while(p &&strcmp(p->data.name,b) != 0)
{
p = p->next
}
return p->data.NO
}
template <class List>
void Student<List>::Delete(int i)
{
Node<List>*p,*q
p = head
int j = 0
while(p &&j <i-1)
{
p = p->next
j++
}
if(!p || !p->next) {cerr<<"删除位置非法"exit(1)}
else
{
List x
q = p->next
x = q->data
p->next = q->next
delete q
cout<<x.name<<","<<x.NO<<endl
}
}
template <class List>
void Student<List>::Insert(int i,List item)
{
Node<List>*p,*s
p = head
int j = 0
while (p &&j <i-1)
{
p = p->next
j++
}
if(!p) {cerr<<"插入位置非法"exit(1)}
else
{
s = new Node<List>
strcpy(s->data.name,item.name)
s->data.NO = item.NO
s->next = p->next
p->next = s
}
}
template <class List>
void Student<List>::Change(char a[],int num)
{
Node<List>*p
p = head->next
while (p &&strcmp(p->data.name,a) != 0)
{
p = p->next
}
p->data.NO = num
}
template <class List>
Student<List>::~Student()
{
Node<List>*p,*q
p = head
while (p)
{
q = p
p = p->next
delete q
}
head = NULL
}
void main()
{
cout<<"请建立学籍系统"<<endl
int m
cout<<"请输入总人数:"
cin>>m
Student<List>stu(m)
int n = m
stu.Setdata(n)
stu.PrintStudent()
int choice
do
{
cout<<"********"<<endl
cout<<"1.查询"<<endl
cout<<"2.删除"<<endl
cout<<"3.插入"<<endl
cout<<"4.修改"<<endl
cout<<"0.退出"<<endl
cout<<"********"<<endl
cout<<"请输入您的选择:"
cin>>choice
switch(choice)
{
case 1:
{
char b[20]
cout<<"请输入需查询的姓名:"
cin>>b
cout<<"查询人的学号为:"
cout<<stu.Get(b)<<endl
}break
case 2:
{
int i
cout<<"请输入需删除数据的位置:"
cin>>i
cout<<"删除的数据为:"
stu.Delete(i)
}break
case 3:
{
List item
cout<<"请输入需插入学生的姓名:"
cin>>item.name
cout<<"请输入需插入学生的学号:"
cin>>item.NO
int i
cout<<"请输入需插入的位置:"
cin>>i
stu.Insert(i,item)
stu.PrintStudent()
}break
case 4:
{
char a[20]
cout<<"请输入需修改人的姓名:"
cin>>a
int num
cout<<"请输入修改的新学号:"
cin>>num
stu.Change(a,num)
stu.PrintStudent()
}break
case 0:
{
exit(1)
}break
default:
{
cout<<"选择项非法,请重新选择"
cout<<endl
cout<<endl
}
}
} while(choice)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)