我是靠谱客的博主 呆萌香烟,最近开发中收集的这篇文章主要介绍马房山实验报告大学C语言实验——网管系统当年我写的并不好,基本没有在意系统结构,所以重在理解,酌情cv实验内容开发环境实验源码,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

武汉理工大学C语言实验——网管

  • 当年我写的并不好,基本没有在意系统结构,所以重在理解,酌情cv
  • 实验内容
  • 开发环境
  • 实验源码
    • 源文件
      • main.c
      • outputMenu.c
      • card.c
      • billion_service.c
    • 头文件
      • main.h
      • outputMenu.h
      • card.h
      • billion_service.h
      • model.h

当年我写的并不好,基本没有在意系统结构,所以重在理解,酌情cv

实验内容

该系统可以实现用户的添加、修改、删除、充值、上下机、上机以及消费数据统计等功能。(不涉及GUI)

开发环境

macOS 10.14 Xcode
各位用vscode的同学可能会遇到某些小问题。
记得改文件路径!

实验源码

建议放到C工程里阅读,以体现出整体结构。
只要稍微听了老师讲了下结构就应该知道每个文件是干什么的(不过有一说一讲了确实和没讲一样)

源文件

main.c

//
//  main.c
//  AccountManager
//
//  Created by WMIII on 2020/3/9.
//  Copyright © 2020 WMIII. All rights reserved.
//  

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "outputMenu.h"
#include "card.h"

Card *head_card;
Card *user_card;
Card *tail_card;
int menu;                       //菜单序号值
float yuanPerT = 1;             //十分钟1元
int tenMnt = 600;
FILE *fp;

int main(int argc, const char * argv[])

{
    initCardList();
    praseCard("/Volumes/Transcend/C/AccountManager/Data/card.ams");
  //每次打开程序时都会先初始化链表,然后将文件中的数据读取到链表中
    
    puts("Account Management System     version: 1.0n");
    puts("Welcome to the account management system");
    outputMenu();
    do
    {
        printf("请选择菜单编号(0~9):");
        scanf("%d",&menu);
        fflush(stdin);
        chooseMenu(menu);
    }
    while(menu!=0);     //输入0时退出系统
    
    return 0;
}

outputMenu.c

//
//  outputMenu.c
//  AccountManager
//
//  Created by WMIII on 2020/3/9.
//  Copyright © 2020 WMIII. All rights reserved.
//

#include "outputMenu.h"

extern Card *head_card;
extern Card *user_card;
extern Card *tail_card;

void outputMenu(void)               //输出菜单
{
    puts("----------MENU----------");
    puts("1.添加卡");
    puts("2.查询卡");
    puts("3.上机");
    puts("4.下机");
    puts("5.充值");
    puts("6.退费");
    puts("7.查询统计");
    puts("8.注销卡");
    puts("9.查询菜单");
    puts("0.退出");
}

void chooseMenu(int menu)           //选择菜单功能
{
    switch (menu)
    {
        case 1:
            puts("-----添加卡-----");
            //insert code here...
            saveCard("/Volumes/Transcend/C/AccountManager/Data/card.ams");
            break;
        case 2:
            puts("-----查询卡-----");
            //insert code here...
            printf("请输入需要查询的卡号:");
            searchCard();
            break;
        case 3:
            puts("-----上机-----");
            //insert code here...
            logon();
            break;
        case 4:
            puts("-----下机-----");
            //insert code here...
            logoff();
            break;
        case 5:
            puts("-----充值-----");
            //insert code here...
            topUp();
            break;
        case 6:
            puts("-----退费-----");
            //insert code here...
            topOff();
            break;
        case 7:
            puts("-----查询统计-----");
            //insert code here...
            break;
        case 8:
            puts("-----注销卡-----");
            //insert code here...
            cancel();
            break;
        case 9:
            outputMenu();
            break;
        case 0:
            puts("-----退出-----");
            releaseCard();
            break;
        default:
            puts("Warning:Illegal menu number.n");
            break;
    }
}

