|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
老师老师让同学写个学生成绩管理系统,可以保存到文件
今天写了个类,通用性高
分享
- #include<stdio.h>
- #include "cache.h"
- struct stkey
- {
- char szKey[20];
- bool operator < (const stkey &c) const
- {
- int iRev = strcmp(szKey,c.szKey);
- if(iRev<0)
- return true;
- return false;
- }
- void print()
- {
- printf("key:%s\t",szKey);
- }
- };
- template <class K>
- struct student
- {
- K key;
- int nNum;
- int nSocre;
- char szAsin[50];
- void print()
- {
- key.print();
- printf("学号:%d,分数:%d,个性签名:%s\n",nNum,nSocre,szAsin);
- }
- };
- int main(void)
- {
- //Cache<int,struct student<int> > cache_fist;
- Cache<struct stkey,struct student<struct stkey> > cache;
- #if 0
- for (int i=0;i<100;i++)
- {
- struct student<struct stkey> st = {0};
- sprintf(st.key.szKey,"学生%d",i+1);
- st.nNum = i+1;
- st.nSocre = i+100;
- sprintf(st.szAsin,"因为专注所以专业_%d",i+1);
- cache.add(st);
- }
- struct stkey st={"学生2"};
- if (cache.del(st))
- {
- printf("%s删除成功\n",st.szKey);
- }
- if(cache.save("1.dat"))
- {
- printf("保存成功\n");
- }
- #else
- cache.load("1.dat");
- cache.print();
- #endif
- system("pause");
- return 0;
- }
复制代码
完整的下载地址,含视频解说
|
|