求一个C 语言的源代码

软件和网站开发以及相关技术探讨
回复
头像
远古石头
帖子: 16
注册时间: 2008-05-25 15:48

求一个C 语言的源代码

#1

帖子 远古石头 » 2009-06-24 16:02

输入10辆汽车的信息,每辆汽车含有成员名为“编号,发动机号,使用年限,原价,磨损=使用年限*4000,实际车价,使用年龄排名”,分别编写6个函数求:
(1)输入一辆汽车的编号,查询该汽车的信息并输出,若不存在显示没找到。
(2)输入一辆汽车的信息,按编号顺序将汽车的信息插入后输出。
(3)输入一辆已存在的汽车的发动机编号,删除该汽车的信息后输出。
(4)求每辆汽车的磨损(磨损=使用年限*4000),实际车价(实际车价=原价-磨损-税收)。
(5)求所有原价项,磨损项和税收的总额并输出。
(6)找出使用年龄排名第一并输出其信息。
要求:
10辆汽车的数据用文件存储,每辆汽车的结构体用数组或单链表,首先建立一个具有10辆汽车数据的单链表或数组,并程序启动后先显示“菜单”,当输入为1时,执行第(1)个函数;当输入为2时,执行第(2)个函数;当输入为3时,执行第(3)个函数;当输入为4时,执行第(4)个函数;当输入为5时,执行第(5)个函数;当输入为6时,执行第(6)个函数;当输入为7时,退出系统,当输入其他数字时,提示输入有错误。
头像
sxdhaoren
帖子: 852
注册时间: 2008-10-01 0:20
系统: ubuntu kylin16.04.3

Re: 求一个C 语言的源代码

#2

帖子 sxdhaoren » 2009-06-24 16:06

你想偷懒啊,这个题我当年可是自己做出来的
自由软件爱好者
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

Re: 求一个C 语言的源代码

#3

帖子 BigSnake.NET » 2009-06-24 18:56

竟然问作业..
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
头像
远古石头
帖子: 16
注册时间: 2008-05-25 15:48

Re: 求一个C 语言的源代码

#4

帖子 远古石头 » 2009-06-25 14:17

哈哈,是呀是呀
chuzhufei
帖子: 35
注册时间: 2009-04-01 8:50

Re: 求一个C 语言的源代码

#5

帖子 chuzhufei » 2009-06-25 15:36

自己做 别想偷懒!!
:em04
头像
HFUTec
帖子: 48
注册时间: 2009-03-20 8:52

Re: 求一个C 语言的源代码

#6

帖子 HFUTec » 2009-07-01 21:19

呃,既然是作业,那还是自己做吧
头像
jiefey
帖子: 144
注册时间: 2009-07-24 0:14

Re: 求一个C 语言的源代码

#7

帖子 jiefey » 2009-08-14 1:26

:em06 原来作业不能在这里问……
知道了 - -!

代码: 全选

好东西>> http://yisnet.com/go/
头像
mickeywaley
帖子: 1427
注册时间: 2009-03-19 9:19
系统: ubuntu
来自: 江苏
联系:

Re: 求一个C 语言的源代码

#8

帖子 mickeywaley » 2009-08-14 1:38

以前看到有人问过,找出来了,不明白的别问我,问这里的人http://topic.csdn.net/u/20090624/15/28e09190-58a6-4469-b6e1-b0f1eba07a09.html
楼主,你再加工一下吧,那些指定执行哪个函数用switch,还有链表未建立之前,其它函数要设置无法调用.

C/C++ code

代码: 全选