card.c

//
//  card.c
//  AccountManager
//
//  Created by WMIII on 2020/3/16.
//  Copyright © 2020 WMIII. All rights reserved.
//
#include "card.h"
#define True 1
#define False 0

//extern Card *user_card;
extern Card *head_card;
extern Card *tail_card;
extern FILE *fp;
extern float yuanPerT;              //十分钟1元
extern int tenMnt;
char space[] = "                                                  ";


int matchCard(char Name[])          //通过遍历以检查是否有重复的卡号,用于添加卡中。已通过宏定义,True为1;False为0。
{                                   //此函数在 saveCard 函数中调用
    Card *pcard;
    pcard = head_card;
    int signal = 1;                 //判断标志位
    int nindex = 0;
    if(head_card != NULL)           //当链表头部不为空时才进行比较
    {
        do
        {
            if(strcmp(pcard->aName, Name) == 0)
            {
                return nindex;       //卡号存在
            }
            else
            {
                pcard = pcard->next;
                if(pcard == NULL)
                {
                    signal = 0;
                }
            }
            nindex++;
        }
        while (signal);
    }
    return -1;
}


int saveCard(const char* pPath)                 //通过文件的方法添加并保存卡
{
    Card *new_card;
    new_card=(struct Card*)malloc(sizeof(struct Card));
    struct tm *local;
    time_t t;
    t=time(NULL);
    local=localtime(&t);
    new_card->tStart = t;
    new_card->tLast = t;
    new_card->tEnd = t + 31536000;
    printf("卡号(长度为1~18):");     scanf("%s",&(*new_card->aName));
    if(matchCard(new_card->aName) != -1)                 //在此处进行比较,若不存在同名卡号,则直接返回False
    {
        puts("此卡号已存在!");
        free(new_card);                                     //添加失败,释放空间
        return False;
    }
    printf("密码(长度为1~8):");     scanf("%s",&(*new_card->aPwd));
    printf("开卡金额:");  scanf("%f",&(new_card->fBalance));
    printf("状态:");     scanf("%d",&(new_card->nStatus));
    new_card->fTotalUse = 0;
    new_card->nUseCount = 0;
    new_card->nDel = 0;
    
    puts("-----Create Successfully!-----");
    printf("卡号:%s   ",new_card->aName);
    printf("密码:%s   ",new_card->aPwd);
    printf("开卡金额:%.2f    ",new_card->fBalance);
    printf("状态:%dn",new_card->nStatus);
    printf("开卡时间:%d-%d-%d,%d:%d:%dn",local->tm_year+1900,local->tm_mon+1,local->tm_mday,local->tm_hour,local->tm_min,local->tm_sec);
    printf("截止时间:%d-%d-%d,%d:%d:%dnn",local->tm_year+1901,local->tm_mon+1,local->tm_mday,local->tm_hour,local->tm_min,local->tm_sec);
    
    if ((fp = fopen(pPath, "a")) == NULL)
    {
        if ((fp = fopen(pPath, "w")) == NULL)
        {
            puts("打开错误!");
            free(new_card);
            return False;
        }
    }
    
    fprintf(fp, "%s##%s##%.2f##%d##%.2f##%d##%d##%ld##%ld##%ld##%sn", new_card->aName, new_card->aPwd, new_card->fBalance, new_card->nStatus, new_card->fTotalUse, new_card->nUseCount, new_card->nDel, new_card->tStart, new_card->tLast, new_card->tEnd, space);
    //卡号  密码  余额  状态  累计使用  使用次数  删除标识  开卡时间  上次使用时间  截止时间
    fclose(fp);
    
    if (head_card == NULL)                      //这里把新创建的卡添加到链表中
    {
        head_card = tail_card = new_card;
    }
    
    else
    {
        tail_card->next = new_card;
        tail_card = tail_card -> next;
        tail_card->next = NULL;
    }
    return True;
}


