MFC中CList类库的遍历

#include <iostream>
#include "List.h"
using namespace std;
void main()
{CList list;list.AddHead(33);list.AddHead(88);list.AddHead(99);POSITION pos = list.GetHeadPosition();cout << "正向:" << endl;while (pos)cout << list.GetNext(pos) << endl;cout << "反向:" << endl;pos = list.GetTailPosition();while (pos)cout << list.GetPrev(pos) << endl;cout << "共有:" << list.GetCount() << "条数据" << endl;
}

C++中定义CStudent类

文件名:Student.h

#pragma once
#include <afxtempl.h>
typedef struct SUser
{int nNumb;char sName[20];float fMath;
}DATA;typedef bool(*BY_FUNC)(DATA& q,DATA& m);class CStudent
{CList<DATA> m_list;int Menu();int Input();void Delete();void Modify();void Print();void Sort(BY_FUNC pFunc);int SortMenu();void Load();void Save();public:CStudent();~CStudent();void Start();
};

类成员函数实现

文件名:Student.cpp

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include "Student.h"
using namespace std;
int CStudent::Menu()
{system("cls");//clear screenputs("\n\t\t1、浏览所有信息");puts("\t\t2、添加信息");puts("\t\t3、删除信息");puts("\t\t4、修改信息");puts("\t\t5、查找信息");puts("\t\t0、退出");printf("\t\t请选择:");int i = 0;cin >> i;switch (i){case 1:while (SortMenu());break;case 2:while (Input());break;case 3:Delete();case 4:Modify();}return i;
}int CStudent::Input()
{cout << "请输入学号:";DATA d;cin >> d.nNumb;cout << "请输入姓名和数学成绩(空格间隔):";cin >> d.sName >> d.fMath;m_list.AddTail(d);Print();Save();cout << "是否继续添加?";rewind(stdin);char c = getchar();return c == 'y' || c == 'Y';return 0;
}void CStudent::Delete()
{int nNumb;Print();cout << "\n请输入要删除的学号:";cin >> nNumb;POSITION pos = m_list.GetHeadPosition();while (pos){if (m_list.GetAt(pos).nNumb == nNumb){m_list.RemoveAt(pos);Print();cout << "删除成功!" << endl;system("pause");Save();return false;}m_list.GetNext(pos);}cout << "你输入的学号不存在,是否继续删除?[y/n]" ;char c = _getch();putchar(c);puts("");return 'y' == c || 'Y' == c;
}void CStudent::Modify()
{}void CStudent::Print()
{POSITION pos = m_list.GetHeadPosition();while (pos){DATA d = m_list.GetAt(pos);cout << d.nNumb << "\t" << d.sName << "\t" << d.fMath << endl;m_list.GetNext(pos);}system("pause");
}bool byNumb(DATA& q,DATA& m)
{return q.nNumb < m.nNumb;
}bool byName(DATA& q, DATA& m)
{return strcmp(q.sName, m.sName) < 0;
}bool byMath(DATA& q, DATA& m)
{return q.fMath > m.fMath;
}void CStudent::Sort(BY_FUNC pFunc)
{POSITION pos = m_list.GetHeadPosition(), m, q;while (pos){m = q = pos;m_list.GetNext(q);while (q){//if (m_list.GetAt(q).nNumb < m_list.GetAt(m).nNumb)if(pFunc(m_list.GetAt(q),m_list.GetAt(m)))m = q;m_list.GetNext(q);}if (m != pos){DATA t = m_list.GetAt(pos);m_list.SetAt(pos, m_list.GetAt(m));m_list.SetAt(m, t);}m_list.GetNext(pos);}Print();
}int CStudent::SortMenu()
{system("cls");puts("1.按学号排序");puts("2.按姓名排序");puts("3.按成绩排序");puts("4.不排序");puts("0.返回主菜单");int i = 0;cin >> i;BY_FUNC ps[] = { byNumb,byName,byMath };switch (i){case 1:case 2:case 3:Sort(ps[i-1]);break;case 4:Print();default:return i;}return i;return 0;
}void CStudent::Load()
{FILE* pf = fopen("stud.lv", "r");if (!pf){puts("加载文件时失败!");system("pause");return;}DATA t;while (fread(&t, 1, sizeof(DATA), pf) == sizeof(DATA))m_list.AddTail(t);fclose(pf);
}void CStudent::Save()
{FILE* pf = fopen("stud.lv", "w");if (!pf){puts("保存文件时失败!");system("pause");return;}POSITION pos = m_list.GetHeadPosition();while (pos){fwrite(pos, 1, sizeof(DATA), pf);m_list.GetNext(pos);}
}CStudent::CStudent()
{}CStudent::~CStudent()
{}void CStudent::Start()
{Load();while (Menu());
}

主函数

文件名:main.cpp

#include <iostream>
#include "Student.h"
int main()
{CStudent st;st.Start();return 0;
}

【2】C++语法与数据结构之MFC_CList学生管理系统_链表内排序_函数指针相关推荐

  1. 【3】C++语法与数据结构之MFC_CList学生管理系统_链表外排序_函数指针

    注意:此时排序规则函数定义为全局函数 C++中定义CStudent类 文件名:Student.h #pragma once #include <afxtempl.h> typedef st ...

  2. 【6】C++语法与数据结构之STL_list学生管理系统_链表外排序_函数指针

    本文通过STL类库的list数据结构来完成学生管理系统,采用链表外排序,通过函数指针实现. 注意:此时排序规则函数定义为类静态成员函数,等价于全局函数 函数指针定义为 BY_FUNC ps[] = { ...

  3. 【5】C++语法与数据结构之STL_list学生管理系统_链表内排序_函数指针

    本文通过STL类库的list数据结构来完成学生管理系统,采用链表内排序,通过list类库自带sort函数进行排序. 注意:此时排序规则函数定义为类静态成员函数,等价于全局函数 函数指针定义为 BY_F ...

  4. 学生管理系统(链表)

    文章目录 前言 一.具体过程 1.引入头文件contact.h 2.创建test.c 3.创建contact.c 二.写在最后 前言 链表的学生管理系统相比之前更高效,同样有内存的扩充,也补充了文件操 ...

  5. 学生管理系统(C++语言_顺序表)

    该程序是基于C++语言实现的学生管理系统.其中运用到了STL里的容容器,算法和迭代器,以及C++11的仿函数等.主要实现了学生信息的增删改查等.有不足之处还请各路朋友们指正. 测试环境为Windows ...

  6. 学生管理系统——用链表实现

    前言 该程序是大一上学期的课设,在上学期的基础上对此程序进行了细节上的优化,以及将程序分成多个文件,第一次对多文件开发有了了解(再也不要将几千行代码放在一个文件内了) 一. 软件功能描述 假设学生成绩 ...

  7. 学生管理系统(链表+数据库)学习小结

    //学生管理系统的小结(另一个版本http://blog.csdn.net/ytz_linuxer/archive/2009/07/18/4358937.aspx) 作者:刘晓兵 语言:C语言,主要是 ...

  8. 数据结构课程实验——学生管理系统——源代码

    源代码 screen类(用来与用户交互) import java.util.*;class screen {void maindan(){student1 pg1=new student1();pg1 ...

  9. 学生管理系统 java 开题报告_基于JAVA的学籍管理系统开题报告.doc

    毕业设计(论文)选题申请表 基本情况学生姓名 学 号 专 业 年 级题 目基于JAVA的学生学籍管理系统的设计与实现选题来源指导教师推荐( 学生自拟( 其它(选择本题目原因 选择基于JAVA的学生学籍 ...

最新文章

  1. 我佛了!用KNN实现验证码识别,又 Get 到一招!
  2. Linux发行版上安装Netbeans IDE的各种方法
  3. 图深度学习(GraphDL),下一个人工智能算法热点
  4. IIS7 授权配置错误
  5. 今日arXiv精选 | 11篇ICCV 2021最新论文
  6. 【Linux系统编程】 Linux系统调用概述
  7. 2015-03-18 header note creation in my Appointment
  8. c++ opencv mat_实战 | OpenCV 实现多张图像拼接
  9. protobuf序列化协议python教程
  10. 人工智能与机器学习大牛们的blog
  11. 阶段3 1.Mybatis_04.自定义Mybatis框架基于注解开发_3 基于注解的自定义再分析
  12. Barrage 弹幕实现原理
  13. 长白山沟谷地带珍贵药材选址设计实习
  14. 计算机主板上电源供电缩写,新电脑电源标准开始普及?取消5V、3.3V供电,主板供电变为10PIN...
  15. 痘痘告诉你,身体哪里生病了
  16. 锚具ovm是什么意思_OVM锚具(柳州欧维姆)
  17. Forth 系统实现
  18. GIT提交错分支,push错分支怎么办
  19. 转:红帽旗下Linux的版本说明RedHat、CentOS、Fedora、OEL等
  20. 爱江山更爱美人服务器维修怎么,爱江山更爱美人落星院详细玩法攻略

热门文章

  1. Docker原理及常见命令
  2. 艾克姆 STC15W4K56S4 IAP15W4K58S4 51开发板 大赛esp8266开发板 STC15W4K56S4
  3. 大阪第83天——可怕的日本(转贴)
  4. 安装webase时报错,Nginx冲突!
  5. 目前 流行到 TTS软件 和 发音库
  6. 【高德地图API】从零开始学高德JS API(五)路线规划——驾车|公交|步行
  7. 如何在小程序内实现界面快速置顶功能?
  8. Python免费发短信
  9. 笔记本联想(Lenovo)G40-70M加装内存和SSD固态硬盘
  10. [osg]源码分析:osg::Vec3, osg::Vec3f