#include
#include
#include
#define LEN sizeof(struct car)
#define NULL 0
struct car
{
	int num; //编号
	unsigned int vin;//发动机号
	unsigned int old;//使用年限
	long double price;//原价
	long double att;//磨损
	long double realprice;//实际车价
	unsigned int car_age;//使用车龄
	struct car *next;
};
struct car *creat(void)
{   //建立汽车数据
	struct car *p1,*p2,*head;
	p1=p2=(struct car *)malloc(LEN);
	head=NULL;
	for(int i=0;i<3;i++)
	{//建立一个有10辆汽车信息的链表
		printf("pleae input the information of the car(%d):\n",i);
		printf("order:\tnum\tvin\told\tprice\tcar_age:\n");
		scanf("%d%ld%ld%Lf%ld",&p1->num,&p1->vin,&p1->old,&p1->price,&p1->car_age);
		p1->att=p1->old*4;//磨损=使用年限(old)*4
		p1->realprice=p1->price-p1->att;//实际车价=原价(price)-磨损(att)
		if(i==0)
			head=p1;		
		p2=p1;
		p1=(struct car*)malloc(LEN);
		p2->next=p1;
	}
	p2->next=NULL;
	return head;
}
void print(struct car *head)
{  //打印函数.
	printf("\tnum\tvin\told\tprice\tatt\trealprice\tcar_age\n");
	for(struct car *p=head;p!=NULL;p=p->next)
		printf("\t%d\t%ld\t%ld\t%.2f\t%.2f\t%.2f\t\t%d\n",p->num,p->vin,p->old,p->price,p->att,p->realprice,p->car_age);
}
void order(struct car *head)
{  //按编号从小至大排序
	int num;
	unsigned int vin,car_age,old;
	long double price,att,realprice;
	struct car *p1,*p2;
	for(p1=head;p1->next!=NULL;p1=p1->next)
		for(p2=p1->next;p2!=NULL;p2=p2->next)
			if(p1->num>p2->num)
			{
				num=p1->num;
				p1->num=p2->num;
				p2->num=num;
				
				vin=p1->vin;
				p1->vin=p2->vin;
				p2->vin=vin;

				old=p1->old;
				p1->old=p2->old;
				p2->old=old;
				
				price=p1->price;
				p1->price=p2->price;
				p2->price=price;

				att=p1->att;
				p1->att=p2->att;
				p2->att=att;

				realprice=p1->realprice;
				p1->realprice=p2->realprice;
				p2->realprice=realprice;

				car_age=p1->car_age;
				p1->car_age=p2->car_age;
				p2->car_age=car_age;
			}
}
struct car *insert(struct car *head)
{   //插入一辆汽车的信息
	struct car *p;
	p=(struct car *)malloc(LEN);
	printf("insert a car information:\n");
	printf("order:\tnum\tvin\told\tprice\tcar_age:\n");
	scanf("%d%ld%ld%Lf%ld",&p->num,&p->vin,&p->old,&p->price,&p->car_age);
	p->att=p->old*4;//磨损=使用年限(old)*4
	p->realprice=p->price-p->att;//实际车价=原价(price)-磨损(att)
	p->next=head;//插入信息结点接到首结点之前
	head=p;
	order(head);//调用排序
	return head;
}
void check(struct car *head)
{ //查找
	printf("please input the num of the car:\n");
	int num,flag=0;
	scanf("%d",&num);
	for(struct car *p=head;p!=NULL;p=p->next)
		if(p->num==num)
		{
			printf("found:\n");
			printf("\tnum\tvin\told\tprice\tatt\trealprice\tcar_age\n");
			printf("\t%d\t%ld\t%ld\t%.2f\t%.2f\t%.2f\t\t%d\n",p->num,p->vin,p->old,p->price,p->att,p->realprice,p->car_age);
			flag=1;
		}
	if(!flag)
		printf("Not found!\n");
}
struct car *delete_vin(struct car *head)
{   //删除指定编号
	struct car *p1,*p2;
	printf("please input the vin of the car(delete):\n");
	unsigned int vin;
	scanf("%ld",&vin);
	for(p2=p1=head;p2!=NULL;p1=p2,p2=p2->next)
		if(p2->vin==vin)
			if(p2==head)
				head=head->next;
			else 
				if(p2->next==NULL)
					p1->next=NULL;
				else
					p1->next=p2->next;
	return head;
}
void car_age_first(struct car *head)
{   //显示使用年龄最高的某部车信息.
	struct car *p=head,*ptemp=head;;
	unsigned int age_max=p->car_age;
	for(p=p->next;p!=NULL;p=p->next)
		if(p->car_age>age_max)
		{
			age_max=p->car_age;
			ptemp=p;
		}
	printf("the age of the car is:\n");
	printf("\tnum\tvin\told\tprice\tatt\trealprice\tcar_age\n");
	printf("\t%d\t%ld\t%ld\t%.2f\t%.2f\t%.2f\t\t%d\n",ptemp->num,ptemp->vin,ptemp->old,ptemp->price,ptemp->att,ptemp->realprice,ptemp->car_age);
}
main()
{
	struct car *head;
	head=creat();
	print(head);
	order(head);//调用排序函数
	print(head);
	car_age_first(head);//使用年龄max
//	head=insert(head);//插入一个结点
//	print(head);
//	check(head);查找某编号
//	head=delete_vin(head); //删除特定编号
//	print(head);
}

回复