int queryCard(char cardName[], char listName[])   //模糊查询卡号,两个参数分别为需查询的卡号、链表中的卡号;
{
    long int l1 = strlen(cardName);      // l1 为需查询的卡号长度
    long int l2 = strlen(listName);      // l2 为链表中卡号长度
    long int i = 0, j = 0;               // i,j用于遍历字符串数组
    while (i < l1 && j <l2)
    {
        if (cardName[i] == listName[j])
            i++;
        
        j++;
    }
    if(i == l1)
        return True;                     //若输入的字符中的字符都能按顺序在卡号中找到,则返回True(即返回1)
    else
        return False;
}
//该函数的思路为按顺序匹配两个字符串中的字符;若输入的字符中的字符都能按顺序在卡号中找到,则该卡号满足查询条件。


void searchCard(void)           //查询卡(模糊查询)
{
    char cardName[18];
    scanf("%s",cardName);
    Card *pcard;
    pcard = head_card;
    char i = 0x00;                 //8位状态寄存器,(暂时)仅最低位有效;最低位置1代表已经找到了相匹配的h卡号,并且输出了卡信息表头,防止表头重复输出
    while(pcard != NULL)
    {
        if (queryCard(cardName, pcard->aName))
        {
            if (i == 0x00)
            {
                printf("n卡号      状态      余额      累计使用    使用次数       上次使用时间  n");    //输出卡信息表头
                i = (i | 1);                                                                            //输出之后i的最低位置1
            }
            
            struct tm *local;
            local = localtime(&pcard->tLast);
            printf("%s       %d      %.2f      %.2f        %d       %d-%d-%d, %d:%dn",pcard->aName, pcard->nStatus, pcard->fBalance, pcard->fTotalUse, pcard->nUseCount, local->tm_year+1900,local->tm_mon+1,local->tm_mday,local->tm_hour,local->tm_min);
        }
        
        pcard = pcard->next;            //指向下一张卡
        
        if (pcard == NULL && i == 0x00)    //已遍历完链表,并且未找到相匹配的卡时
        {
            puts("找不到相关信息!n");
        }
    }
}


void initCardList(void)               //初始化链表函数
{
    head_card=(struct Card*)malloc(sizeof(struct Card));
    head_card= NULL;
}


void releaseCard(void)     //释放链表
{
    if (head_card != NULL)
    {
        free(head_card);
        head_card = head_card->next;
    }
    free(head_card);
}


void praseCard(const char* pPath)                  //将文件中的信息放入链表中
{
    char buf[256];
    fp = fopen(pPath, "r");
    
    while(!feof(fp))                                //未到文件末尾时
    {
        while (fgets(buf, 256, fp) != NULL)          //当返回的一行不为空时进行转换
        {
            int i = 0;
            char flag[10][20];
            char* str;
            str = strtok(buf, "##");
            
            while (str != NULL && strcmp(str, "n"))
            {
                strcpy(flag[i], str);
                str = strtok(NULL, "##");
                i++;
            }
            
            Card* strToCard = NULL;                 //将数据保存在结构体中
            strToCard = (struct Card*)malloc(sizeof(struct Card));
            strcpy(strToCard->aName, flag[0]);
            strcpy(strToCard->aPwd, flag[1]);
            strToCard->fBalance = atof(flag[2]);
            strToCard->nStatus = atoi(flag[3]);
            strToCard->fTotalUse = atof(flag[4]);
            strToCard->nUseCount = atoi(flag[5]);
            strToCard->nDel = atoi(flag[6]);
            strToCard->tStart = atol(flag[7]);
            strToCard->tLast = atol(flag[8]);
            strToCard->tEnd = atol(flag[9]);
            
            if (head_card == NULL)                  //将结构体添加到链表中
            {
                head_card = tail_card = strToCard;
            }
            else
            {
                tail_card->next = strToCard;
                tail_card = tail_card -> next;
                tail_card->next = NULL;
            }
        }
    }
}


