zoukankan      html  css  js  c++  java
  • C语言结课课程设计

    大一上学期C语言课结课课程设计:停车场管理系统

    分了学习小组, 我们小组有我、YL(YKL)、MCL
    三人分工完成
    不过我比较闲所以就把整个项目自己悄咪咪写完了
    题目:

    初始:
    一小时之内免费
    一小时后按每小时五元计费
    系统功能
    1.车辆入场登记
    读文件中原有内容:车牌号,入场时间
    屏幕输入车牌号,同时写入文件
    入场时间为当前时间
    2.显示目前场内车辆信息(车牌号、入场时间)和剩余车位数、已经用的车位数
    屏幕输出
    3.管理收费价目表
    默认一小时(分钟)内免费
    多于一小时(分钟)按每小时x元计费
    x由屏幕输入
    4.输入某几辆车出场时间
    更新文件内车辆信息(把出场的车删掉)
    分别输出结算金额到屏幕
    5.统计当天车辆数及收费总金额
    输出到屏幕
    6.根据车辆停车总时间从小到大排序
    停车总时间为停车时间到当前时间
    输出排序结果到文件
    7.退出系统
    

    数据(自己写的)

    Doinb	2020	12	14	18	50	
    Clear	2020	12	14	18	53	
    ClearLove	2020	12	14	19	21	
    9E33F	2020	12	14	9	45	
    X999	2020	12	14	18	32	
    8NNXN	2020	12	14	18	40	
    9N622	2020	12	14	18	47	
    9N777	2020	12	14	18	49	
    MLXG	2020	12	14	19	24	
    

    ParkDefinations.h

    #define N 200//车位
    #define M 10
    typedef struct Node{
        int time[5];
        //出入场时间
        long parktime;
        char num[M];//车牌号
    }Car;
    //从上到下依次为功能1~6
    void CarsInput(Car car[], int *n);//车辆信息,车辆总数
    void CarsInformation(Car car[], int n);//车辆信息
    void Price(int *price);//收费价目
    void Charge(Car car[], int *n, int price, int *sum);//车辆信息,车辆总数,停车花费,
    void Print(Car car[], int n, int sum);//车辆信息
    void Sort(Car car[], int n);//排序
    

    main.c

    #include <time.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <memory.h>
    #include <windows.h>
    #include "ParkDefinations.h"
    
    int main(void)
    {
    	time_t t = time(NULL);
        struct tm *local;
        local = localtime(&t);
    
        int op, price=5, n=0, sum=0, lastday = 0;
        Car car[205];
        do
        {
            system("cls");
            fprintf(stdout, "1.Vehicle entry registration
    ");
            fprintf(stdout, "2.List vehicle information
    ");
            fprintf(stdout, "3.Change the price
    ");
            fprintf(stdout, "4.Vehicle leave registration
    ");
            fprintf(stdout, "5.Count the vehicles admitted today and the total amount charged
    ");
            fprintf(stdout, "6.Rank the total parking time from smallest to largest
    ");
            fprintf(stdout, "7.Exit
    ");
            fprintf(stdout, "Please enter the choice:");
    
            fscanf(stdin, "%d", &op);
            switch(op)
            {
                case 1:
                    CarsInput(car, &n);
                    break;
                case 2:
                    if(n == 0)
                    {
                        fprintf(stdin, "There are no cars in the Park");
                        break;
                    }
                    CarsInformation(car, n);
                    break;
                case 3:
                    if(n == 0)
                    {
                        fprintf(stdin, "There are no cars in the Park");
                        break;
                    }
                    Price(&price);
                    break;
                case 4:
                    if(n == 0)
                    {
                        fprintf(stdin, "There are no cars in the Park");
                        break;
                    }
                    local = localtime(&t);
                    if(!lastday && lastday != local->tm_mday)
                    {
                        lastday = local->tm_mday;
                        sum = 0;
                    }
                    Charge(car, &n, price, &sum);
                    break;
                case 5:
                    if(n == 0)
                    {
                        fprintf(stdin, "There are no cars in the Park");
                        break;
                    }
                    local = localtime(&t);
                    if(!lastday && lastday != local->tm_mday)
                    {
                        lastday = local->tm_mday;
                        sum = 0;
                    }
                    Print(car, n, sum);
                    break;
                case 6:
                    if(n == 0)
                    {
                        fprintf(stdin, "There are no cars in the Park");
                        break;
                    }
                    Sort(car, n);
                    break;
                case 7:
                    break;
                default:puts("Error Inputs");
            }
            system("pause");
        }while(op != 7);
        return 0;
    }
    

    YKL.h

    #define N 200//车位
    #define M 10
    typedef struct Node{
        int time[5];
        //出入场时间
        long parktime;
        char num[M];//车牌号
        struct Node *next;
    }Car;
    void CarsInput(Car car[], int *n);//车辆信息,车辆总数
    void CarsInformation(Car car[], int n);//车辆信息
    

    YKL.c

    #include <memory.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <time.h>
    #include "YKL.h"
    
    
    int day_diff(int year, int month, int day)
    {
        int i, ans = 0;
        int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        for(i=1970; i<year; ++i)
        {
            ans += 365;
            if(i%400 == 0 || (i%4 == 0 && i%100 != 0))
                ++ans;
        }
        if(year%400 == 0 || (year%4 == 0 && year%100 != 0))
            ++days[2];
        for(i=1; i<month; ++i)
            ans += days[i];
        ans += day-1;
        return ans;
    }
    void CarsInput(Car car[], int *n)
    {
    //初始化
        FILE *fp;
        if((fp = fopen("E:\程序\c\作业\停车场管理系统\data.txt", "r"))==NULL)
            if((fp = fopen("E:\程序\c\作业\停车场管理系统\data.txt", "w"))==NULL)
            {
                puts("Failure to open data.txt");
                exit(0);
            }
    	time_t t=time(NULL);
    	struct tm *local = localtime(&t);
    	memset(car, 0, *n);
    	*n = 0;
    	int i, j, diffday;
    //文件输入
    	while(fscanf(fp, "%s", car[*n].num) != EOF)
        {
            for(i=0; i<5; ++i)
                fscanf(fp, "%d", &car[*n].time[i]);
            diffday = day_diff(car[*n].time[0], car[*n].time[1], car[*n].time[2]);
            car[*n].parktime = (diffday * 24 + car[*n].time[3] - 8) * 3600 + car[*n].time[4] * 60;
            //local是中国时间,time()是国际时间,差八个小时
            ++*n;
        }
        fprintf(stdout, "Data has been entered
    ");
    	fclose(fp);
    //屏幕输入
    	if((fp = fopen("E:\程序\c\作业\停车场管理系统\data.txt", "a"))==NULL)
        {
            puts("Failure to open data.txt");
            exit(0);
        }
    	int x;
    	fprintf(stdout, "Please enter the total number of new cars entering the parking lot:");
    	fscanf(stdin, "%d", &x);
    	for(i=0; i<x; ++i)
        {
            fprintf(stdout, "Please enter the car's license plate number:");
            fscanf(stdin, "%s", car[*n].num);
    
            t = time(NULL);
            local = localtime(&t);
            car[*n].time[0] = local->tm_year + 1900;
            car[*n].time[1] = local->tm_mon + 1;
            car[*n].time[2] = local->tm_mday;
            car[*n].time[3] = local->tm_hour;
            car[*n].time[4] = local->tm_min;
    
            fprintf(fp, "%s	", car[*n].num);
            for(j=0; j<5; ++j)
                fprintf(fp, "%d	",car[*n].time[j]);
            fprintf(fp, "
    ");
    
            ++*n;
            if(*n == N)
            {
                fprintf(stdout, "The park is full!
    ");
                break;
            }
        }
        fflush(stdin);
    	fclose(fp);
        return ;
    }
    void CarsInformation(Car car[], int n)
    {
        int i, j;
        fprintf(stdout, "There are %d cars in the park, and there are %d empty places.
    ", n, N-n);
        for(i=0; i<n; ++i)
        {
            fprintf(stdout, "%s	", car[i].num);
            for(j=0; j<5; ++j)
                fprintf(stdout, "%d	", car[i].time[j]);
            fprintf(stdout, "
    ");
        }
        return ;
    }
    

    MCL.h

    #ifndef MCL_H_INCLUDED
    #define MCL_H_INCLUDED
    
    #define N 200//车位
    #define M 10
    typedef struct Node{
        int time[5];
        //出入场时间
        long parktime;
        char num[M];//车牌号
        struct Node *next;
    }Car;
    void Price(int *price);//收费价目
    void Charge(Car car[], int *n, int price, int *sum);//车辆信息,车辆总数,停车花费,
    
    #endif // MCL_H_INCLUDED
    

    MCL.c

    #include <string.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <time.h>
    #include "MCL.h"
    
    void Price(int *price)
    {
        fprintf(stdout, "Now the cost is %d yuan per hour.
    ", *price);
        fprintf(stdout, "Are you going to change it?(y/n)
    ");
        fflush(stdin);
        char c = getchar();
        while(c!='y' && c!='n' && c!='N' && c!='Y'){puts("Input Error!");c=getchar();}
        if(c=='n' || c=='N')return ;
        fprintf(stdout, "Please enter the new cost:(an integer):");
        fscanf(stdin, "%d", price);
        fprintf(stdout, "Now the cost is %d yuan per hour.
    ", *price);
        return ;
    }
    void Charge(Car car[], int *n, int price, int *sum)
    {
        FILE *fp;
        time_t t=time(NULL);
        if((fp = fopen("E:\程序\c\作业\停车场管理系统\data.txt", "r+"))==NULL)
        {
            puts("ERROR!!!!");
            exit(0);
        }
        fflush(stdin);
        int x, i, j, k, flag;
        char emp[M];
        fprintf(stdout, "Please input the number of the leaved cars:");
        fscanf(stdin, "%d", &x);
        for(i=0; i<x; ++i)
        {
            printf("Please enter the car's license plate number:  ");
            fscanf(stdin, "%s", emp);
            flag = 0;
            for(j=0; !flag && j<*n; ++j)
                if(strcmp(emp, car[j].num) == 0)
                {
                    fprintf(stdout, "%s has left, the charge is %ld yuan
    ", emp, (t-car[j].parktime)/3600 * price);
                    *sum += (t-car[j].parktime)/3600 * price;
                    --*n;
                    for(k=j; k<*n; ++k)
                        car[k] = car[k+1];
                    flag = 1;
                }
            if(!flag)
                fprintf(stdout, "%s is not in the Park!
    ", emp);
        }
        if((fp = fopen("E:\程序\c\作业\停车场管理系统\data.txt", "w"))==NULL)
    	{
    		fputs("Failure to open data.txt", stdout);
    		exit(0);
    	}
        for(i=0; i<*n; ++i)
        {
            fprintf(fp, "%s	", car[i].num);
            for(j=0; j<5; ++j)
                fprintf(fp, "%d	", car[i].time[j]);
            fprintf(fp, "
    ");
        }
        fclose(fp);
        return ;
    }
    

    NLH.h

    #ifndef NLH_H_INCLUDED
    #define NLH_H_INCLUDED
    
    #define N 200//车位
    #define M 10
    typedef struct Node{
        int time[5];
        //出入场时间
        long parktime;
        char num[M];//车牌号
        struct Node *next;
    }Car;
    void Print(Car car[], int n, int sum);//车辆信息
    void Sort(Car car[], int n);//排序
    
    #endif // NLH_H_INCLUDED
    

    NLH.c

    #include <stdlib.h>
    #include <stdio.h>
    #include <time.h>
    #include "NLH.h"
    
    void Print(Car car[], int n, int sum)
    {
        fprintf(stdout, "There are %d cars parking today.
    ", n);
        fprintf(stdout, "The income is %d yuan today.
    ", sum);
        return ;
    }
    void Sort(Car car[], int n)
    {
    //初始化
        FILE *fp;
        if((fp = fopen("E:\程序\c\作业\停车场管理系统\data.txt", "w"))==NULL)
    	{
    		puts("Failure to open data.txt");
    		exit(0);
    	}
    	Car emp;
    	int i, j, k;
    //选择排序
    	for(k, i=0; i<n; ++i)
    	{
    	    k=i;
            for(j=k+1; j<n; ++j)
                if(car[j].parktime < car[k].parktime)
                    k=j;
            if(i != k)
            {
                emp = car[i];
                car[i] = car[k];
                car[k] = emp;
            }
    	}
    //输出
    	for(i=0; i<n; ++i)
        {
            fprintf(fp, "%s	", car[i].num);
            for(j=0; j<5; ++j)
                fprintf(fp, "%d	", car[i].time[j]);
            fprintf(fp, "
    ");
        }
        return ;
    }
    
  • 相关阅读:
    一手遮天 Android
    一手遮天 Android
    一手遮天 Android
    一手遮天 Android
    一手遮天 Android
    springcloud-gateway整合Swagger聚合微服务系统API文档
    Gateway 其他配置
    Gateway Global Filters
    Gateway GatewayFilter Factories
    Gateway Route Predicate Factories
  • 原文地址:https://www.cnblogs.com/kuaileyongheng/p/14140283.html
Copyright © 2011-2022 走看看