|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
c-free5.0 ,vs2017编译通过
//#define _CRT_SECURE_NO_WARNINGS
#include <ctime>
#include <string>
#include <iostream>
#include <windows.h>
#include <stdio.h>
using namespace std;
#define SETBUFTONULL while(getchar() != '\n'); // 消除多余的回车键
struct purchaseHistory // 一条包含 卡编号,持卡人姓名,消费类型,金额,时间 的记录
{
string id;
string name;
string type;
float money;
string time;
purchaseHistory *next;
};
purchaseHistory *myStudentInfo = NULL;// 第一条记录,初始化为空
void setcolor(unsigned short); // 设置颜色,(为了使界面更加的友好)
void getoxy(int, int); // 使光标调到指定的地方
void newRecord(); // 新增一条记录
void fidRecord(); // 查询记录
string Get_Current_Date(); // 返回一个 "M-D-Y"格式的当前时间
BOOL hangUpTable(purchaseHistory); // 录入一条记录
void printRecordOne(purchaseHistory, POINT); // 一条记录
void queryID(); // 查找(ID)
void queryName(); // 查找(姓名)
void queryType(); // 查找(消费类型)
void printAll(); // 打印所有记录
void help(); // 帮助
void read();
void storage();
int main()
{
void read();
system("title Information recording system ..");
while (TRUE)
{
system("cls");
setcolor(8);
cout << "请按照对应的序号进行选择\n\n";
setcolor(12);
cout << "1 >增 加 记 录<\n" // 选项菜单
<< "2 >查 询 记 录<\n"
<< "3 >帮 助 信 息<\n"
<< "4 >退 出 程 序<\n\n"
<< ":: 请选择 ";
setcolor(10);
switch (getchar())
{
case '1': newRecord(); break;
case '2': fidRecord(); break;
case '3': help(); break;
case '4': storage(); return 0;
default:setcolor(8); cout << "\n 请重新输入..."; Sleep(500); // 这个是延时函数,参数是毫秒
}
SETBUFTONULL
}
return 0;
}
void setcolor(unsigned short color)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color); // 系统的API函数,设置控制台字体颜色
}
void gotoxy(int x, int y)
{
COORD f = { y,x };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), f);
}
void newRecord()
{
SETBUFTONULL
system("cls");
purchaseHistory mydata;
setcolor(8);
cout << "请按照次格式进行记录的录入 : 卡编号 持卡人姓名 消费类型 消费金额\n";
setcolor(12);
cout << "> 在此处输入数据 :";
setcolor(10);
cin >> mydata.id >> mydata.name >> mydata.type >> mydata.money; // 数据录入
mydata.time = Get_Current_Date().c_str();
if (hangUpTable(mydata) == TRUE) // 将录入的数据添加到记录链
{
setcolor(8);
cout << "::成功录入一条数据";
Sleep(500);
}
}
void fidRecord()
{
system("title Query record"); // 设置标题为
while (TRUE)
{
SETBUFTONULL
system("cls");
setcolor(12);
cout << "1 >查询 (卡ID)<\n"
<< "2 >查询 (持卡人姓名)<\n"
<< "3 >查询 (消费类型)<\n\n"
<< "4 >打印全部记录\n"
<< "5 >返回助菜单<\n\n"
<< ":: 请选择 ";
setcolor(10);
switch (getchar())
{
case '1': queryID(); break;
case '2': queryName(); break;
case '3': queryType(); break;
case '4': printAll(); break;
case '5': ; return;
default:setcolor(8); cout << "\n 请重新输入..."; Sleep(500);
}
}
}
string Get_Current_Date()
{
time_t nowtime;
nowtime = time(NULL); //获取日历时间
char tmp[64];
strftime(tmp, sizeof(tmp), "%Y-%m-%d", localtime(&nowtime));
return tmp;
}
BOOL hangUpTable(purchaseHistory mydata)
{
purchaseHistory *p = new purchaseHistory; // 链表节点的添加
p->next = myStudentInfo;
myStudentInfo = p;
p->id = mydata.id;
p->name = mydata.name;
p->type = mydata.type;
p->money = mydata.money;
p->time = mydata.time;
return TRUE;
}
void printRecordOne(purchaseHistory data,POINT pos) // 格式化输出,让输出变得更整齐
{
gotoxy(pos.x, pos.y);
cout << "ID: ";
cout << data.id;
gotoxy(pos.x, pos.y + 12);
cout << "姓名: ";
cout << data.name;
gotoxy(pos.x, pos.y + 26);
cout << "类型: ";
cout << data.type;
gotoxy(pos.x, pos.y + 40);
cout << "金额: ";
cout << data.money;
gotoxy(pos.x, pos.y + 52);
cout << "时间: ";
cout << data.time;
}
void queryID()
{
system("cls");
SETBUFTONULL
string fid;
setcolor(12);
cout << "> 输入ID:";
setcolor(10);
cin >> fid;
setcolor(12);
cout << "\n::找到如下记录 :\n";
setcolor(15);
purchaseHistory *p = myStudentInfo;
int pos = 0;
while (p != NULL) // 遍历链表,满足条件就输出该记录
{
if (p->id.compare(fid) == 0)
{
POINT a = { 4 + pos++,2 };
printRecordOne(*p,a);
}
p = p->next;
}
setcolor(8);
cout << "\n按回车键继续..\n";
Sleep(1000);
SETBUFTONULL
}
void queryName()
{
system("cls");
SETBUFTONULL
string fid;
setcolor(12);
cout << "> 输入持卡人姓名:";
setcolor(10);
cin >> fid;
setcolor(12);
cout << "\n::找到如下记录 :\n";
setcolor(15);
purchaseHistory *p = myStudentInfo;
int pos = 0;
while (p != NULL) // 遍历链表,满足条件就输出该记录
{
if (p->name.compare(fid) == 0)
{
POINT a = { 4 + pos++,2 };
printRecordOne(*p, a);
}
p = p->next;
}
setcolor(8);
cout << "\n按回车键继续..\n";
Sleep(1000);
SETBUFTONULL
}
void queryType()
{
system("cls");
SETBUFTONULL
string fid;
setcolor(12);
cout << "> 输入消费类型:";
setcolor(10);
cin >> fid;
setcolor(12);
cout << "\n::找到如下记录 :\n";
setcolor(15);
purchaseHistory *p = myStudentInfo;
int pos = 0;
while (p != NULL) // 遍历链表,满足条件就输出该记录
{
if (p->type.compare(fid) == 0)
{
POINT a = { 4 + pos++,2 };
printRecordOne(*p, a);
}
p = p->next;
}
setcolor(8);
cout << "\n按回车键继续..\n";
Sleep(1000);
SETBUFTONULL
}
void printAll()
{
system("cls");
setcolor(12);
cout << "\n::找到如下记录 :\n";
setcolor(15);
purchaseHistory *p = myStudentInfo;
int pos = 0;
while (p != NULL) // 遍历链表,打印所有记录
{
POINT a = { 4 + pos++,2 };
printRecordOne(*p, a);
p = p->next;
}
setcolor(8);
cout << "\n按回车键继续..\n";
Sleep(1000);
SETBUFTONULL
}
void help()
{
system("cls"); // 介绍怎么用
setcolor(11);
cout << "如何新增一条消费记录:\n\n";
setcolor(8);
cout << " 增加消费记录的时候,请按照此格式 :卡编号 持卡人姓名 消费类型 消费金额 进行录入,消费的时间系统会自动录入,每项记录之间用空格分开,如果发现打印有错误,则用回车分隔每项记录\n";
setcolor(11);
cout << "如何查询消费记录:\n\n";
setcolor(8);
cout << " 查询消费记录有以下几个模式\n";
setcolor(7);
cout << " 按照 ID 进行查询,该查询会查找出所有符合添加的记录\n";
cout << " 按照 姓名 进行查询,该查询会查找出所有符合添加的记录\n";
cout << " 按照 消费类型 进行查询,该查询会查找出所有符合添加的记录\n";
setcolor(11);
cout << "关于本程序:\n\n";
setcolor(8);
cout << " \n 0.0 没有介绍喔!";
setcolor(12);
cout << "\n\n 按回车继续.....";
Sleep(1000);
SETBUFTONULL
}
void read()
{
/*
FILE *fp = fopen("data.json","r");
if(fp == NULL) return ;
while(!feof(fp))
{
purchaseHistory *p = new purchaseHistory;
p->next = myStudentInfo;
myStudentInfo = p;
fscanf(fp,"%s %s %f %s\n",p->id,p->name,p->money,p->time);
}
fclose(fp);*/
}
void storage()
{
/*
FILE *fp = fopen("data.json","w+");
purchaseHistory *p = myStudentInfo;
while(p != NULL)
{
fprintf(fp,"%s %s %f %s\n",p->id,p->name,p->money,p->time);
p = p->next;
// delete(myStudentInfo);
/ myStudentInfo = p;
}
fclose(fp);*/
} |
评分
-
查看全部评分
|