Card* doLogon(char Name[], char Pwd[])
{
    int nindex = matchCard(Name);
    int i;
    Card* pcard = head_card;
    for(i = nindex; i>0; i--)
    {
        pcard = pcard->next;
    }
    
    if (pcard != NULL)
    {
        if (strcmp(Pwd, pcard->aPwd) != 0)
        {
            puts("账号或密码不正确!");
            return NULL;
        }
        switch (pcard->nStatus)
        {
            case 1:
                puts("该卡正在上机!");
                return NULL;
                break;
                
            case 2:
                puts("该卡已注销!");
                return NULL;
                break;
                
            case 3:
                puts("该卡已失效!");
                return NULL;
                break;
        }
        if (pcard->fBalance <= 0)
        {
            puts("该卡余额不足!");
            return  NULL;
        }
        pcard->nStatus = 1;
        pcard->nUseCount++;
        pcard->tLast = time(NULL);
        updateCard(pcard, "/Volumes/Transcend/C/Account_Manager 2.0/Data/card.ams", nindex);
        return pcard;
    }
    else
        return NULL;
}


int updateCard(const Card* pcard,const char *pPath , int nindex)
{
    char aBuf[256] = {0};
    int nLine = 0;
    long int lPosition = 0;
    
    if ((fp = fopen(pPath, "r+")) == NULL)
    {
        puts("打开错误!");
        return False;
    }

    rewind(fp);
    while ((nLine < nindex))
    {
        if(fgets(aBuf, 256, fp) != NULL)
        {
            lPosition = ftell(fp);
            nLine++;
        }
    }
    fseek(fp, lPosition, 0);
    memset(aBuf, ' ', 80);
    
    fprintf(fp, "%s", aBuf);
    fseek(fp, lPosition, 0);
    
    fprintf(fp, "%s##%s##%.2f##%d##%.2f##%d##%d##%ld##%ld##%ld##", pcard->aName, pcard->aPwd, pcard->fBalance, pcard->nStatus, pcard->fTotalUse, pcard->nUseCount, pcard->nDel, pcard->tStart, pcard->tLast, pcard->tEnd);
    //卡号  密码  余额  状态  累计使用  使用次数  删除标识  开卡时间  上次使用时间  截止时间
    fclose(fp);

    return True;
}


int logon(void)
{
    struct tm* local;
    char cardName[18];
    char cardPwd[8];
    printf("请输入卡号:");    scanf("%s",cardName);
    printf("请输入密码:");    scanf("%s",cardPwd);
    Card* pcard;
    pcard = doLogon(cardName, cardPwd);
    
    if (pcard == NULL)
    {
        puts("上机失败n");
        return False;
    }
    else
        puts("上机成功!");
    
    local = localtime(&pcard->tLast);
    puts("卡号       余额          上机时间");
    printf("%s      %.2f     %d-%d-%d, %d:%dn", pcard->aName, pcard->fBalance,    local->tm_year+1900,local->tm_mon+1,local->tm_mday,local->tm_hour,local->tm_min);
    
    int i = addLogon(pcard);
    if(i == 1)
    {
        puts("数据保存成功!n");
        return True;
    }
    else
    {
        puts("数据保存失败!");
        return False;
    }
}


