| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1490 人关注过本帖
标题:设计一个C语言汽车销售系统程序
取消只看楼主 加入收藏
爱的鑫空
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-8-6
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:1 
设计一个C语言汽车销售系统程序
设计一个C语言汽车销售系统程序
每辆车需要包含一下信息

车名
车型
颜色
单位进价
单位售价
库存车辆总数
卖车数量
利润

设计要求:
以上信息需要储存到文件(file)里,这个文件提供“永久”存储为employee数据库。(这句我也不知道是不是这样翻译的)


当程序运行时将首先从file里加载数据
提示:当该程序运行时 文件不会显示 数据也不会加载
(这里没搞明白老师的意图 晕了)

程序会显示以下菜单选项
1-Display the list of all car record (显示所有输入车)
2-Add a new record (添加一个新的输入)
3-Modify an existing record (修改当前显示记录)
4-Sales and Profits (显示车型 库存量 每类车销售数量 每类车销售总价  每类车利润 各类车的利润总和)
5-Sort the list of car in alphabetic order, based on company name(按字母顺序排列车名)
6-Quit - Data is to be saved to a file which will then be used by the program on subsequent runs.
(数据储存到之前的那个file里)
大致翻译成这样了


程序我大致上我已经弄出来 但是有错误 运行不了 能不能帮我看看怎么修改啊
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>


void input();
void sort();
void display();
void insert();
void modify();


int count=0;
struct car
{
                    char name[20];//车名
                    char model[20];//车型
                    char color[20];//颜色
                    int cost;//单位进价
                    int price;//单位售价
                    int total;//库存车辆总数
                    int profit;//利润
                    int num;//卖车数量
                    int stock;//卖车之后的库存数量
                    
};
struct car info[50];


void addrecord()
{

int i=0;
char c_pd; //pd为判断是否还要继续输入
FILE *fp; //打开文件
if((fp=fopen("c:\\database\\database.txt","a"))==0)
{
printf("Cannot open file!"); exit(0);
} //以二进制读写的形式创建一个保存文件

do
{
printf("please enter a record:\n");
printf("the car is 'name,number,Unit Cost,Selling Price ,color':\n");
scanf("%s,%d,%d,%d,%s,",info[i].name,info[i].num,info[i].cost,info[i].price,info[i].color);//输入汽车信息
count++;
fwrite(&info[i],sizeof(info),50,fp); //存入文件中

printf("continue enter ? yes enter 'y';  no enter 'n'\n");//是否继续输入号码记录
fflush(stdin);//清空缓存
scanf("%c",&c_pd);
if(c_pd=='y')i++;
}while(c_pd=='y');

fclose(fp);
}



void main()/*主函数*/
{
int select;/*功能选择模块*/
do
{

printf("\n\t\t\t\t1.Display the list of all car record \n");
printf("\t\t\t\t2.Add a new record \n");
printf("\t\t\t\t3.Modify an existing record \n");
printf("\t\t\t\t4.Sales and Profits\n");
printf("\t\t\t\t5.Sort the list of car in alphabetic order\n");
printf("\t\t\t\t6.Quit\n");
printf("\t\t\t\t7.查询学生信息\n");
printf("\t\t\t\t8.退出\n");
printf("\t\t\t\tEnter your choice:");
scanf("%d",&select);
switch(select)
{
case 1:system("cls");//显示所有输入车
 display();break;
case 2:system("cls");//添加一个新的输入
insert();break;
case 3:system("cls");//修改当前显示记录
 modify();break;
case 4:system("cls");//显示车型 库存量 每类车销售数量 每类车销售总价  每类车利润 各类车的利润总和
insert();break;
case 5:system("cls");//按字母顺序排列车名
 sort();break;
case 6:system("cls");//数据储存到之前的那个file里
modify();break;

case 7:system("exit");//
exit(0);
default:system("cls");
}
}while(2);/*至此功能选择结束*/
display() /*显示数据函数*/
{
int i;
char ch;
//printf("%d",count);
do
{
printf("\t\t\tCar information\n");
printf("\tname\tnumber\tUnit Cost\tselling price\tcolor\n");
for(i=0;i<count;i++)
{

printf("%s\t%d\t%d\t%d\t%s,",info[i].name,info[i].num,info[i].cost,info[i].price,info[i].color);
}
printf("\t\t按任意键返回主菜单.");
ch=getch();
}
while(!ch);
}

 insert()/*插入数据函数*/
{
    int i=0;
char ch='y';
do
{
printf("\n\t\enter new car information\n");
scanf("%s,%d,%d,%d,%s,",info[i].name,info[i].num,info[i].cost,info[i].price,info[i].color);
printf("\n");
count=count+1;
sort();
printf("\n是否继续输入?(Y/N)");
ch=getch();
system("cls");
}while(ch!='n'&&ch!='N');

}


 modify()/*修改数据函数*/
{
int i;
 char name;
    printf("Enter car name:");
    scanf("%d",&name);
    for(i=0;i<count;i++)
if(name==info[i].name)
{

printf("\n\t\tmodify information\n");
printf("\n\t\enter new car information\n");
scanf("%s,%d,%d,%d,%s,",info[i].name,info[i].num,info[i].cost,info[i].price,info[i].color);
printf("\n");
sort();
break;
}
system("cls");
}

 Profits()
{
   
int i;
char ch;
//printf("%d",count);
do
{
printf("\t\t\tCar information\n");
printf("\tname\tnumber\tUnit Cost\tselling price\tcolor\n");
for(i=0;i<count;i++)
{
    int Total=0;
    Total=info[i].num*(info[i].price-info[i].cost)+Total;
    info[i].profit=info[i].num*(info[i].price-info[i].cost);
    info[i].stock=info[i].total-info[i].num;
printf("name%s\tselling number%d\tunit cost%d\tnumber of stock\tselling price%d\tcolor%s\t%d,",info[i].name,info[i].num,info[i].cost,info[i].stock,info[i].price,info[i].color,info[i].profit);
   
   
}
printf("Total profit%d:",Total);
printf("\t\t按任意键返回主菜单.");
ch=getch();
}
while(!ch);
}
void sort()/*排序数据函数*/
{
struct car info;
char temp[20];
int i,j;
for(i=1;i<count;i++)
{
for(j=1;j<=count-i;j++)
{
if((strcmp(info[i].name, info[j].names) )
{
         strcpy(temp, info[i].name);
         strcpy(info[i].name, info[j].name);
         strcpy(info[i].name, temp);

}
   printf("\n The sorted list in alphabetical order is: \n");
     for(i = 0; i< 6; i++)
       printf(" %s\n", info[i].name);

}
}
display();
}

[ 本帖最后由 爱的鑫空 于 2012-8-6 23:24 编辑 ]
搜索更多相关主题的帖子: employee existing record 
2012-08-06 00:29
爱的鑫空
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-8-6
收藏
得分:0 
回复 2楼 信箱有效
我今天才注册的 就这么点分 怎么增啊
2012-08-06 01:03
快速回复:设计一个C语言汽车销售系统程序
数据加载中...
 
   



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

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