Card* doLogoff(char Name[], char Pwd[])     //下机
{
    int nindex = matchCard(Name);
    int i;
    Card* pcard = head_card;
    float useTime;                          //单位:秒
    int useTmnt;                            //单位:10分钟

    for(i = nindex; i>0; i--)
    {
        pcard = pcard->next;
    }
    if (pcard != NULL)
    {
        if (strcmp(Pwd, pcard->aPwd) != 0)
        {
            puts("账号或密码不正确!");
            return NULL;
        }
        switch (pcard->nStatus)
        {
            case 0:
                puts("该卡未上机!");
                return NULL;
                break;
                
            case 2:
                puts("该卡已注销!");
                return NULL;
                break;
                
            case 3:
                puts("该卡已失效!");
                return NULL;
                break;
        }
        if (pcard->fBalance <= 0)
        {
            puts("该卡余额不足!");
            return NULL;
        }
        
        useTime = time(NULL) - pcard->tLast;
        useTmnt = useTime/tenMnt;
        useTmnt++;                          //为了方便,做一次奸商吧
        useTime = useTmnt;
        
        pcard->fBalance -= useTime * yuanPerT;
        pcard->fTotalUse += useTime * yuanPerT;
        pcard->nStatus = 0;                 //下机状态
        updateCard(pcard, "/Volumes/Transcend/C/Account_Manager 2.0/Data/card.ams", nindex);
        return pcard;
    }
    else
        return NULL;
}


int logoff(void)
{
    struct tm* local;
    struct tm* logoffTime;
    char cardName[18];
    char cardPwd[8];
    printf("请输入卡号:");    scanf("%s",cardName);
    printf("请输入密码:");    scanf("%s",cardPwd);
    Card* pcard;
    pcard = doLogoff(cardName, cardPwd);
    
    if (pcard == NULL)
    {
        puts("下机失败n");
        return False;
    }
    else
        puts("下机成功!");
    
    float useTime;                          //单位:秒
    int useTmnt;                            //单位:10分钟
    useTime = time(NULL) - pcard->tLast;
    useTmnt = useTime/tenMnt;
    useTmnt++;                          //为了方便,做一次奸商吧
    useTime = useTmnt;
    
    local = localtime(&pcard->tLast);
    long int t = time(NULL);
    logoffTime = localtime(&t);
    
    puts("卡号       余额          上机时间              下机时间           消费金额");
    printf("%s      %.2f     %d-%d-%d, %d:%d    %d-%d-%d, %d:%d       %.2fn", pcard->aName, pcard->fBalance,   local->tm_year+1900,local->tm_mon+1,local->tm_mday,local->tm_hour,local->tm_min, logoffTime->tm_year+1900,logoffTime->tm_mon+1,logoffTime->tm_mday,logoffTime->tm_hour,logoffTime->tm_min,useTime);
    
    int i = addBilling(pcard);
    if(i == 1)
    {
        puts("数据保存成功!n");
        return True;
    }
    else
    {
        puts("数据保存失败!");
        return False;
    }
}

billion_service.c

//
//  billion_service.c
//  AccountManager
//
//  Created by WMIII on 2020/4/6.
//  Copyright © 2020 WMIII. All rights reserved.
//

#include "billion_service.h"

#define True 1
#define False 0

extern Card *head_card;
extern Card *tail_card;
extern float yuanPerT;                     //十分钟1元
extern int tenMnt;


int addLogon(Card* pcard)
{
    LogonInfo* plogon = NULL;
    plogon = (struct LogonInfo*)malloc(sizeof(struct LogonInfo));
    
    strcpy(plogon->aCardName, pcard->aName);
    plogon->tLogon = pcard->tLast;
    plogon->fBalance = pcard->fBalance;
    
    saveLogon(plogon, "/Volumes/Transcend/C/Account_Manager 2.0/Data/billion.ams");
    free(plogon);
    return True;
}


int saveLogon(LogonInfo* plogon, const char *pPath)
{
    FILE* fp;
    if ((fp = fopen(pPath, "a")) == NULL)
    {
        if ((fp = fopen(pPath, "w")) == NULL)
        {
            puts("打开错误!");
            return False;
        }
    }
    
    fprintf(fp, "%s##%ld##%.2fn", plogon->aCardName, plogon->tLogon, plogon->fBalance);
    fclose(fp);
    return True;
}


int addBilling(Card* pcard)
{
    Billing* pbilling = NULL;
    pbilling = (struct Billing*)malloc(sizeof(struct Billing));

    strcpy(pbilling->aCardName, pcard->aName);
    pbilling->tStart = pcard->tLast;
    pbilling->tEnd = time(NULL);
    pbilling->fAmount = ((pbilling->tEnd - pbilling->tStart)/tenMnt) * yuanPerT + 1;
    pbilling->nStatus = pcard->nStatus;
    pbilling->nDel = pcard->nDel;
    
    saveBilling(pbilling, "/Volumes/Transcend/C/Account_Manager 2.0/Data/billion.ams");
    free(pbilling);
    return True;
}


int saveBilling(Billing* pbilling, const char *pPath)
{
    FILE* fp;
    if ((fp = fopen(pPath, "a")) == NULL)
    {
        if ((fp = fopen(pPath, "w")) == NULL)
        {
            puts("打开错误!");
            return False;
        }
    }
    
    fprintf(fp, "%s##%ld##%ld##%.2f##%d##%dn", pbilling->aCardName, pbilling->tStart, pbilling->tEnd, pbilling->fAmount, pbilling->nStatus, pbilling->nDel);
    //卡号  上机时间  下机时间  消费金额  消费状态  删除标识
    
    fclose(fp);
    return True;
}


int addTopUp(Card* pcard, float topUpNum)
{
    TopupInfo* ptopup = NULL;
    ptopup = (struct TopupInfo*)malloc(sizeof(struct  TopupInfo));
    strcpy(ptopup->aCardName, pcard->aName);
    ptopup -> tTime = time(NULL);
    ptopup -> nStatus = 0;
    ptopup -> fMoney = topUpNum;
    ptopup -> nDel = pcard -> nDel;
    
    saveTop(ptopup, "/Volumes/Transcend/C/Account_Manager 2.0/Data/money.ams");
    free(ptopup);
    return True;
}


int addTopOff(Card* pcard)
{
    TopupInfo* ptopoff = NULL;
    ptopoff = (struct TopupInfo*)malloc(sizeof(struct  TopupInfo));
    strcpy(ptopoff -> aCardName, pcard -> aName);
    ptopoff -> tTime = time(NULL);
    ptopoff -> nStatus = 1;
    ptopoff -> fMoney = pcard -> fBalance;
    ptopoff -> nDel = pcard -> nDel;
    saveTop(ptopoff, "/Volumes/Transcend/C/Account_Manager 2.0/Data/money.ams");
    free(ptopoff);

    return True;
}


int saveTop(TopupInfo* ptopup, const char *pPath)
{
    FILE *fp;
    if ((fp = fopen(pPath, "a")) == NULL)
    {
        if ((fp = fopen(pPath, "w")) == NULL)
        {
            puts("打开错误!");
            return False;
        }
    }
    
    fprintf(fp, "%s##%ld##%d##%f##%dn",ptopup -> aCardName, ptopup -> tTime, ptopup -> nStatus, ptopup -> fMoney, ptopup -> nDel);
    //卡号    操作时间    状态  金额   删除标识
    fclose(fp);
    return True;
}


int topUp(void)
{
    //struct tm* topUpTime;
    char cardName[18];
    char cardPwd[8];
    float topUpNum = 0;
    printf("请输入卡号:");        scanf("%s",cardName);
    printf("请输入密码:");        scanf("%s",cardPwd);
    printf("请输入操作金额:");     scanf("%f",&topUpNum);
    Card* pcard = dotopUp(cardName, cardPwd, topUpNum);
    if (pcard == NULL)
    {
        puts("充值失败!n");
        return False;
    }
    else
        puts("充值成功!");
    puts("卡号       充值金额       余额");
    printf("%s       %.2f        %.2fn", pcard -> aName, topUpNum, pcard -> fBalance);
    addTopUp(pcard, topUpNum);

    return True;
}


Card* dotopUp(char Name[], char Pwd[], float topUpNum)
{
    int nindex = matchCard(Name);               //zc找到对应的卡
    int i;
    Card* pcard = head_card;
    for(i = nindex; i>0; i--)
    {
        pcard = pcard->next;
    }
    
    if (pcard != NULL)
    {
        if (strcmp(Pwd, pcard->aPwd) != 0)
        {
            puts("账号或密码不正确!");
            return NULL;
        }
        switch (pcard->nStatus)
        {
            case 2:
                puts("该卡已注销!");
                return NULL;
                break;
                
            case 3:
                puts("该卡已失效!");
                return NULL;
                break;
        }
        
        
        pcard -> fBalance += topUpNum;
        updateCard(pcard, "/Volumes/Transcend/C/Account_Manager 2.0/Data/card.ams", nindex);
        return pcard;
    }
    
    else
        return NULL;
}


int topOff(void)
{
    char cardName[18];
    char cardPwd[8];
    printf("请输入卡号:");        scanf("%s",cardName);
    printf("请输入密码:");        scanf("%s",cardPwd);
    Card* pcard = dotopOff(cardName, cardPwd, 0);
    if (pcard == NULL)
    {
        puts("退费失败!n");
        return False;
    }
    else
        puts("退费成功!n");
    
    return True;
}


Card* dotopOff(char Name[], char Pwd[], int sta)    //0-退费;2-注销
{
    int nindex = matchCard(Name);               //找到对应的卡
    int i;
    Card* pcard = head_card;
    for(i = nindex; i>0; i--)
    {
        pcard = pcard->next;
    }
    if (pcard != NULL)
    {
        if (strcmp(Pwd, pcard->aPwd) != 0)
        {
            puts("账号或密码不正确!");
            return NULL;
        }
        switch (pcard->nStatus)
        {
            case 1:
                puts("该卡正在使用!");
                return NULL;
                break;
            case 2:
                puts("该卡已注销!");
                return NULL;
                break;
            case 3:
                puts("该卡已失效!");
                return NULL;
                break;
        }
        if (pcard->fBalance <= 0)
        {
            puts("该卡余额不足!");
            return NULL;
        }
        float topOffNum = pcard -> fBalance;
        pcard -> nStatus = sta;
        addTopOff(pcard);
        pcard -> fBalance = 0;
        updateCard(pcard, "/Volumes/Transcend/C/Account_Manager 2.0/Data/card.ams", nindex);
        puts("卡号      退费金额      余额");
        printf("%s       %.2f     %.2fn", pcard -> aName, topOffNum, 0.00);
        return pcard;
    }
    else
        return NULL;
}


int cancel(void)
{
    char cardName[18];
    char cardPwd[8];
    printf("请输入卡号:");        scanf("%s",cardName);
    printf("请输入密码:");        scanf("%s",cardPwd);
    Card* pcard = dotopOff(cardName, cardPwd, 2);
    if (pcard == NULL)
    {
        puts("注销失败!n");
        return False;
    }
    else
        puts("注销成功!n");
    
    return True;

}

头文件

main.h

当时在学32创建个main.h看着舒服(乐)

//
//  main.h
//  AccountManager
//
//  Created by WMIII on 2020/3/9.
//  Copyright © 2020 WMIII. All rights reserved.
//

#ifndef main_h
#define main_h

#endif /* main_h */

outputMenu.h

//
//  outputMenu.h
//  AccountManager
//
//  Created by WMIII on 2020/3/9.
//  Copyright © 2020 WMIII. All rights reserved.
//

#ifndef outputMenu_h
#define outputMenu_h

#include <stdio.h>
#include <stdlib.h>
#include "model.h"
#include "card.h"

void outputMenu(void);      //输出菜单
void chooseMenu(int menu);  //选择菜单命令

#endif /* outputMenu_h */

card.h

//
//  card.h
//  AccountManager
//
//  Created by WMIII on 2020/3/16.
//  Copyright © 2020 WMIII. All rights reserved.
//

#ifndef card_h
#define card_h

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "card.h"
#include "billion_service.h"
#include "model.h"


void addCard(void);
void searchCard(void);
int queryCard(char cardName[], char listName[]);           //支持模糊查询的查询卡函数
int matchCard(char Name[]);
void initCardList(void);
int saveCard(const char* pPath);
void releaseCard(void);
void praseCard(const char* pPath);
Card* judgeLogdo(char Name[]);
int logon(void);
int logoff(void);
Card* doLogon(char Name[], char Pwd[]);
Card* doLogoff(char Name[], char Pwd[]);
int updateCard(const Card* pcard,const char *pPath , int nindex);


#endif /* card_h */

billion_service.h

//
//  billion_service.h
//  AccountManager
//
//  Created by WMIII on 2020/4/6.
//  Copyright © 2020 WMIII. All rights reserved.
//

#ifndef billion_service_h
#define billion_service_h

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "card.h"
#include "model.h"


int addBilling(Card* pcard);
int addLogon(Card* pacrd);
int saveBilling(Billing* pbilling, const char *pPath);
int saveLogon(LogonInfo* plogon, const char *pPath);
int topUp(void);
int topOff(void);
Card* dotopUp(char Name[], char Pwd[], float topUpNum);
Card* dotopOff(char Name[], char Pwd[], int status);
int addTopUp(Card* pcard, float topUpNum);
int addTopOff(Card* pcard);
int saveTop(TopupInfo* ptopup, const char *pPath);
int cancel(void);

#endif /* billion_service_h */

model.h

//
//  model.h
//  AccountManager
//
//  Created by WMIII on 2020/3/16.
//  Copyright © 2020 杨富淇. All rights reserved.
//
//  该文件保存全部结构体
#ifndef model_h
#define model_h

#include <time.h>

typedef struct Card         // 卡信息结构体
{
    char aName[18];         // 卡号
    char aPwd[8];           // 密码
    int  nStatus;           // 卡状态(0-未上机;1-正在上机;2-已注销;3-失效)
    time_t tStart;          // 开卡时间
    time_t tEnd;            // 卡的截止时间
    float fTotalUse;        // 累计金额
    time_t tLast;           // 最后使用时间
    int nUseCount;          // 使用次数
    float fBalance;         // 余额
    int nDel;               // 删除标识 0-未删除,1-删除
    struct Card *next;
}Card;


typedef struct Billing
{
    char aCardName[18];     // 卡号
    time_t tStart;          // 上机时间
    time_t tEnd;            // 下机时间
    float fAmount;          // 消费金额
    int nStatus;            // 消费状态     0-未结算,1-已结算;
    int nDel;               // 删除标识     0-未删除,1-已删除;
}Billing;


typedef struct LogonInfo
{
    char aCardName[18];     // 上机卡号
    time_t tLogon;          // 上机时间
    float fBalance;         // 上机时余额
}LogonInfo;


typedef struct LogoffInfo
{
    char aCardName[18];     // 上机卡号
    time_t tStart;          // 上机时间
    time_t tEnd;            // 下机时间
    float fAmount;          // 消费金额
    float fBalance;         // 余额
}LogoffInfo;


typedef struct TopupInfo
{
    char aCardName[18];     //卡号
    time_t tTime;           //充值/退费时间
    int nStatus;            //状态,0-充值;1-退费
    float fMoney;           //金额
    int nDel;               //删除标识,0-未删除;1-删除
}TopupInfo;


#endif /* model_h */

最后

以上就是呆萌香烟为你收集整理的马房山实验报告大学C语言实验——网管系统当年我写的并不好,基本没有在意系统结构,所以重在理解,酌情cv实验内容开发环境实验源码的全部内容,希望文章能够帮你解决马房山实验报告大学C语言实验——网管系统当年我写的并不好,基本没有在意系统结构,所以重在理解,酌情cv实验内容开发环境实验源码所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(42)

评论列表共有 0 条评论

立即
投稿
返回
顶部