├── .gitignore ├── .vscode ├── c_cpp_properties.json ├── launch.json ├── settings.json └── tasks.json ├── C++Lesson ├── .1.1 practice.cpp ├── .1.2 copy.cpp ├── .1.3.cpp ├── .1.4.cpp ├── .1.5.cpp ├── .1.6.cpp ├── .1.7.cpp ├── .2.1.cpp ├── .2.2.cpp ├── .2.3.cpp ├── .2.4.cpp ├── .2.5.cpp ├── .3.1.cpp ├── .3.2.cpp ├── .3.3.cpp ├── .3.4.cpp ├── .3.5.cpp ├── .3.6.cpp ├── .3.7.cpp ├── .3.8.cpp ├── .3.9.cpp ├── .4.1.cpp ├── .4.2.cpp ├── .4.3.cpp ├── .5.1.cpp ├── .5.2.cpp ├── .5.3.cpp ├── .5.4.cpp ├── .6.1.cpp ├── .6.2.cpp ├── .6.3.cpp ├── .6.4.cpp ├── .7.1.cpp ├── .7.2.cpp ├── .9.1.cpp ├── .9.2.cpp ├── .9.3.cpp ├── .9.4.cpp ├── 1.10.1 func copy 2.cpp ├── 1.2.1 例题 cin cout.cpp ├── 1.3.1 static_cast const_cast.cpp ├── 1.5.1 func.cpp ├── 1.5.2 func.cpp ├── 1.9.cpp ├── 2.1 myDate.cpp ├── 2.2 Student.cpp ├── 2.3 driver.cpp ├── 3.1.1 copy func.cpp ├── 3.1.4 copy func copy.cpp ├── 3.13 copy.cpp ├── 3.14.31 copy 2.cpp ├── 3.15 friend copy.cpp ├── 3.16 friend copy 2.cpp ├── 3.17 friend.cpp ├── 3.18 this.cpp ├── 3.2 copy func copy 2.cpp ├── 3.2.1 copy func copy 3.cpp ├── 3.2.5 static copy.cpp ├── 3.3 static.cpp ├── 3.9 const.cpp ├── 4.1 operator.cpp ├── 4.2 operator.cpp ├── 4.2.1 operator copy 2.cpp ├── 4.4.cpp ├── 4.5 stream.cpp ├── 4.6 stream copy.cpp ├── 4.7 operator type.cpp ├── 4.8 auto multi.cpp ├── 4.9 auto multi copy.cpp ├── 5.11 multi inherit copy.cpp ├── 5.14 public.cpp ├── 5.15.cpp ├── 5.16.cpp ├── 5.17.cpp ├── 5.18.cpp ├── 5.19.cpp ├── 5.23.cpp ├── 5.4 static son.cpp ├── 5.5 son.cpp ├── 5.6 son type.cpp ├── 5.7 type copy.cpp ├── 7.1.cpp ├── 7.10.cpp ├── 7.11.cpp ├── 7.12.cpp ├── 7.13.cpp ├── 7.14.cpp ├── 7.2.cpp ├── 7.3.cpp ├── 7.4.cpp ├── 7.5.cpp ├── 7.6.cpp ├── 7.7.cpp ├── 7.8.cpp ├── 7.9.cpp ├── 8.1.cpp ├── 8.2.cpp ├── 9.1.cpp ├── 9.6.cpp ├── input.dat ├── input2.dat ├── main copy.cpp ├── main type.cpp ├── main.cpp └── test.txt ├── C++Practice ├── 1.test.cpp ├── C-SIMS │ ├── BU.dat │ ├── C-SIMS.sln │ ├── C-SIMS.vcxproj │ ├── C-SIMS.vcxproj.filters │ ├── CS.dat │ ├── MA.dat │ ├── StudIMS.cpp │ ├── Student.cpp │ └── Student.h ├── SIMS │ ├── BU.dat │ ├── CS.dat │ ├── MA.dat │ ├── SIMS.sln │ ├── SIMS.vcxproj │ ├── SIMS.vcxproj.filters │ ├── Student.cpp │ ├── Student.h │ ├── myfunc.cpp │ ├── myfunc.h │ └── stuInfoMS.cpp ├── demo1 │ ├── Observer.cpp │ ├── Observer.h │ ├── Observerable.cpp │ ├── Observerable.h │ ├── Singleton.cpp │ ├── Singleton.h │ ├── demo1.cpp │ ├── demo1.sln │ ├── demo1.vcxproj │ └── demo1.vcxproj.filters ├── exam-a.cpp ├── exam-b.cpp ├── exam-b.dsp ├── exam-b.opt ├── exam-b.plg ├── noobtest │ ├── noobtest.cpp │ ├── noobtest.sln │ ├── noobtest.vcxproj │ └── noobtest.vcxproj.filters ├── studTest │ ├── CS.dat │ ├── Employee.txt │ ├── cs.txt │ ├── studTest.sln │ ├── studTest.vcxproj │ ├── studTest.vcxproj.filters │ └── students.cpp └── 环境搭建.md ├── C++基础补充-菜鸟教程.assets └── image-20210701020655565.png ├── C++基础补充-菜鸟教程.md ├── C++实战笔记-罗剑锋.md ├── C++实现学生信息管理系统.assets ├── image-20211020141109034.png ├── image-20211020141202556.png ├── image-20211020141217839.png ├── image-20211020141305130.png ├── image-20211020141320169.png ├── image-20211020141353469.png ├── image-20211020141417347.png ├── image-20211020141446629-16347104871251-16347104874922.png ├── image-20211020141446629-16347104871251.png ├── image-20211020141446629.png ├── image-20211020141507906.png ├── image-20211020141519022.png ├── image-20211020141717472.png ├── image-20211020141729565.png ├── image-20211020141743039.png ├── image-20211020141809730.png ├── image-20211020141854587.png ├── image-20211020141900449.png ├── image-20211020141911534.png ├── image-20211020141917357.png ├── image-20211020142033914.png ├── image-20211020142040534.png ├── image-20211020142047142.png ├── image-20211020142052313.png ├── image-20211020142114604.png ├── image-20211020142120036.png ├── image-20211020142127909.png ├── image-20211020142133397.png └── image-20211020142141791.png ├── C++实现学生信息管理系统.md ├── C_2Level ├── 1.Fibonacci sequence.c ├── 10.pointerArray.c ├── 11.pointerArray2.c ├── 12.pointerArray3.c ├── 13.pointerChar.c ├── 14.CharPractice.c ├── 15.funfactorial.c ├── 16.FILEwrite.c ├── 17.FILEread.c ├── 2.switch.c ├── 3.A-aExchange.c ├── 4.LettersSum.c ├── 5.func.c ├── 6.Transfer parameters.c ├── 7.Comma expression.c ├── 8.pointer.c └── 9.array.c ├── C_C++网络编程,从socket到epoll.assets ├── image-20210705144109361.png ├── image-20210705224417795.png └── image-20210705235241828.png ├── C_C++网络编程,从socket到epoll.md ├── C_DataStruc ├── d.c.1.0.time.c ├── d.c.1.1.leafnode_num.c ├── d.c.1.2.StraightInsertSort.c ├── d.c.1.3.InitiateLinkList.c ├── d.c.1.4.SearchBin.c ├── d.c.1.5.MM.c ├── d.c.1.6.preorder.c ├── d.c.1.7.Height.c ├── d.c.1.8..c ├── d.c.2.hong.c ├── d.c.3.struct.c ├── d.c.4.common.c ├── d.c.5.Linked list.c ├── d.c.6.dynamic linked list.c ├── d.c.7.Bitwise and.c └── d.c.8.c ├── ComputerNetwork ├── 1.gethostbyname.cpp ├── TCPdtc.cpp ├── TCPdtd.cpp ├── UDPdtc.cpp ├── UDPdtd.cpp ├── chatServer │ ├── chatServer.cpp │ ├── chatServer.sln │ ├── chatServer.vcxproj │ └── chatServer.vcxproj.filters ├── conTCP.cpp ├── conUDP.cpp ├── consock.cpp ├── errexit.cpp ├── passTCP.cpp ├── passUDP.cpp ├── passsock.cpp ├── timeClient │ ├── socketToEpoll.sln │ ├── socketToEpoll.vcxproj │ ├── socketToEpoll.vcxproj.filters │ └── timeClient.cpp └── timeServer │ ├── timeServer.cpp │ ├── timeServer.sln │ ├── timeServer.vcxproj │ └── timeServer.vcxproj.filters ├── QT ├── hello.cpp └── hello.h ├── WinSock2 介绍和使用.md ├── readme.md ├── runoob_C++ ├── 1.enum.cpp ├── 2.1.time.cpp ├── 2.2.ctime.cpp ├── 2.3.UTC.cpp ├── 2.3.localtime.cpp ├── 3.vector.cpp ├── 4.1.struct.cpp ├── 5.1.this.cpp ├── 6.1.virtual class.cpp ├── 7.1.trycatch.cpp ├── 8.1.file.cpp ├── 8.2.fileToObj.cpp └── 9.1.strCopy.cpp ├── test └── test.cpp ├── 重构你的C++知识体系.assets ├── image-20210614151906425.png ├── image-20210614163449148.png ├── image-20210614210809551.png ├── image-20210614210835469.png ├── image-20210614210912489.png ├── image-20210614210955598.png ├── image-20210614211125429.png ├── image-20210614212540778.png ├── image-20210614214610073.png ├── image-20210614214734879.png ├── image-20210614215222003.png ├── image-20210615030116586.png ├── image-20210615032854986.png ├── image-20210615162644999.png ├── image-20210615172103195.png ├── image-20210615174553010.png ├── image-20210615175409247.png ├── image-20210616151449502.png ├── image-20210616164751511.png ├── image-20210616231240853.png ├── image-20210616233840459.png ├── image-20210616234259086.png ├── image-20210616234851389.png ├── image-20210617020952360.png ├── image-20210617021008259.png ├── image-20210617164318813.png ├── image-20210617164448957.png ├── image-20210617165343966.png ├── image-20210617220542688.png ├── image-20210617220811295.png ├── image-20210617230304263.png ├── image-20210620214025500.png ├── image-20210620214101363.png ├── image-20210623011547211.png ├── image-20210623011723074.png ├── image-20210623165734882.png ├── image-20210623215619574.png ├── image-20210623215725958.png ├── image-20210625024426055.png ├── image-20210625024752763.png └── image-20210625025022609.png └── 重构你的C++知识体系.md /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/* 2 | !.vscode/settings.json 3 | !.vscode/tasks.json 4 | !.vscode/launch.json 5 | !.vscode/extensions.json 6 | *.code-workspace 7 | ## Ignore Visual Studio temporary files, build results, and 8 | ## files generated by popular Visual Studio add-ons. 9 | 10 | # User-specific files 11 | *.suo 12 | *.user 13 | *.userosscache 14 | *.sln.docstates 15 | *.exe 16 | # User-specific files (MonoDevelop/Xamarin Studio) 17 | *.userprefs 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | bld/ 27 | [Bb]in/ 28 | [Oo]bj/ 29 | [Ll]og/ 30 | 31 | # Visual Studio 2019 cache/options directory 32 | .vs/ 33 | # Uncomment if you have tasks that create the 34 | 35 | # Visual C++ cache files 36 | ipch/ 37 | *.aps 38 | *.ncb 39 | *.opensdf 40 | *.sdf 41 | *.cachefile 42 | 43 | # Visual Studio profiler 44 | *.psess 45 | *.vsp 46 | *.vspx 47 | 48 | 49 | # C++ objects and libs 50 | *.slo 51 | *.lo 52 | *.o 53 | *.a 54 | *.la 55 | *.lai 56 | *.so 57 | *.so.* 58 | *.dll 59 | *.dylib 60 | 61 | # Qt-es 62 | object_script.*.Release 63 | object_script.*.Debug 64 | *_plugin_import.cpp 65 | /.qmake.cache 66 | /.qmake.stash 67 | *.pro.user 68 | *.pro.user.* 69 | *.qbs.user 70 | *.qbs.user.* 71 | *.moc 72 | moc_*.cpp 73 | moc_*.h 74 | qrc_*.cpp 75 | ui_*.h 76 | *.qmlc 77 | *.jsc 78 | Makefile* 79 | *build-* 80 | *.qm 81 | *.prl 82 | 83 | # Qt unit tests 84 | target_wrapper.* 85 | 86 | # QtCreator 87 | *.autosave 88 | 89 | # QtCreator Qml 90 | *.qmlproject.user 91 | *.qmlproject.user.* 92 | 93 | # QtCreator CMake 94 | CMakeLists.txt.user* 95 | 96 | # QtCreator 4.8< compilation database 97 | compile_commands.json 98 | 99 | # QtCreator local machine specific files for imported projects 100 | *creator.user* 101 | 102 | *_qmlcache.qrc 103 | /ComputerNetwork/uWebSockets 104 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Win32", 5 | "includePath": [ 6 | "${workspaceFolder}/**" 7 | ], 8 | "defines": [ 9 | "_DEBUG", 10 | "UNICODE", 11 | "_UNICODE" 12 | ], 13 | "intelliSenseMode": "gcc-x64", 14 | "compilerPath": "C:/TDM-GCC-64/bin/g++.exe" 15 | } 16 | ], 17 | "version": 4 18 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // https://code.visualstudio.com/docs/cpp/launch-json-reference 2 | { 3 | "version": "0.2.0", 4 | "configurations": [{ 5 | "name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示 6 | "type": "cppdbg", // 配置类型,对于C/C++可认为此处只能是cppdbg,由cpptools提供;不同编程语言不同 7 | "request": "launch", // 可以为launch(启动)或attach(附加) 8 | "program": "${fileDirname}/${fileBasenameNoExtension}.exe", // 将要进行调试的程序的路径 9 | "args": [], // 程序调试时传递给程序的命令行参数,一般设为空 10 | "stopAtEntry": false, // 设为true时程序将暂停在程序入口处,相当于在main上打断点 11 | "cwd": "${workspaceFolder}", // 调试程序时的工作目录,此为工作区文件夹;改成${fileDirname}可变为文件所在目录 12 | "environment": [], // 环境变量 13 | "externalConsole": false, // 使用单独的cmd窗口,与其它IDE一致;为false时使用内置终端 14 | "internalConsoleOptions": "neverOpen", // 如果不设为neverOpen,调试时会跳到“调试控制台”选项卡,你应该不需要对gdb手动输命令吧? 15 | "MIMode": "gdb", // 指定连接的调试器,可以为gdb或lldb。但我没试过lldb 16 | "miDebuggerPath": "gdb.exe", // 调试器路径,Windows下后缀不能省略,Linux下则不要 17 | "setupCommands": [ 18 | { // 模板自带,好像可以更好地显示STL容器的内容,具体作用自行Google 19 | "description": "Enable pretty-printing for gdb", 20 | "text": "-enable-pretty-printing", 21 | "ignoreFailures": false 22 | } 23 | ], 24 | "preLaunchTask": "Compile" // 调试前执行的任务,一般为编译程序。与tasks.json的label相对应 25 | }] 26 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.defaultLanguage": "c", // ctrl+N新建文件后默认的语言 3 | // "editor.formatOnType": true, // 输入分号(C/C++的语句结束标识)后自动格式化当前这一行的代码 4 | // "editor.suggest.snippetsPreventQuickSuggestions": false, // clangd的snippets有很多的跳转点,不用这个就必须手动触发Intellisense了 5 | // "editor.acceptSuggestionOnEnter": "off", // 我个人的习惯,按回车时一定是真正的换行,只有tab才会接受Intellisense 6 | // "editor.snippetSuggestions": "top", // (可选)snippets显示在补全列表顶端,默认是inline 7 | 8 | // "code-runner.runInTerminal": true, // 设置成false会在“输出”中输出,无法输入 9 | // "code-runner.executorMap": { 10 | // "c": "gcc '$fileName' -o '$fileNameWithoutExt.exe' -Wall -O2 -m64 -lm -static-libgcc -fexec-charset=GBK -D__USE_MINGW_ANSI_STDIO && &'./$fileNameWithoutExt.exe'", 11 | // "cpp": "g++ '$fileName' -o '$fileNameWithoutExt.exe' -Wall -O2 -m64 -static-libgcc -fexec-charset=GBK && &'./$fileNameWithoutExt.exe'" 12 | // // "c": "gcc $fileName -o $fileNameWithoutExt.exe -Wall -O2 -m64 -lm -static-libgcc -fexec-charset=GBK -D__USE_MINGW_ANSI_STDIO && $dir$fileNameWithoutExt.exe", 13 | // // "cpp": "g++ $fileName -o $fileNameWithoutExt.exe -Wall -O2 -m64 -static-libgcc -fexec-charset=GBK && $dir$fileNameWithoutExt.exe" 14 | // }, // 右键run code时运行的命令;未注释的仅适用于PowerShell(Win10默认)和pwsh,文件名中有空格也可以编译运行;注释掉的适用于cmd(win7默认)、PS和bash,但文件名中有空格时无法运行 15 | // "code-runner.saveFileBeforeRun": true, // run code前保存 16 | // "code-runner.preserveFocus": true, // 若为false,run code后光标会聚焦到终端上。如果需要频繁输入数据可设为false 17 | // "code-runner.clearPreviousOutput": false, // 每次run code前清空属于code runner的终端消息,默认false 18 | // "code-runner.ignoreSelection": true, // 默认为false,效果是鼠标选中一块代码后可以单独执行,但C是编译型语言,不适合这样用 19 | // "code-runner.fileDirectoryAsCwd": true, // 将code runner终端的工作目录切换到文件目录再运行,对依赖cwd的程序产生影响;如果为false,executorMap要加cd $dir 20 | 21 | "C_Cpp.clang_format_sortIncludes": true, // 格式化时调整include的顺序(按字母排序) 22 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | // https://code.visualstudio.com/docs/editor/tasks 2 | { 3 | "version": "2.0.0", 4 | "tasks": [{ 5 | "label": "Compile", // 任务名称,与launch.json的preLaunchTask相对应 6 | "command": "g++", // 要使用的编译器,C++用g++;gcc:C; 7 | "args": [ 8 | "${file}", 9 | "-o", // 指定输出文件名,不加该参数则默认输出a.exe,Linux下默认a.out 10 | "${fileDirname}/${fileBasenameNoExtension}.exe", 11 | "-g", // 生成和调试有关的信息 断点参数 12 | // "-m64", // 不知为何有时会生成16位程序而无法运行,此条可强制生成64位的 13 | "-Wall", // 开启额外警告 14 | "-static-libgcc", // 静态链接libgcc,一般都会加上 15 | // "-fexec-charset=GBK", // 生成的程序使用GBK编码,不加这条会导致Win下输出中文乱码;繁体系统改成BIG5 16 | // "-D__USE_MINGW_ANSI_STDIO", // 用MinGW写C时留着,否则不需要,用于支持printf的%zd和%Lf等 17 | ], // 编译的命令,其实相当于VSC帮你在终端中输了这些东西 18 | "type": "process", // process是把预定义变量和转义解析后直接全部传给command;shell相当于先打开shell再输入命令,所以args还会经过shell再解析一遍 19 | "group": { 20 | "kind": "build", 21 | "isDefault": true // 不为true时ctrl shift B就要手动选择了 22 | }, 23 | "presentation": { 24 | "echo": true, 25 | "reveal": "always", // 执行任务时是否跳转到终端面板,可以为always,silent,never。具体参见VSC的文档,即使设为never,手动点进去还是可以看到 26 | "focus": false, // 设为true后可以使执行task时焦点聚集在终端,但对编译C/C++来说,设为true没有意义 27 | "panel": "shared" // 不同的文件的编译信息共享一个终端面板 28 | }, 29 | "problemMatcher":"$gcc" // 捕捉编译时终端里的报错信息到问题面板中,修改代码后需要重新编译才会再次触发 30 | // 本来有Lint,再开problemMatcher就有双重报错,但MinGW的Lint效果实在太差了;用Clangd可以注释掉 31 | }] 32 | } -------------------------------------------------------------------------------- /C++Lesson/.1.1 practice.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void func(int a, int b, int c = 0) 4 | { 5 | cout << a << b << c; 6 | } 7 | int main() 8 | { 9 | func(5, 9); 10 | return 0; 11 | } -------------------------------------------------------------------------------- /C++Lesson/.1.2 copy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | const int x = 5, y = 6; 7 | const int *p = &x; 8 | p = &y; 9 | cout << *p << endl; 10 | return 0; 11 | } -------------------------------------------------------------------------------- /C++Lesson/.1.3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | double pi = 3.14159; 4 | int main() 5 | { 6 | double r; 7 | cout << "输入r:"; 8 | cin >> r; 9 | double l = 2.0 * pi * r; 10 | double s = pi * r * r; 11 | cout << l << endl; 12 | cout << s << endl; 13 | return 0; 14 | } -------------------------------------------------------------------------------- /C++Lesson/.1.4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | public: 6 | int fun(double x) 7 | { 8 | return int(x / 2); 9 | } 10 | int fun(int x) 11 | { 12 | return x * 2; 13 | } 14 | }; 15 | int main() 16 | { 17 | A a; 18 | int s = a.fun(6.0) + a.fun(2); 19 | cout << s; 20 | return 0; 21 | } -------------------------------------------------------------------------------- /C++Lesson/.1.5.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int f(int); 5 | int main() 6 | { 7 | for (int i = 0; i < 3; i++) 8 | { 9 | cout << f(i) << endl; 10 | } 11 | return 0; 12 | } 13 | int f(int a) 14 | { 15 | int b = 0, c = 1; 16 | b++; 17 | c++; 18 | return int(a + pow(double(b), 2) + c); 19 | } -------------------------------------------------------------------------------- /C++Lesson/.1.6.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | float bigger(int a, float b) 4 | { 5 | if (a > b) 6 | return a; 7 | else 8 | return b; 9 | } 10 | int main() 11 | { 12 | int xI = 10; 13 | float yF = 40.444; 14 | cout << bigger(xI, yF); 15 | return 0; 16 | } -------------------------------------------------------------------------------- /C++Lesson/.1.7.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | // 程序设计题 4 | // 将键盘输入的 n 个字符保存到 一维数组 A 中。输入字符前,先输入 n 值。 5 | // 数组 A 动态申请空间,程序结束再释放 6 | 7 | // 2.输出 n 个字符串中最长的和最短的串,计算n个串的平均长度。 8 | int main() 9 | { 10 | int a = 1; 11 | int b = a--; 12 | // const int c; 13 | cout << a-- << endl 14 | << b; 15 | return 0; 16 | } -------------------------------------------------------------------------------- /C++Lesson/.2.1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Test 4 | { 5 | int x, y; 6 | 7 | public: 8 | Test(int a, int b) 9 | { 10 | x = a; 11 | y = b; 12 | } 13 | int getx() 14 | { 15 | return x; 16 | } 17 | int gety() 18 | { 19 | return y; 20 | } 21 | }; 22 | int main() 23 | { 24 | Test mt(10, 20); 25 | cout << mt.getx() << mt.gety() << endl; 26 | return 0; 27 | } -------------------------------------------------------------------------------- /C++Lesson/.2.2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Test 4 | { 5 | int x, y; 6 | 7 | public: 8 | void fun(int a, int b) 9 | { 10 | x = a; 11 | y = b; 12 | } 13 | void show() 14 | { 15 | cout << x; 16 | if (y > 0) 17 | cout << y << endl; 18 | } 19 | }; 20 | int main() 21 | { 22 | Test a; 23 | a.fun(1, 10); 24 | a.show(); 25 | a.fun(2, 0); 26 | a.show(); 27 | return 0; 28 | } -------------------------------------------------------------------------------- /C++Lesson/.2.3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Test 4 | { 5 | public: 6 | int x, y; 7 | 8 | private: 9 | int a, b; 10 | 11 | public: 12 | int getc(); 13 | }; 14 | int Test::getc() 15 | { 16 | return a; 17 | } 18 | int main() 19 | { 20 | Test a; 21 | cout << a.x << endl 22 | << a.getc(); 23 | return 0; 24 | } -------------------------------------------------------------------------------- /C++Lesson/.2.4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int *p1; 7 | int **p2 = &p1; 8 | int b = 20; 9 | p1 = &b; 10 | cout << **p2 << endl 11 | << *p2; 12 | 13 | return 0; 14 | } -------------------------------------------------------------------------------- /C++Lesson/.2.5.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | private: 6 | int x, y; 7 | 8 | public: 9 | int getx() 10 | { 11 | return x; 12 | } 13 | int gety() 14 | { 15 | return y; 16 | } 17 | void setx(int x0) 18 | { 19 | x = x0; 20 | } 21 | void sety(int y0) 22 | { 23 | y = y0; 24 | } 25 | void displayx() 26 | { 27 | cout << "x=" << x << endl; 28 | } 29 | void displayy() 30 | { 31 | cout << "y=" << y << endl; 32 | } 33 | }; 34 | int main() 35 | { 36 | A obj, *p, arr[10]; 37 | obj.setx(111); 38 | cout << obj.getx() << endl; 39 | obj.displayx(); 40 | 41 | p = new A; 42 | (*p).setx(56); 43 | p->sety(78); 44 | int k = (*p).getx(); 45 | int m = p->gety(); 46 | cout << "k=" << k << endl; 47 | cout << "m=" << m << endl; 48 | for (int i = 0; i < 5; i++) 49 | { 50 | arr[i].setx(i + 10); 51 | arr[i].sety(i + 20); 52 | } 53 | p = &arr[9]; 54 | while (p >= &arr[5]) 55 | { 56 | p->setx(88); 57 | p->sety(99); 58 | p--; 59 | } 60 | for (int i = 0; i < 10; i++) 61 | cout << arr[i].getx() << " , " << arr[i].gety() << endl; 62 | return 0; 63 | } -------------------------------------------------------------------------------- /C++Lesson/.3.1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | float x; 6 | 7 | public: 8 | void f(float a) 9 | { 10 | x = a; 11 | } 12 | float friend max(A &a, A &b); 13 | }; 14 | float max(A &a, A &b) 15 | { 16 | return (a.x > b.x) ? a.x : b.x; 17 | } 18 | int main() 19 | { 20 | A a, b; 21 | a.f(2.2); 22 | b.f(3.3); 23 | cout << max(a, b); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /C++Lesson/.3.2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | float x, y; 6 | 7 | public: 8 | void f(float a, float b) 9 | { 10 | x = a; 11 | y = b; 12 | } 13 | void friend print(A a); 14 | }; 15 | void print(A a) 16 | { 17 | cout << a.x << "," << a.y; 18 | } 19 | int main() 20 | { 21 | A a; 22 | a.f(3.0, 5.0); 23 | print(a); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /C++Lesson/.3.3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | public: 6 | int x, y; 7 | void init(int a, int b) 8 | { 9 | x = a; 10 | y = b; 11 | } 12 | }; 13 | int main() 14 | { 15 | A a; 16 | a.init(5, 9); 17 | cout << a.x << a.y; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /C++Lesson/.3.4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | private: 6 | static int num; 7 | 8 | public: 9 | A(int n); 10 | void show(); 11 | }; 12 | int A::num = 5; 13 | A::A(int n) 14 | { 15 | num = n; 16 | } 17 | void A::show() 18 | { 19 | cout << num; 20 | } 21 | int main() 22 | { 23 | A a(10); 24 | a.show(); 25 | return 0; 26 | } -------------------------------------------------------------------------------- /C++Lesson/.3.5.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | int a, b; 6 | 7 | public: 8 | A(int x = 0, int y = 0) 9 | { 10 | a = x; 11 | b = y; 12 | cout << a << "," << b; 13 | } 14 | }; 15 | int main() 16 | { 17 | A *p; 18 | // p = new A(4, 5); 19 | p = new A(1, 2); 20 | return 0; 21 | } -------------------------------------------------------------------------------- /C++Lesson/.3.6.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | int m; 6 | 7 | public: 8 | A() {} 9 | A(int a) : m(a) {} 10 | int get() { return m; } 11 | void set(int a) { m = a; } 12 | }; 13 | int main() 14 | { 15 | A *p = new A[2]; 16 | p->set(30); 17 | p = p + 1; 18 | p->set(50); 19 | A a[2] = {1, 9}; 20 | cout << a[0].get() << "," << a[1].get() << endl; 21 | cout << p->get() << endl; 22 | p = p - 1; 23 | cout << p->get() << endl; 24 | delete[] p; 25 | return 0; 26 | } -------------------------------------------------------------------------------- /C++Lesson/.3.7.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | int n; 6 | 7 | public: 8 | A() { n = 1; } 9 | int getValue() const 10 | { 11 | return n; 12 | } 13 | int getValue() 14 | { 15 | return 2 * n; 16 | } 17 | }; 18 | int main() 19 | { 20 | const A a; 21 | A a2; 22 | cout << a.getValue() << "," << a2.getValue(); 23 | return 0; 24 | } -------------------------------------------------------------------------------- /C++Lesson/.3.8.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | int n; 6 | 7 | public: 8 | A(int j = 5) { n = j++; } 9 | void print() const 10 | { 11 | cout << n << endl; 12 | } 13 | void print() 14 | { 15 | n = n + 1; 16 | cout << n; 17 | } 18 | }; 19 | int main() 20 | { 21 | A a; 22 | const A a2(2); 23 | a.print(); 24 | a2.print(); 25 | return 0; 26 | } -------------------------------------------------------------------------------- /C++Lesson/.3.9.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | public: 6 | int x, y; 7 | void init(int initx, int inity) 8 | { 9 | x = initx; 10 | y = inity; 11 | } 12 | int getx() 13 | { 14 | return x; 15 | } 16 | int gety() 17 | { 18 | return y; 19 | } 20 | }; 21 | void dispaly(A &a) 22 | { 23 | cout << a.getx() << "," << a.gety() << endl; 24 | } 25 | int main() 26 | { 27 | A B[5]{{5, 5}, {3, 3}, {1, 1}, {2, 2}, {4, 4}}; 28 | A *p = B; 29 | B[3].init(7, 3); 30 | p->init(7, 8); 31 | for (int k = 0; k < 5; k++) 32 | dispaly(*(p++)); 33 | return 0; 34 | } -------------------------------------------------------------------------------- /C++Lesson/.4.1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | double x, y; 6 | 7 | public: 8 | A(double r = 0, double i = 0) : x(r), y(i) {} 9 | operator double(); 10 | }; 11 | A::operator double() { return x; } 12 | int main() 13 | { 14 | A a(1.2, -3.4); 15 | cout << (double)a << endl; 16 | double n = 12 + a; 17 | cout << n; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /C++Lesson/.4.2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | 6 | int real, imag; 7 | 8 | public: 9 | A(int r = 0, int i = 0) 10 | { 11 | real = r; 12 | imag = i; 13 | } 14 | A operator-(A &c); // 重载为成员函数 15 | A friend operator+(A &a, A &b); //重载为友元 16 | void out() 17 | { 18 | cout << real << "," << imag << endl; 19 | } 20 | }; 21 | A operator+(A &a, A &b) 22 | { 23 | int r = a.real + b.real; 24 | int i = a.imag + b.imag; 25 | return A(r, i); 26 | } 27 | A A::operator-(A &c) 28 | { 29 | cout << real << "," << imag << endl; 30 | int r = this->real - c.real; 31 | int i = this->imag - c.imag; 32 | return A(r, i); 33 | } 34 | int main() 35 | { 36 | A a(1, 2), b(3, 4), z; 37 | z = a + b; 38 | z.out(); 39 | z = a - b; 40 | z.out(); 41 | return 0; 42 | } -------------------------------------------------------------------------------- /C++Lesson/.4.3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class pointer 4 | { 5 | public: 6 | int a; 7 | int *p; 8 | pointer() 9 | { 10 | a = 100; 11 | p = new int(10); //初始化内存 12 | *p = 11; //向内存赋值 13 | } 14 | pointer(const pointer &temp) //复制构造函数 15 | { 16 | if (this != &temp) 17 | { 18 | a = temp.a; // a 是局部变量,内存跟随对象 19 | p = temp.p; // p 是指针变量,内存固定,需要深度复制 20 | // cout << "*p=" << *p << ",p=" << p << endl; 21 | // delete p; //删除指针,新指针的地址还是原来的地址,不能删除 22 | // p = new int(*temp.p + 1); //把指针 temp.p 的值赋值给 指针 p 23 | // *p = *temp.p + 10; //加10更好分辨 *p 24 | // cout << "*p=" << *p << ",p=" << p << endl; 25 | } 26 | } 27 | ~pointer() //析构函数 28 | { 29 | if (p != NULL) 30 | delete p; 31 | } 32 | pointer operator=(pointer &a) //成员函数 重载赋值运算符 33 | { 34 | if (this == &a) 35 | return *this; 36 | else 37 | { 38 | delete p; 39 | this->p = new int(*a.p); 40 | cout << "*p3=" << *p << ",p3=" << p << endl; 41 | return *this; 42 | } 43 | } 44 | }; 45 | int main() 46 | { 47 | pointer p1; 48 | pointer p2(p1); 49 | cout << p1.a << ",p1=" << *p1.p << "," << (p1.p == p2.p) << endl; 50 | p1.a = 123; 51 | *p1.p = 234; 52 | cout << (p1.a == p2.a) << ",p2=" << *p1.p << "," << (p1.p == p2.p) << endl; 53 | return 0; 54 | } -------------------------------------------------------------------------------- /C++Lesson/.5.1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | int r, w; 6 | 7 | public: 8 | A() 9 | { 10 | cout << "A默认构造" << endl; 11 | } 12 | A(int r1, int w1) : r(r1), w(w1) 13 | { 14 | cout << "2个参数构造" << endl; 15 | } 16 | ~A() 17 | { 18 | cout << "A默认析构" << endl; 19 | } 20 | }; 21 | 22 | class B 23 | { 24 | int pr; 25 | A ty; 26 | 27 | public: 28 | B() 29 | { 30 | cout << "B默认构造" << endl; 31 | } 32 | B(int p, int tr, int w) : pr(p), ty(tr, w) 33 | { 34 | cout << "3个参数构造" << endl; 35 | } 36 | ~B() 37 | { 38 | cout << "B默认析构" << endl; 39 | } 40 | }; 41 | int main() 42 | { 43 | B(); 44 | B b(1, 2, 3); 45 | return 0; 46 | } -------------------------------------------------------------------------------- /C++Lesson/.5.2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Date 4 | { 5 | int n; 6 | 7 | public: 8 | Date(int y, int m, int d) 9 | { 10 | SetDate(y, m, d); 11 | } 12 | void SetDate(int y, int m, int d) 13 | { 14 | year = y; 15 | month = m; 16 | day = d; 17 | } 18 | void Print() const 19 | { 20 | cout << year << '/' << month << '/' << day << "; "; 21 | } 22 | 23 | protected: 24 | int year, month, day; 25 | }; 26 | 27 | class DateTime : public Date 28 | { 29 | public: 30 | DateTime(int y, int m, int d, int h, int mi, int s) : Date(y, m, d) //初始化Date 31 | { 32 | SetTime(h, mi, s); 33 | } 34 | void SetTime(int h, int mi, int s) 35 | { 36 | hours = h; 37 | minutes = mi; 38 | seconds = s; 39 | } 40 | void Print() const 41 | { 42 | cout << hours << ":" << minutes << ":" << seconds << "\n"; 43 | } 44 | 45 | private: 46 | int hours, minutes, seconds; 47 | }; 48 | int main() 49 | { 50 | DateTime dt(2018, 7, 16, 12, 30, 0); 51 | DateTime *pdt = &dt; 52 | ((Date)dt).Print(); // 对象类型转换,调用基类成员函数 53 | dt.Print(); 54 | cout << "---------------------" << endl; 55 | ((Date *)pdt)->Print(); // 对象指针类型转换,调用基类成员函数 56 | pdt->Print(); 57 | return 0; 58 | } -------------------------------------------------------------------------------- /C++Lesson/.5.3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Base 4 | { 5 | int n; 6 | 7 | public: 8 | Base() //没有方法内容会报错 9 | { 10 | cout << "基类" << endl; 11 | } 12 | void Print() 13 | { 14 | cout << "基类打印" << endl; 15 | } 16 | }; 17 | 18 | class Derived : public Base 19 | { 20 | public: 21 | Derived() 22 | { 23 | cout << "派生类" << endl; 24 | } 25 | void Print() 26 | { 27 | cout << "派生类打印" << endl; 28 | } 29 | }; 30 | 31 | int main() 32 | { 33 | Base b; 34 | Derived der; 35 | cout << "-----基类指针指向派生类对象-------" << endl; 36 | Base *pBase = &der; //基类指针指向派生类对象 37 | pBase->Print(); //基类 Print 函数 38 | 39 | cout << "-------基类指针指向基类对象-----" << endl; 40 | pBase = &b; //基类指针指向基类对象 41 | pBase->Print(); //基类 Print 函数 42 | 43 | cout << "-------派生类对象转换为基类对象-----" << endl; 44 | ((Base)der).Print(); //指针或对象是什么类型就调用什么类型的函数 45 | // ((Derived)b).Print(); //基类对象无法转换为派生类对象 46 | 47 | cout << "------派生类指针指向派生类对象------" << endl; 48 | Derived *pDer = &der; //派生类指针指向派生类对象 49 | pDer->Print(); //派生类 Print 函数 50 | 51 | cout << "-----派生类指针指向 基类指针转换成派生类指针-------" << endl; 52 | pDer = (Derived *)(pBase); //基类指针转换成派生类指针赋值给派生类指针 53 | pDer->Print(); //派生类 Print 函数 54 | 55 | cout << "-----派生类指针指向 转换成派生类型的基类对象-------" << endl; 56 | pDer = (Derived *)(&b); //派生类指针指向转换成派生类型的基类对象 57 | pDer->Print(); //派生类 Print 函数 58 | 59 | cout << "-----派生类指针转换成基类指针-------" << endl; 60 | pBase = ((Base *)(pDer)); //派生类指针转换成基类指针 61 | pBase->Print(); //基类 Print 函数 62 | 63 | cout << "-----函数调用-------" << endl; 64 | pDer->Base::Print(); //派生类指针调用基类函数 65 | pBase->Base::Print(); //基类指针调用基类函数 66 | ((Derived *)(pBase))->Print(); //基类指针转换派生指针调用派生类函数 67 | pBase->Print(); 68 | pDer->Print(); 69 | return 0; 70 | } -------------------------------------------------------------------------------- /C++Lesson/.5.4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class B 4 | { 5 | int b; 6 | 7 | public: 8 | B(int n) 9 | { 10 | b = n; 11 | cout << b << endl; 12 | } 13 | ~B() 14 | { 15 | cout << "B destroy" << endl; 16 | } 17 | }; 18 | class C 19 | { 20 | int c; 21 | 22 | public: 23 | C(int n, int m) 24 | { 25 | c = n; 26 | cout << c << endl; 27 | } 28 | ~C() 29 | { 30 | cout << "C destroy" << endl; 31 | } 32 | }; 33 | class D : public B, public C 34 | { 35 | int d; 36 | 37 | public: 38 | D(int n1, int n2, int n3, int n4) : C(n3, n4), B(n2) 39 | { 40 | d = n1; 41 | cout << d << endl; 42 | } 43 | ~D() 44 | { 45 | cout << "D destroy" << endl; 46 | } 47 | }; 48 | int main() 49 | { 50 | D objD(2, 4, 6, 8); 51 | return 0; 52 | } -------------------------------------------------------------------------------- /C++Lesson/.6.1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | public: 6 | int i; 7 | virtual void func() 8 | { 9 | cout << "A0" << endl; 10 | } 11 | virtual void func2() 12 | { 13 | cout << "A1" << endl; 14 | } 15 | }; 16 | class B : public A 17 | { 18 | int j; 19 | void func() 20 | { 21 | cout << "B0" << endl; 22 | } 23 | virtual void func3() 24 | { 25 | cout << "B3" << endl; 26 | } 27 | }; 28 | int main() 29 | { 30 | A *a; 31 | B b; 32 | a = &b; 33 | a->func(); 34 | a->func2(); 35 | // a->func3(); 36 | return 0; 37 | } -------------------------------------------------------------------------------- /C++Lesson/.6.2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | int n; 6 | 7 | public: 8 | ~A() 9 | { 10 | cout << "A析构" << endl; 11 | } 12 | virtual void f() = 0; 13 | }; 14 | class D : public A 15 | { 16 | public: 17 | ~D() 18 | { 19 | cout << "D析构" << endl; 20 | } 21 | virtual void f() 22 | { 23 | cout << "D::f" << endl; 24 | } 25 | }; 26 | int main() 27 | { 28 | A *a; 29 | D q; 30 | a = &q; 31 | a->f(); 32 | return 0; 33 | } -------------------------------------------------------------------------------- /C++Lesson/.6.3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | public: 6 | virtual void func() = 0; 7 | }; 8 | class B : public A 9 | { 10 | public: 11 | void func() 12 | { 13 | cout << "A1" << endl; 14 | } 15 | }; 16 | class C : public A 17 | { 18 | public: 19 | void func() 20 | { 21 | cout << "A2" << endl; 22 | } 23 | }; 24 | void fun(A *p) 25 | { 26 | p->func(); 27 | } 28 | int main() 29 | { 30 | B b; 31 | C c; 32 | A *p = &b; 33 | fun(p); 34 | p = &c; 35 | fun(p); 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /C++Lesson/.6.4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | public: 6 | virtual void fun() 7 | { 8 | cout << "A::fun()" << endl; 9 | } 10 | }; 11 | class D : public A 12 | { 13 | public: 14 | virtual void fun() 15 | { 16 | cout << "D::fun()" << endl; 17 | } 18 | }; 19 | void Test() 20 | { 21 | A a; 22 | D d; 23 | a.fun(); 24 | d.fun(); 25 | } 26 | int main() 27 | { 28 | Test(); 29 | // A a; 30 | // D d; 31 | // a.fun(); 32 | // d.fun(); 33 | return 0; 34 | } -------------------------------------------------------------------------------- /C++Lesson/.7.1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | class A 5 | { 6 | int n; 7 | 8 | public: 9 | }; 10 | int main() 11 | { 12 | cout << setw(3) << 25 << oct << 25 << hex << endl; 13 | return 0; 14 | } -------------------------------------------------------------------------------- /C++Lesson/.7.2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | int n; 6 | 7 | public: 8 | }; 9 | int main() 10 | { 11 | 12 | return 0; 13 | } -------------------------------------------------------------------------------- /C++Lesson/.9.1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | template 4 | class f 5 | { 6 | public: 7 | T x, y; 8 | void fun(T a, T b) 9 | { 10 | x = a; 11 | y = b; 12 | } 13 | T max() 14 | { 15 | return (x > y) ? x : y; 16 | } 17 | }; 18 | int main() 19 | { 20 | f a; 21 | f b; 22 | a.fun(1.5, 3.8); 23 | cout << a.x << "," << a.y << "," << a.max() << endl; 24 | b.fun(-1, 4); 25 | cout << b.x << "," << b.y << "," << b.max() << endl; 26 | return 0; 27 | } -------------------------------------------------------------------------------- /C++Lesson/.9.2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | template 4 | class A 5 | { 6 | int x, y, s; 7 | 8 | public: 9 | A(T a, T b) 10 | { 11 | x = a; 12 | y = b; 13 | s = x + y; 14 | } 15 | void show() 16 | { 17 | cout << "x+y=" << s << endl; 18 | } 19 | }; 20 | int main() 21 | { 22 | A add(10, 100); 23 | add.show(); 24 | A add2(1.1, 2); 25 | add2.show(); 26 | return 0; 27 | } -------------------------------------------------------------------------------- /C++Lesson/.9.3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | int n; 6 | 7 | public: 8 | }; 9 | int main() 10 | { 11 | 12 | return 0; 13 | } -------------------------------------------------------------------------------- /C++Lesson/.9.4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | int n; 6 | 7 | public: 8 | }; 9 | int main() 10 | { 11 | 12 | return 0; 13 | } -------------------------------------------------------------------------------- /C++Lesson/1.10.1 func copy 2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | string str; 7 | if (str.empty()) 8 | { 9 | cout << "null," 10 | << "length=" << str.length() << endl; 11 | } 12 | else 13 | { 14 | cout << "Not null" << endl; 15 | } 16 | str = str.append("sadfgflk"); 17 | cout << "str is " << str << ",size=" << str.size() << endl; 18 | const char *p = str.c_str(); 19 | cout << "p=" << p << endl; 20 | cout << "p=" << *p << endl; 21 | cout << "find:" << str.find("ad", 0) << endl; 22 | cout << "find:" << str.find("de", 4) << endl; 23 | string str1 = str.insert(4, "123"); 24 | cout << str1 << endl; 25 | cout << str.substr(5, str.length()) 26 | << endl 27 | << str.length() << endl; 28 | str.append("+love"); 29 | cout << str << endl; 30 | const string str2 = "321"; 31 | str.insert(str.length() - 1, str2); 32 | cout << str << endl; 33 | int num = str.find("f1", 2); 34 | cout << num << endl; 35 | int num2 = str.find('f', 2); 36 | cout << num << endl; 37 | cout << str.empty() << endl; 38 | cout << str.size() << endl; 39 | cout << str.length() << endl; 40 | cout << sizeof(str) << endl; 41 | return 0; 42 | } -------------------------------------------------------------------------------- /C++Lesson/1.2.1 例题 cin cout.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int oneInt1, oneInt2; 7 | char strArray[20]; 8 | string str; 9 | double oneDouble; 10 | char oneChar = 'a'; 11 | cout << "输入两个整型值,一个字符,一个字符串,一个浮点值,"; 12 | cout << "以空格、tab、enter 键分割" << endl; 13 | cin >> oneInt1 >> oneInt2 >> oneChar >> strArray >> oneDouble; 14 | str = strArray; 15 | cout << "输入的数据是:" << endl; //endl 是换行 16 | cout << "字符串:\t\t" << str << endl //\t是制表符 17 | << "两个整型值:\t" << oneInt1 << "和\t" << oneInt2 << endl 18 | << "字符:\t\t" << oneChar << "\n" //"\n"是换行符,与endl相同 19 | << "浮点值:\t\t" << oneDouble << endl; 20 | cout << "1234\ 21 | 56785" << endl; //"\" 用于连接换行的内容 22 | return 0; 23 | } -------------------------------------------------------------------------------- /C++Lesson/1.3.1 static_cast const_cast.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int a = 10; 6 | const int *p = &a; //不能使用常量指针p修改a的值,"&"取地址符,"*"从地址取值 7 | const int ca = 30; //被const修饰 8 | int *q; 9 | cout << "a的内存地址为:\t" << &a << "\t a的值为:\t" << a << endl; 10 | cout << "p指向的地址为:\t" << p << "\t *p的值为:\t" << *p << endl; 11 | q = const_cast(p); //去除p的常量性赋给q,如果写q=p;会报错 12 | *q = 20; //如果写*p=20;是错误的 13 | cout << "a的内存地址为:\t" << &a << "\t a的值为:\t" << a << endl; 14 | cout << "p指向的地址为:\t" << p << "\t *p的值为:\t" << *p << endl; 15 | cout << "q指向的地址为:\t" << q << "\t *q的值为:\t" << *q << endl; 16 | cout << "分界线" << endl; 17 | p = &ca; //ca的值不能修改 18 | q = const_cast(p); //去除p的常量性赋给q,如果写q=p;会报错 19 | *q = 40; //如果写*p=40;是错误的 20 | cout << "ca的内存地址为:\t" << &ca << "\t ca的值为:\t" << ca << endl; 21 | cout << "p指向的地址为:\t" << p << "\t *p的值为:\t" << *p << endl; 22 | cout << "q指向的地址为:\t" << q << "\t *q的值为:\t" << *q << endl; 23 | return 0; 24 | } -------------------------------------------------------------------------------- /C++Lesson/1.5.1 func.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void SwapValue(int a, int b) //形参 4 | { 5 | int tmp; 6 | tmp = a; 7 | a = b; 8 | b = tmp; 9 | cout << "在SwapValue()函数中:\t\ta=" << a << ", b=" << b << endl; 10 | return; 11 | } 12 | void SwapRef(int &a, int &b) //a,b 实参引用地址的值互换 13 | { 14 | int tmp; 15 | tmp = a; 16 | a = b; 17 | b = tmp; 18 | cout << "在SwapRef()函数中:\t\ta=" << a << ", b=" << b << endl; 19 | return; 20 | } 21 | int main() 22 | { 23 | int a = 10; 24 | int b = 20; 25 | cout << "数据交换前:\t\ta=" << a << ", b=" << b << endl 26 | << endl; 27 | SwapValue(a, b); 28 | cout << "SwapValue后:\t\ta=" << a << ", b=" << b << endl 29 | << endl; 30 | a = 10; 31 | b = 20; 32 | SwapRef(a, b); 33 | cout << "SwapRef后:\t\ta=" << a << ", b=" << b << endl 34 | << endl; 35 | return 0; 36 | } -------------------------------------------------------------------------------- /C++Lesson/1.5.2 func.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int oneX = 10; 4 | int oneY = 20; 5 | int a = 11; 6 | int &refValue(int &x) //返回值是引用,可作左值 7 | { 8 | return x; 9 | } 10 | int main() 11 | { 12 | // refValue(oneX) = 30; //返回值是引用,可作左值 13 | cout << "oneX=" << oneX << endl; //输出 oneX=30 14 | // refValue(oneY) = 40; //返回值是引用的函数调用表达式,可作左值使用 15 | cout << "oneY=" << oneY << endl; //输出oneY=40 16 | refValue(a) = 111; 17 | cout << refValue(a) << endl 18 | << a; 19 | return 0; 20 | } -------------------------------------------------------------------------------- /C++Lesson/1.9.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int *A = new int[5]; 4 | int main() 5 | { 6 | for (int i = 0; i < 5; i++) 7 | { 8 | A[i] = i + 1; 9 | cout << A[i] << endl; 10 | } 11 | // delete[] A; 12 | delete A; 13 | for (int i = 0; i < 5; i++) 14 | { 15 | cout << A[i] << endl; 16 | } 17 | return 0; 18 | } -------------------------------------------------------------------------------- /C++Lesson/2.1 myDate.cpp: -------------------------------------------------------------------------------- 1 | class myDate 2 | { 3 | public: 4 | myDate(); //构造函数 5 | myDate(int, int, int); //构造函数 6 | void setDate(int, int, int); //设置日期 7 | void setDate(myDate); //设置日期 8 | myDate getDate(); //获取日期 9 | void setYear(int); //设置年 10 | int getMonth(); //获取月 11 | void printDate() const; //打印日期 12 | 13 | private: 14 | int year, month, day; //成员变量,年月日 15 | }; 16 | //类体外定义成员函数 17 | myDate::myDate() 18 | { 19 | year = 1970, month = 1, day = 1; 20 | } 21 | myDate::myDate(int y, int m, int d) 22 | { 23 | year = y; 24 | month = m; 25 | day = d; 26 | } 27 | void myDate::setDate(int y, int m, int d) 28 | { 29 | year = y; 30 | month = m; 31 | day = d; 32 | return; 33 | } 34 | void myDate::setDate(myDate oneD) 35 | { 36 | year = oneD.year; 37 | month = oneD.month; 38 | day = oneD.day; 39 | return; 40 | } 41 | myDate myDate::getDate() 42 | { 43 | return *this; 44 | } 45 | void myDate::setYear(int y) 46 | { 47 | year = y; 48 | return; 49 | } 50 | int myDate::getMonth() 51 | { 52 | return month; 53 | } 54 | 55 | void myDate::printDate() const 56 | { 57 | cout << year << "/" << month << "/" << day; 58 | return; 59 | } -------------------------------------------------------------------------------- /C++Lesson/2.2 Student.cpp: -------------------------------------------------------------------------------- 1 | class Student 2 | { 3 | public: 4 | void setStudent(string, myDate); //设置学生信息 5 | void setName(string); //设置姓名 6 | string getName(); //获取姓名 7 | void setBirthday(myDate); //设置生日 8 | myDate getBirthday(); //获取生日 9 | void printStudent() const; //打印信息 10 | 11 | private: 12 | string name; //姓名 13 | myDate birthday; //生日 14 | }; 15 | //类体外定义成员函数 16 | void Student::setStudent(string s, myDate d) 17 | { 18 | name = s; 19 | birthday.setDate(d); 20 | return; 21 | } 22 | void Student::setName(string n) 23 | { 24 | name = n; 25 | return; 26 | } 27 | string Student::getName() 28 | { 29 | return name; 30 | } 31 | void Student::setBirthday(myDate d) 32 | { 33 | birthday.setDate(d); 34 | return; 35 | } 36 | myDate Student::getBirthday() 37 | { 38 | return birthday; 39 | } 40 | void Student::printStudent() const 41 | { 42 | cout << "姓名:" << name << "\t生日:"; 43 | birthday.printDate(); //调用类myDate 的成员函数 44 | cout << endl; 45 | } -------------------------------------------------------------------------------- /C++Lesson/2.3 driver.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Lesson/2.3 driver.cpp -------------------------------------------------------------------------------- /C++Lesson/3.1.1 copy func.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Lesson/3.1.1 copy func.cpp -------------------------------------------------------------------------------- /C++Lesson/3.1.4 copy func copy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | class myDate 5 | { 6 | public: 7 | myDate(); //构造函数 8 | myDate(int, int, int); //构造函数 9 | void setDate(int, int, int); //设置日期 10 | void setDate(myDate); //设置日期 11 | myDate getDate(); //获取日期 12 | void setYear(int); //设置年 13 | int getMonth(); //获取月 14 | void printDate() const; //打印日期 15 | ~myDate(); 16 | 17 | private: 18 | int year, month, day; //成员变量,年月日 19 | }; 20 | //类体外定义成员函数 21 | myDate::myDate() 22 | { 23 | year = 1970, month = 1, day = 1; 24 | } 25 | myDate::myDate(int y, int m, int d) 26 | { 27 | year = y; 28 | month = m; 29 | day = d; 30 | } 31 | void myDate::setDate(int y, int m, int d) 32 | { 33 | year = y; 34 | month = m; 35 | day = d; 36 | return; 37 | } 38 | void myDate::setDate(myDate oneD) 39 | { 40 | year = oneD.year; 41 | month = oneD.month; 42 | day = oneD.day; 43 | return; 44 | } 45 | myDate myDate::getDate() 46 | { 47 | return *this; 48 | } 49 | void myDate::setYear(int y) 50 | { 51 | year = y; 52 | return; 53 | } 54 | int myDate::getMonth() 55 | { 56 | return month; 57 | } 58 | 59 | void myDate::printDate() const 60 | { 61 | cout << year << "/" << month << "/" << day; 62 | return; 63 | } 64 | 65 | class Student 66 | { 67 | public: 68 | Student(); //构造函数,无参数 69 | Student(string); //构造函数,带一个参数 70 | void setStudent(string, myDate); //设置学生信息 71 | void setName(string); //设置姓名 72 | string getName(); //获取姓名 73 | void setBirthday(myDate); //设置生日 74 | myDate getBirthday(); //获取生日 75 | void printStudent() const; //打印信息 76 | Student(const Student &s); //声明复制构造函数 77 | ~Student(); //声明析构函数 78 | 79 | private: 80 | string name; //姓名 81 | myDate birthday; //生日 82 | }; 83 | 84 | //定义构造函数 85 | Student::Student() : name("NoName"), birthday(myDate()){}; //添加,不带参数 86 | Student::Student(string n) : name(n), birthday(myDate()){}; //添加,带一个参数 87 | 88 | //类体外定义成员函数 89 | Student::Student(const Student &s) //自定义复制构造函数 90 | { 91 | name = "Copy" + s.name; 92 | birthday = s.birthday; 93 | } 94 | void Student::setStudent(string s, myDate d) 95 | { 96 | name = s; 97 | birthday.setDate(d); 98 | return; 99 | } 100 | void Student::setName(string n) 101 | { 102 | name = n; 103 | return; 104 | } 105 | string Student::getName() 106 | { 107 | return name; 108 | } 109 | void Student::setBirthday(myDate d) 110 | { 111 | birthday.setDate(d); 112 | return; 113 | } 114 | myDate Student::getBirthday() 115 | { 116 | return birthday; 117 | } 118 | void Student::printStudent() const 119 | { 120 | cout << "姓名:" << name << "\t生日:"; 121 | birthday.printDate(); //调用类myDate 的成员函数 122 | cout << endl; 123 | } 124 | //定义析构函数 125 | myDate::~myDate() 126 | { 127 | cout << "myDate 析构函数" << endl; 128 | } 129 | Student::~Student() 130 | { 131 | cout << "Student 析构函数" << endl; 132 | } 133 | int main() 134 | { 135 | Student stud; 136 | stud.setName("444"); //姓名改为444 137 | Student ss[2] = {stud, Student()}; 138 | stud.printStudent(); 139 | stud.setName("111"); 140 | ss[0] = Student(stud); //调用复制构造函数 141 | ss[1] = Student(); 142 | stud.printStudent(); 143 | ss[0].printStudent(); //姓名 Copy111 144 | ss[1].printStudent(); //默认新对象 145 | return 0; 146 | } -------------------------------------------------------------------------------- /C++Lesson/3.13 copy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | public: 6 | A() 7 | { 8 | cout << "default" << endl; 9 | } 10 | A(A &a) 11 | { 12 | cout << "copy" << endl; 13 | } 14 | }; 15 | 16 | class B 17 | { 18 | A a; 19 | }; 20 | 21 | int main() 22 | { 23 | B b1, b2(b1); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /C++Lesson/3.14.31 copy 2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | class Point 5 | { 6 | private: 7 | double x, y; 8 | friend class Line; 9 | 10 | public: 11 | Point(double i = 0, double j = 0) 12 | { 13 | x = i; 14 | y = j; 15 | } 16 | Point(Point &p) 17 | { 18 | x = p.x; 19 | y = p.y; 20 | } 21 | }; 22 | 23 | class Line 24 | { 25 | private: 26 | Point p1, p2; 27 | 28 | public: 29 | Line(Point &xp1, Point &xp2) : p1(xp1), p2(xp2) {} 30 | double GetLength(); 31 | }; 32 | 33 | double Line::GetLength() 34 | { 35 | double dx = p2.x - p1.x; 36 | double dy = p2.y - p1.y; 37 | return sqrt(dx * dx + dy * dy); 38 | } 39 | 40 | int main() 41 | { 42 | Point p1, p2(6, 8); 43 | Line L1(p1, p2); 44 | cout << L1.GetLength() << endl; 45 | return 0; 46 | } -------------------------------------------------------------------------------- /C++Lesson/3.15 friend copy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class myComplex //������ 4 | { 5 | private: 6 | double real, imag; //������ʵ�����鲿 7 | public: 8 | myComplex(); 9 | myComplex(double r, double i); 10 | myComplex addCom(myComplex c); //��Ա����, �����߶������������c��� 11 | void outCom(); //��Ա����, ��������߶�����й����� 12 | }; 13 | myComplex::myComplex(double r, double i) 14 | { 15 | real = r; 16 | imag = i; 17 | } 18 | myComplex::myComplex() 19 | { 20 | real = 0; 21 | imag = 0; 22 | } 23 | myComplex myComplex::addCom(myComplex c) 24 | { 25 | return myComplex(real + c.real, imag + c.imag); 26 | } 27 | void myComplex::outCom() 28 | { 29 | cout << "(" << real << "," << imag << ")"; 30 | } 31 | 32 | int main() 33 | { 34 | myComplex c1(1, 2), c2(3, 4), res; 35 | res = c1.addCom(c2); //���ó�Ա��������ͨ������� 36 | c1.outCom(); 37 | cout << "+"; 38 | c2.outCom(); 39 | cout << "="; 40 | res.outCom(); 41 | cout << endl; 42 | return 0; 43 | } -------------------------------------------------------------------------------- /C++Lesson/3.16 friend copy 2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Lesson/3.16 friend copy 2.cpp -------------------------------------------------------------------------------- /C++Lesson/3.17 friend.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class myComplex //������ 4 | { 5 | private: 6 | double real, imag; //������ʵ�����鲿 7 | public: 8 | myComplex(); 9 | myComplex(double r, double i); 10 | friend class oper; //��Ԫ�� 11 | }; 12 | myComplex::myComplex(double r, double i) 13 | { 14 | real = r; 15 | imag = i; 16 | } 17 | myComplex::myComplex() 18 | { 19 | real = 0; 20 | imag = 0; 21 | } 22 | class oper 23 | { 24 | public: 25 | myComplex addCom(myComplex c1, myComplex c2); //��Ԫ����, ��������������� 26 | void outCom(myComplex c); //��Ԫ����, ��Ҳ����������� 27 | }; 28 | myComplex oper::addCom(myComplex c1, myComplex c2) //���庯�� 29 | { 30 | return myComplex(c1.real + c2.real, c1.imag + c2.imag); 31 | } 32 | void oper::outCom(myComplex c) //���庯�� 33 | { 34 | cout << "(" << c.real << "," << c.imag << ")"; 35 | } 36 | 37 | int main() 38 | { 39 | myComplex c1(1, 2), c2(3, 4), res; 40 | oper o; 41 | res = o.addCom(c1, c2); //���ó�Ա��������ͨ������� 42 | o.outCom(c1); 43 | cout << "+"; 44 | o.outCom(c2); 45 | cout << "="; 46 | o.outCom(res); 47 | cout << endl; 48 | return 0; 49 | } -------------------------------------------------------------------------------- /C++Lesson/3.18 this.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class myComplex 4 | { 5 | public: 6 | double real, imag; 7 | myComplex() : real(0), imag(0) {} 8 | myComplex(double, double); 9 | myComplex AddRealOne(); 10 | myComplex AddImagOne(); 11 | void outCom(); //��Ա����, ��������߶�����й����� 12 | }; 13 | myComplex::myComplex(double real, double imag) 14 | { 15 | this->real = real; 16 | this->imag = imag; 17 | } 18 | void myComplex::outCom() 19 | { 20 | cout << "(" << real << "," << imag << ")"; 21 | } 22 | myComplex myComplex::AddRealOne() 23 | { 24 | this->real++; 25 | return *this; // ���ض����� 26 | } 27 | myComplex myComplex::AddImagOne() 28 | { 29 | this->imag++; 30 | return *this; // ���ض����� 31 | } 32 | 33 | int main() 34 | { 35 | myComplex c1(1, 1), c2, c3; 36 | c1.outCom(); 37 | c2.outCom(); 38 | c3.outCom(); 39 | cout << endl 40 | << "�ֽ���" << endl; 41 | c2 = c1.AddRealOne(); 42 | c1.outCom(); 43 | c3 = c1.AddImagOne(); 44 | c2.outCom(); 45 | c3.outCom(); 46 | cout << endl; 47 | return 0; 48 | } -------------------------------------------------------------------------------- /C++Lesson/3.2 copy func copy 2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Lesson/3.2 copy func copy 2.cpp -------------------------------------------------------------------------------- /C++Lesson/3.2.1 copy func copy 3.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Lesson/3.2.1 copy func copy 3.cpp -------------------------------------------------------------------------------- /C++Lesson/3.2.5 static copy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | class Test 5 | { 6 | public: 7 | static int x; 8 | Test(int i = 10) 9 | { 10 | x = i + x; 11 | } 12 | int Getnum() 13 | { 14 | return Test::x + 7; 15 | } 16 | }; 17 | int Test::x = 83; 18 | int main() 19 | { 20 | Test test; 21 | cout << test.Getnum() << endl; 22 | return 0; 23 | } -------------------------------------------------------------------------------- /C++Lesson/3.3 static.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | static int glos = 100; 5 | void f() 6 | { 7 | int a = 1; 8 | static int fs = 1; 9 | cout << "在f中:a(自动变量)=" << a << " fs(静态)" << fs << " glos(静态)=" << glos << endl; 10 | a += 2; 11 | fs += 2; 12 | glos += 10; 13 | cout << "在f中:a(自动变量)=" << a << " fs(静态)" << fs << " glos(静态)=" << glos << endl 14 | << endl; 15 | } 16 | int main() 17 | { 18 | static int ms = 10; 19 | for (int i = 1; i <= 3; i++) 20 | f(); 21 | cout << "ms=" << ms << endl; 22 | cout << "glos=" << glos << endl; 23 | return 0; 24 | } -------------------------------------------------------------------------------- /C++Lesson/3.9 const.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Lesson/3.9 const.cpp -------------------------------------------------------------------------------- /C++Lesson/4.1 operator.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Lesson/4.1 operator.cpp -------------------------------------------------------------------------------- /C++Lesson/4.2 operator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class myComplex //复数类 4 | { 5 | private: 6 | double real, imag; //复数的实部和虚部 7 | public: 8 | myComplex(); 9 | myComplex(double r, double i); 10 | myComplex addCom(myComplex c); //成员函数, 调用者对象与参数对象c相加 11 | void outCom(); //成员函数, 输出调用者对象的有关数据 12 | myComplex operator-(const myComplex &c); //成员 重载函数 13 | friend myComplex operator+(const myComplex &c1, const myComplex &c2); //友元 重载函数 14 | friend myComplex operator-(const myComplex &c1, const myComplex &c2); //友元 重载函数 15 | friend myComplex operator-(const myComplex &c1, double r); //友元 重载函数 16 | friend myComplex operator-(double r, const myComplex &c1); //友元 重载函数 17 | }; 18 | myComplex::myComplex(double r, double i) 19 | { 20 | real = r; 21 | imag = i; 22 | } 23 | myComplex::myComplex() 24 | { 25 | real = 0; 26 | imag = 0; 27 | } 28 | myComplex myComplex::addCom(myComplex c) 29 | { 30 | return myComplex(real + c.real, imag + c.imag); 31 | } 32 | void myComplex::outCom() 33 | { 34 | cout << "(" << real << "," << imag << ")"; 35 | } 36 | myComplex myComplex::operator-(const myComplex &c) 37 | { 38 | return myComplex(this->real - c.real, this->imag - c.imag); //返回一个临时对象 39 | } 40 | myComplex operator+(const myComplex &c1, const myComplex &c2) //c1+c2 41 | { 42 | return myComplex(c1.real + c2.real, c1.imag + c2.imag); //返回一个临时对象 43 | } 44 | myComplex operator-(const myComplex &c1, const myComplex &c2) //c1-c2 45 | { 46 | return myComplex(c1.real - c2.real, c1.imag - c2.imag); //返回一个临时对象 47 | } 48 | myComplex operator-(const myComplex &c1, double r) //c1-r 49 | { 50 | return myComplex(c1.real - r, c1.imag); //返回一个临时对象 51 | } 52 | myComplex operator-(double r, const myComplex &c1) //r-c1 53 | { 54 | return myComplex(r + c1.real, -c1.imag); //返回一个临时对象 55 | } 56 | 57 | int main() 58 | { 59 | myComplex c1(1, 2), c2(3, 4), res; 60 | c1.outCom(); 61 | cout << "operator+"; 62 | c2.outCom(); 63 | cout << "="; 64 | res = c1 + c2; 65 | res.outCom(); 66 | cout << endl; 67 | c1.outCom(); 68 | cout << "operator-"; 69 | c2.outCom(); 70 | cout << "="; 71 | res = c1 - c2; 72 | res.outCom(); 73 | cout << endl; 74 | res = c1 - c2; 75 | res.outCom(); 76 | res = c1 - 5; 77 | res.outCom(); 78 | res = 5 - c1; 79 | res.outCom(); 80 | return 0; 81 | } -------------------------------------------------------------------------------- /C++Lesson/4.2.1 operator copy 2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class myComplex //复数类 4 | { 5 | private: 6 | double real, imag; //复数的实部和虚部 7 | public: 8 | myComplex(); 9 | myComplex(double r, double i); 10 | ~myComplex() {} //不能有分号 11 | myComplex addCom(myComplex c1); //成员函数, 调用者对象与参数对象c相加 12 | void outCom(); //成员函数, 输出调用者对象的有关数据 13 | void outCom(string s); //成员函数, 输出调用者对象的有关数据 14 | void changeReal(double r); //成员函数 15 | myComplex operator-(const myComplex &c); //成员 重载函数 16 | friend myComplex operator+(const myComplex &c1, const myComplex &c2); //友元 重载函数 c1+c2 17 | friend myComplex operator+(const myComplex &c1, double r); //友元 重载函数 c1+r 18 | friend myComplex operator+(double r, const myComplex &c1); //友元 重载函数 r+c1 19 | friend myComplex operator-(const myComplex &c1, const myComplex &c2); //友元 重载函数 20 | friend myComplex operator-(const myComplex &c1, double r); //友元 重载函数 21 | friend myComplex operator-(double r, const myComplex &c1); //友元 重载函数 22 | myComplex &operator=(const myComplex &c); //成员函数 23 | myComplex &operator=(double); //成员函数 24 | }; 25 | myComplex::myComplex(double r, double i) 26 | { 27 | real = r; 28 | imag = i; 29 | } 30 | myComplex::myComplex() 31 | { 32 | real = 0; 33 | imag = 0; 34 | } 35 | myComplex myComplex::addCom(myComplex c1) 36 | { 37 | return myComplex(this->real + c1.real, this->imag + c1.imag); 38 | } 39 | void myComplex::outCom() 40 | { 41 | cout << "(" << real << "," << imag << ")"; 42 | } 43 | void myComplex::outCom(string s) 44 | { 45 | cout << s << "(" << real << "," << imag << ")" << endl; 46 | } 47 | void myComplex::changeReal(double r) 48 | { 49 | this->real = r; 50 | } 51 | myComplex myComplex::operator-(const myComplex &c) 52 | { 53 | return myComplex(this->real - c.real, this->imag - c.imag); //返回一个临时对象 54 | } 55 | myComplex operator+(const myComplex &c1, const myComplex &c2) //c1+c2 56 | { 57 | return myComplex(c1.real + c2.real, c1.imag + c2.imag); //返回一个临时对象 58 | } 59 | myComplex operator+(const myComplex &c1, double r) //c1+r 60 | { 61 | return myComplex(c1.real + r, c1.imag); //返回一个临时对象 62 | } 63 | myComplex operator+(double r, const myComplex &c1) //r+c2 64 | { 65 | return myComplex(r + c1.real, c1.imag); //返回一个临时对象 66 | } 67 | myComplex operator-(const myComplex &c1, const myComplex &c2) //c1-c2 68 | { 69 | return myComplex(c1.real - c2.real, c1.imag - c2.imag); //返回一个临时对象 70 | } 71 | myComplex operator-(const myComplex &c1, double r) //c1-r 72 | { 73 | return myComplex(c1.real - r, c1.imag); //返回一个临时对象 74 | } 75 | myComplex operator-(double r, const myComplex &c1) //r-c1 76 | { 77 | return myComplex(r + c1.real, -c1.imag); //返回一个临时对象 78 | } 79 | myComplex &myComplex::operator=(const myComplex &c1) 80 | { 81 | this->real = c1.real; 82 | this->imag = c1.imag; 83 | return *this; 84 | } 85 | myComplex &myComplex::operator=(double r) 86 | { 87 | this->real = r; 88 | this->imag = 0; 89 | return *this; 90 | } 91 | 92 | int main() 93 | { 94 | myComplex c1(1, 2), c2(3, 4), res; 95 | c1.outCom("\t\t\tc1"); 96 | c2.outCom("\t\t\tc2"); 97 | res = c1 + c2; 98 | res.outCom("执行 res = c1 + c2 →\tres"); 99 | res = c1.addCom(c2); 100 | res.outCom("执行 res = c1.addCom(c2) →\tres"); 101 | res = c1 + 5; 102 | res.outCom("执行 res = c1 + 5 →\tres"); 103 | res = 5 + c1; 104 | res.outCom("执行 res = 5 + c1 →\tres"); 105 | res = c1; 106 | c1.outCom("\t\t\tc1"); 107 | res.outCom("执行 res = c1 →\tres"); 108 | c1.changeReal(-3); 109 | c1.outCom("执行 changeReal(-3) →\tc1"); 110 | res.outCom("\t\t\tres"); 111 | res = c1; 112 | res.outCom("res = c1 →\tres"); 113 | res = 7; 114 | res.outCom("res = 7 →\tres"); 115 | res = 7 + 8; 116 | res.outCom("res = 7 + 8; →\tres"); 117 | res = c1 = c2; 118 | c1.outCom("\t\t\tc1"); 119 | c2.outCom("\t\t\tc2"); 120 | res.outCom("res = c1 = c2 →\tres"); 121 | 122 | return 0; 123 | } -------------------------------------------------------------------------------- /C++Lesson/4.4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class pointer 4 | { 5 | public: 6 | int a; 7 | int *p; 8 | pointer() 9 | { 10 | a = 100; 11 | p = new int(10); //初始化内存 12 | *p = 11; //向内存赋值 13 | } 14 | pointer(const pointer &temp) //复制构造函数 15 | { 16 | if (this != &temp) 17 | { 18 | a = temp.a; // a 是局部变量,内存跟随对象 19 | p = temp.p; // p 是指针变量,内存固定,需要深度复制 20 | cout << "*p=" << *p << ",p=" << p << endl; 21 | // delete p; //删除指针,新指针的地址还是原来的地址,不能删除 22 | p = new int(*temp.p + 1); //把指针 temp.p 的值赋值给 指针 p 23 | *p = *temp.p + 10; //加10更好分辨 *p 24 | cout << "*p=" << *p << ",p=" << p << endl; 25 | } 26 | } 27 | ~pointer() //析构函数 28 | { 29 | if (p != NULL) 30 | delete p; 31 | } 32 | pointer operator=(pointer &a) //成员函数 重载赋值运算符 33 | { 34 | if (this == &a) 35 | return *this; 36 | else 37 | { 38 | delete p; 39 | this->p = new int(*a.p); 40 | cout << "*p3=" << *p << ",p3=" << p << endl; 41 | return *this; 42 | } 43 | } 44 | }; 45 | int main() 46 | { 47 | pointer p1; 48 | pointer p2(p1); 49 | pointer p3; 50 | p3 = p1; 51 | p1.a = 123; 52 | *p1.p = 234; 53 | cout << p1.a << ",p1=" << *p1.p << endl; 54 | cout << p2.a << ",p2=" << *p2.p << endl; 55 | cout << p3.a << ",p3=" << *p3.p << endl; 56 | return 0; 57 | } -------------------------------------------------------------------------------- /C++Lesson/4.5 stream.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | class myComplex 6 | { 7 | private: 8 | double real, imag; 9 | 10 | public: 11 | myComplex() : real(0), imag(0) {} 12 | myComplex(double r, double i) : real(r), imag(i) {} 13 | friend ostream &operator<<(ostream &os, const myComplex &c); //友元,插入 14 | friend istream &operator>>(istream &is, myComplex &c); //友元,提取 15 | }; 16 | ostream &operator<<(ostream &os, const myComplex &c) 17 | { 18 | if (c.imag >= 0) 19 | { 20 | os << c.real << "+" << c.imag << "i"; //以 a+bi 的形式输入 21 | } 22 | else 23 | { 24 | os << c.real << "-" << -c.imag << "i"; 25 | } 26 | return os; 27 | } 28 | istream &operator>>(istream &is, myComplex &c) 29 | { 30 | string s; 31 | is >> s; //将a+bi 作为字符串读入,a+bi中间不能有空格 32 | int pos = s.find("+", 0); //查找虚部 33 | if (pos == -1) 34 | pos = s.find("-", 1); //虚部为负数时 35 | string sReal = s.substr(0, pos); //分离出代表实部的字符串 36 | c.real = atof(sReal.c_str()); //atof() 能将参数内容转换成浮点数 37 | sReal = s.substr(pos, s.length() - pos - 1); //分离出代表虚部的字符串 38 | c.imag = atof(sReal.c_str()); 39 | return is; 40 | } 41 | int main() 42 | { 43 | myComplex c, c1; 44 | int n; 45 | cout << "请输入两个复数([-]a±bi)和一个整数, 以空格分隔" << endl; 46 | cin >> c >> c1 >> n; 47 | cout << c << "," << n << "," << c1; 48 | return 0; 49 | } -------------------------------------------------------------------------------- /C++Lesson/4.6 stream copy.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Lesson/4.6 stream copy.cpp -------------------------------------------------------------------------------- /C++Lesson/4.7 operator type.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Lesson/4.7 operator type.cpp -------------------------------------------------------------------------------- /C++Lesson/4.8 auto multi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Demo 4 | { 5 | private: 6 | int n; 7 | 8 | public: 9 | Demo(int i = 0) : n(i) {} 10 | Demo &operator++(); //用于前置 11 | Demo operator++(int); //用于后置 12 | operator int() { return n; } 13 | friend Demo &operator--(Demo &); 14 | friend Demo operator--(Demo &, int); 15 | }; 16 | Demo &Demo::operator++() //前置++ 17 | { 18 | n++; 19 | return *this; 20 | } 21 | Demo Demo::operator++(int k) //后置++ 22 | { 23 | Demo tmp(*this); //记录修改前的对象 24 | n++; 25 | return tmp; //返回修改前对象 26 | } 27 | Demo &operator--(Demo &d) //前置-- 28 | { 29 | d.n--; 30 | return d; 31 | } 32 | Demo operator--(Demo &d, int) //后置-- 33 | { 34 | Demo tmp(d); 35 | d.n--; 36 | return tmp; 37 | } 38 | int main() 39 | { 40 | Demo d(10); 41 | cout << (d++) << ","; // d.operator++(0) 42 | cout << d << ","; 43 | cout << (++d) << ","; // d.operator++() 44 | cout << d << ","; 45 | cout << (d--) << ","; // d.operator--(d,0) 46 | cout << d << ","; 47 | cout << (--d) << ","; // d.operator--(d) 48 | cout << d << ","; 49 | return 0; 50 | } -------------------------------------------------------------------------------- /C++Lesson/4.9 auto multi copy.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Lesson/4.9 auto multi copy.cpp -------------------------------------------------------------------------------- /C++Lesson/5.11 multi inherit copy.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Lesson/5.11 multi inherit copy.cpp -------------------------------------------------------------------------------- /C++Lesson/5.14 public.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Lesson/5.14 public.cpp -------------------------------------------------------------------------------- /C++Lesson/5.15.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class BaseClass //���� 4 | { 5 | protected: 6 | int v1, v2; 7 | 8 | public: 9 | BaseClass(); 10 | BaseClass(int, int); 11 | ~BaseClass(); 12 | }; 13 | BaseClass::BaseClass() 14 | { 15 | cout << "BaseClass No parameter" << endl; 16 | } 17 | BaseClass::BaseClass(int m, int n) 18 | { 19 | v1 = m; 20 | v2 = n; 21 | cout << "BaseClass Two parameter" << endl; 22 | } 23 | BaseClass::~BaseClass() 24 | { 25 | cout << "BaseClass Destroy" << endl; 26 | } 27 | 28 | class DerivedClass : public BaseClass 29 | { 30 | int v3; 31 | 32 | public: 33 | DerivedClass(); 34 | DerivedClass(int); 35 | DerivedClass(int, int, int); 36 | ~DerivedClass(); 37 | }; 38 | DerivedClass::DerivedClass() 39 | { 40 | cout << "DerivedClass No parameter" << endl; 41 | } 42 | DerivedClass::DerivedClass(int k) : v3(k) 43 | { 44 | cout << "DerivedClass One parameter" << endl; 45 | } 46 | DerivedClass::DerivedClass(int m, int n, int k) : BaseClass(m, n), v3(k) 47 | { 48 | cout << "DerivedClass Three parameter" << endl; 49 | } 50 | DerivedClass::~DerivedClass() 51 | { 52 | cout << "DerivedClass Destroy" << endl; 53 | } 54 | 55 | int main() 56 | { 57 | cout << "create no parameter object" << endl; 58 | BaseClass baseCla; 59 | DerivedClass derivedCla; 60 | cout << "create with parameter object" << endl; 61 | BaseClass baseCla1(10, 20); 62 | DerivedClass derivedCla1(30); 63 | return 0; 64 | } -------------------------------------------------------------------------------- /C++Lesson/5.16.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Lesson/5.16.cpp -------------------------------------------------------------------------------- /C++Lesson/5.17.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Lesson/5.17.cpp -------------------------------------------------------------------------------- /C++Lesson/5.18.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Base 4 | { 5 | public: 6 | Base() {} 7 | Base(Base &c) 8 | { 9 | cout << "Base 复制构造函数" << endl; 10 | } 11 | Base operator=(const Base &b) 12 | { 13 | cout << "Base::operator=" << endl; 14 | return *this; 15 | } 16 | }; 17 | class Derived : public Base 18 | { 19 | public: 20 | Derived() 21 | { 22 | cout << "Derived::构造函数" << endl; 23 | } 24 | }; 25 | 26 | int main() 27 | { 28 | Derived d1, d2; 29 | Derived d3(d1); // d3 初始化过程中会调用类 Base 的复制构造函数 30 | d2 = d1; // 会调用类 Base 的重载运算符“=”运算符 31 | return 0; 32 | } -------------------------------------------------------------------------------- /C++Lesson/5.19.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Base //基类 4 | { 5 | protected: 6 | int v1, v2; 7 | 8 | public: 9 | Base(); 10 | Base(int, int); 11 | ~Base(); 12 | void SetValue(int, int); 13 | void PrintValue(); 14 | }; 15 | Base::Base() : v1(0), v2(0) //无参数时初始化成员变量 16 | { 17 | cout << "Base 无参构造函数" << endl; 18 | } 19 | Base::Base(int m, int n) : v1(m), v2(n) 20 | { 21 | v1 = m; 22 | v2 = n; 23 | cout << "Base 带2个参数构造函数, " << v1 << ", " << v2 << endl; 24 | } 25 | Base::~Base() 26 | { 27 | cout << "Base 析构函数" << endl; 28 | } 29 | void Base::SetValue(int m, int n) 30 | { 31 | v1 = m; 32 | v2 = n; 33 | } 34 | void Base::PrintValue() 35 | { 36 | cout << "v1=" << v1 << "\tv2=" << v2 << endl; 37 | } 38 | 39 | class Base2 //基类 40 | { 41 | protected: 42 | int v1, v4; 43 | 44 | public: 45 | Base2(); 46 | Base2(int, int); 47 | ~Base2(); 48 | void SetValue(int, int); 49 | void PrintValue(); 50 | }; 51 | Base2::Base2() : v1(0), v4(0) //无参数时初始化成员变量 52 | { 53 | cout << "Base2 无参构造函数" << endl; 54 | } 55 | Base2::Base2(int m, int n) : v1(m), v4(n) 56 | { 57 | v1 = m; 58 | v4 = n; 59 | cout << "Base2 带2个参数构造函数, " << v1 << ", " << v4 << endl; 60 | } 61 | Base2::~Base2() 62 | { 63 | cout << "Base2 析构函数" << endl; 64 | } 65 | void Base2::SetValue(int m, int n) 66 | { 67 | v1 = m; 68 | v4 = n; 69 | } 70 | void Base2::PrintValue() 71 | { 72 | cout << "v1=" << v1 << "\tv4=" << v4 << endl; 73 | } 74 | 75 | class Derived : public Base, public Base2 76 | { 77 | public: 78 | int v3; 79 | 80 | public: 81 | Derived(); 82 | Derived(int); 83 | Derived(int, int, int, int); 84 | ~Derived(); 85 | void SetValue(int m, int n, int k, int h) 86 | { 87 | Base::SetValue(m, n); 88 | Base2::SetValue(2 * m, h); 89 | v3 = k; 90 | } 91 | void SetValue(int m, int n, int k) 92 | { 93 | Base::SetValue(m, n); 94 | Base2::SetValue(2 * m, 2 * n); 95 | v3 = k; 96 | } 97 | void SetValue(int m, int n) 98 | { 99 | Base::SetValue(m, n); 100 | Base2::SetValue(-1, -1); 101 | v3 = -1; 102 | } 103 | void PrintValue(); 104 | }; 105 | Derived::Derived() : Base(0, 0), Base2(0, 0), v3(0) //此处默认参数决定基类调用的构造函数参数 106 | { 107 | cout << "Derived 无参构造函数" << endl; 108 | } 109 | Derived::Derived(int k) 110 | { 111 | v3 = k; 112 | cout << "带1个参数构造函数" << endl; 113 | } 114 | Derived::Derived(int m, int n, int k, int t) : Base(m, n), Base2(m, t), v3(k) 115 | { 116 | cout << "带4个参数构造函数" << endl; 117 | } 118 | Derived::~Derived() 119 | { 120 | cout << "Derived 析构函数" << endl; 121 | } 122 | void Derived::PrintValue() 123 | { 124 | Base::PrintValue(); 125 | cout << "\tv3=" << v3 << endl; 126 | Base2::PrintValue(); 127 | cout << endl; 128 | } 129 | 130 | int main() 131 | { 132 | cout << "带4个参数对象的创建" << endl; 133 | Derived derived(1000, 2000, 3000, 4000); 134 | derived.PrintValue(); 135 | cout << endl 136 | << "不带参数对象的创建" << endl; 137 | Derived derived2; 138 | derived2.PrintValue(); 139 | cout << endl 140 | << "带1个参数对象的创建" << endl; 141 | Derived derived3(111); 142 | derived3.PrintValue(); 143 | return 0; 144 | } -------------------------------------------------------------------------------- /C++Lesson/5.23.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class CBase 4 | { 5 | protected: 6 | int n; 7 | 8 | public: 9 | CBase(int i) : n(i) {} 10 | void Print() { cout << "CBase:n=" << n << endl; } 11 | }; 12 | class CDerived : public CBase 13 | { 14 | public: 15 | int v; 16 | CDerived(int i) : CBase(i), v(2 * i) {} 17 | void Func(){}; 18 | void Print() 19 | { 20 | cout << "CDerived:n=" << n << endl; 21 | cout << "CDerived:v=" << v << endl; 22 | } 23 | }; 24 | int main() 25 | { 26 | CDerived objDerived(3); 27 | CBase objBase(5); 28 | CBase *pBase = &objDerived; // 使得基类指针指向派生类对象 29 | //pBase->Func(); //错, CBase类没有Func()成员函数 30 | //pBase->v = 5; //错 CBase类没有v成员变量 31 | pBase->Print(); 32 | cout << "1)------------" << endl; 33 | //CDerived * pDerived = & objBase; //错,不能将基类指针赋值给派生类指针 34 | CDerived *pDerived = static_cast(&objBase); 35 | pDerived->Print(); //慎用,可能出现不可预期的错误 36 | cout << "2)------------" << endl; 37 | objDerived.Print(); 38 | cout << "3)------------" << endl; 39 | pDerived->v = 128; //往别人的空间里写入数据,会有问题 40 | objDerived.Print(); 41 | return 0; 42 | } -------------------------------------------------------------------------------- /C++Lesson/5.4 static son.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Base 4 | { 5 | private: 6 | float x; 7 | 8 | public: 9 | static int staV; 10 | Base() 11 | { 12 | staV++; 13 | } 14 | }; 15 | int Base::staV = 0; 16 | class Derived : public Base 17 | { 18 | private: 19 | float y; 20 | 21 | public: 22 | Derived() 23 | { 24 | staV++; 25 | } 26 | }; 27 | int main() 28 | { 29 | Base a; 30 | cout << a.staV << endl; 31 | Derived d; 32 | cout << d.staV << endl; 33 | return 0; 34 | } -------------------------------------------------------------------------------- /C++Lesson/5.5 son.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Lesson/5.5 son.cpp -------------------------------------------------------------------------------- /C++Lesson/5.6 son type.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Lesson/5.6 son type.cpp -------------------------------------------------------------------------------- /C++Lesson/5.7 type copy.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Lesson/5.7 type copy.cpp -------------------------------------------------------------------------------- /C++Lesson/7.1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int x, y; 6 | cin >> x >> y; 7 | freopen("test.txt", "w", stdout); 8 | if (y == 0) 9 | cerr << "error." << endl; 10 | else 11 | cout << x << "/" << y << "=" << x / y << endl; 12 | return 0; 13 | } -------------------------------------------------------------------------------- /C++Lesson/7.10.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | char c = 'a', str[80] = "1234567890abcdefghijklmn"; 7 | int x = 65; 8 | cout << "cout.put('a'):"; 9 | cout.put('a'); 10 | cout << "\ncout.put(c+25):"; 11 | cout.put(c + 25); //字母转换成整数再相加 12 | cout << "\ncout.put(x):"; 13 | cout.put(x); 14 | cout << "\ncout.put(str,20):"; 15 | cout.write(str, 20); //将str的前20个字节输入到流中 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C++Lesson/7.11.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int n = 0; 7 | char ch; 8 | while (ch = cin.get() != EOF) //遇到结束符才推出 9 | { 10 | cout.put(ch); 11 | n++; 12 | } 13 | cout << "输入字符统计:" << n << endl; 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C++Lesson/7.12.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | char buf[10]; 7 | int i = 0; 8 | while (cin.getline(buf, 10)) //输入超过九个就会出错 9 | { 10 | cout << ++i << ":" << buf << endl; 11 | cout << "last:" << buf << endl; 12 | } 13 | return 0; 14 | } -------------------------------------------------------------------------------- /C++Lesson/7.13.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | char str[30]; 7 | while (!+cin.eof()) //当输入流没有结束时继续循环 8 | { 9 | cin.ignore(10, ':'); //在cin流中跳过':'之前的全部字符 10 | if (!cin.eof()) //输入流没有结束 11 | { 12 | cin >> str; //输入电话号码 13 | cout << str << endl; 14 | } 15 | } 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C++Lesson/7.14.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | string Months[13] = {"", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; //西文格式的月份 5 | int main() 6 | { 7 | char ch; 8 | int year, month, day; 9 | while ((ch = cin.peek()) != EOF) //取输入流的第一个字符查看 10 | { 11 | if (ch > +'A' && ch < 'Z') //处理西文格式 12 | { 13 | string sMonth; 14 | cin >> sMonth >> day >> year; //接收:月、日、年 15 | // 查找月份完成转换 16 | for (month = 0; month < 12 && sMonth != Months[month]; ++month) 17 | ; 18 | } 19 | else 20 | { 21 | cin >> year; 22 | cin.ignore() >> month; 23 | cin.ignore() >> day; 24 | // 以上三条语句等价于 cin>>year>>ch>>month>>ch>>day; 25 | } 26 | cin.ignore(); 27 | cout << setfill('0') << setw(2) << month; 28 | cout << "-" << setw(2) << day << "-" << setw(4) << year << endl; 29 | } 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /C++Lesson/7.2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int x, count, sum = 0; 6 | freopen("input.dat", "r", stdin); //标准输入定向到文件 7 | for (count = 0; count < 10; count++) 8 | { 9 | cin >> x; 10 | sum += x; 11 | } 12 | cout << "前" << count << "个整数的平均值 = " << 1.0 * sum / count << endl; 13 | return 0; 14 | } -------------------------------------------------------------------------------- /C++Lesson/7.3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int x, count, sum = 0; 6 | freopen("input.dat", "r", stdin); //标准输入定向到文件 7 | for (count = 0; count < 10; count++) 8 | { 9 | cin >> x; 10 | if (cin.eof()) 11 | { 12 | cout << cin.eof() << "结束" << endl; 13 | break; 14 | } 15 | else 16 | { 17 | cout << x << "," << sum << endl; 18 | sum += x; 19 | } 20 | } 21 | // 遇到输出中文失败,程序不输出结果,代码编码问题,GB2312改为 UTF-8即可。 22 | cout << "前" << count << "个整数的平均值 = " << 1.0 * sum / count << endl; 23 | return 0; 24 | } -------------------------------------------------------------------------------- /C++Lesson/7.4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | char ch; 6 | int x, count = 0, sum = 0; 7 | cout << "请输入整数 Ctrl+Z 退出" << endl; 8 | do 9 | { 10 | while (cin >> x) 11 | { 12 | sum += x; 13 | count++; 14 | } 15 | cout << "确认退出请输入 Q"; 16 | cin.clear(); 17 | cin >> ch; 18 | } while (toupper(ch) != 'Q'); 19 | cout << "sum=" << sum << ",count=" << count << endl; 20 | return 0; 21 | } -------------------------------------------------------------------------------- /C++Lesson/7.5.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int n = 65535, m = 20; 7 | //分别输出一个整数的十进制 十六进制 八进制 8 | cout << "十进制:" << n << "=" << hex << n << "=" << oct << n << endl; 9 | //使用 setbase 分别输出一个整数的十进制、十六进制和八进制 10 | cout << "" << setbase(10) << m << "=" << setbase(16) << m << "=" << setbase(8) << m << endl; 11 | //使用 showbase 和 setbase 分别输出一个整数 十进制、十六进制、八进制 12 | cout << showbase; 13 | cout << setbase(10) << m << "=" << setbase(16) << m << "=" << setbase(8) << m << endl; 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C++Lesson/7.6.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | double x = 1234567.89, y = 1.23456789; 7 | //无格式控制 8 | cout << "无格式控制:\t\t x=(" << x << "),y=(" << y << ")\n"; 9 | 10 | //保留5位有效数字 11 | cout << "保留5位有效数字:\t\t x=(" << setprecision(5) << x << "),y=(" << y << ")\n"; 12 | 13 | //保留小数点后5位 14 | cout << "保留小数点后5位:\t\t x=(" << fixed << setprecision(5) << x << "),y=(" << y << ")\n"; 15 | 16 | //科学计数法,保留小数点后5位 17 | cout << "科学计数法,保留小数点后5位:\t\t x=(" << scientific << setprecision(5) << x << "),y=(" << y << ")\n"; 18 | 19 | //非负数显示正号,输出宽度为12字符,宽度不足时用‘*’填补 20 | cout << "非负数显示正号:\t\t " << showpos << fixed << setw(12) << setfill('*') << y << endl; 21 | 22 | //非负数不显示正号,输出宽度为12字符,宽度不足时右边用填充字符填充 23 | cout << "不显示正号,右边用填充字符填充:\t\t " << noshowpos << left << setw(12) << y << endl; 24 | 25 | //输出宽度为12字符,宽度不足时左边用填充字符填充 26 | cout << "左边用填充字符填充:\t\t " << showpos << right << setw(12) << y << endl; 27 | 28 | //宽度不足时,负号和数值分列左右,中间用填充字符填充 29 | cout << "中间用填充字符填充:\t\t " << showpos << internal << setw(12) << -y << endl; 30 | } -------------------------------------------------------------------------------- /C++Lesson/7.7.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | string s1, s2; 7 | cin >> setw(5) >> s1 >> setw(3) >> s2; 8 | cout << "s1=" << s1 << ",s2=" << s2 << endl; 9 | return 0; 10 | } -------------------------------------------------------------------------------- /C++Lesson/7.8.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | double x = 12.34; 7 | cout << "1)" << setiosflags(ios::scientific | ios::showpos) << x << endl; 8 | cout << "2)" << resetiosflags(ios::scientific | ios::showpos) << setiosflags(ios::showbase) << x << endl; 9 | cout << "3)" << resetiosflags(ios::fixed) 10 | << setiosflags(ios::scientific | ios::showpos) << x << endl; 11 | cout << "4)" << resetiosflags(ios::showpos) << x << endl; 12 | cout << "5)" << resetiosflags(ios::scientific) << setiosflags(ios::fixed) << x << endl; 13 | return 0; 14 | } -------------------------------------------------------------------------------- /C++Lesson/7.9.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | double values[] = {1.23, 20.3456, 300.4567, 4000.56789, 50000.1234567}; 7 | cout.fill('*'); //填充* 8 | for (int i = 0; i < sizeof(values) / sizeof(double); i++) 9 | { 10 | cout << "values[" << i << "]=("; 11 | cout.width(10); //设置宽度 12 | cout << values[i] << ")" << endl; 13 | } 14 | cout.fill(' '); //填充空格 15 | for (int i = 0; i < sizeof(values) / sizeof(double); i++) 16 | { 17 | cout << "values[" << i << "]=("; 18 | cout.width(10); //设置宽度 19 | cout.precision(i + 3); //设置保留有效数字 20 | cout << values[i] << ")" << endl; 21 | } 22 | return 0; 23 | } -------------------------------------------------------------------------------- /C++Lesson/8.1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | 7 | return 0; 8 | } -------------------------------------------------------------------------------- /C++Lesson/8.2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | 7 | return 0; 8 | } -------------------------------------------------------------------------------- /C++Lesson/9.1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | template 4 | T abs(T x) 5 | { 6 | return x < 0 ? -x : x; 7 | } 8 | int main() 9 | { 10 | int n = -5; 11 | int m = 10; 12 | double d = -5; 13 | float f = 3.2; 14 | cout << n << "的绝对值:" << abs(n) << endl; 15 | cout << m << "的绝对值:" << abs(m) << endl; 16 | cout << d << "的绝对值:" << abs(d) << endl; 17 | cout << f << "的绝对值:" << abs(f) << endl; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /C++Lesson/9.6.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | template 4 | class Pair 5 | { 6 | public: 7 | T1 first; 8 | T2 second; 9 | Pair(T1 k, T2 v) : first(k), second(v) {} 10 | bool operator<(const Pair &p) const; //成员函数 11 | }; 12 | template 13 | bool Pair::operator<(const Pair &p) const //成员函数 14 | { 15 | return first < p.first; 16 | } 17 | int main() 18 | { 19 | Pair student1("Tom", 19); 20 | // 21 | Pair student2("Jim", 21); 22 | // 23 | Pair dic("word", "danci"); 24 | Pair coordinate(10, 20); 25 | cout << "学生:" << student1.first << " " << student1.second << endl; 26 | cout << "学生:" << student2.first << " " << student2.second << endl; 27 | cout << "坐标:" << coordinate.first << " " << coordinate.second << endl; 28 | cout << "学生:" << dic.first << " " << dic.second << endl; 29 | bool a = student1 < student2; 30 | if (a == 0) 31 | cout << student1.first << "位于" << student2.first << "之后" << endl; 32 | else 33 | cout << student1.first << "位于" << student2.first << "之前" << endl; 34 | return 0; 35 | } -------------------------------------------------------------------------------- /C++Lesson/input.dat: -------------------------------------------------------------------------------- 1 | 5 8 10 15 20 25 30 40 50 60 70 80 90 100 110 120 2 | -------------------------------------------------------------------------------- /C++Lesson/input2.dat: -------------------------------------------------------------------------------- 1 | 5 8 10 15 20 2 | -------------------------------------------------------------------------------- /C++Lesson/main copy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int n = 0; 6 | void fun(double n); 7 | // cout << fun(1.1); 8 | fun(10.23); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /C++Lesson/main type.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | cout << "type: \t\t" 9 | << "************size**************" << endl; 10 | cout << "bool: \t\t" 11 | << "所占字节数:" << sizeof(bool); 12 | cout << "\t最大值:" << (numeric_limits::max)(); 13 | cout << "\t\t最小值:" << (numeric_limits::min)() << endl; 14 | cout << "char: \t\t" 15 | << "所占字节数:" << sizeof(char); 16 | cout << "\t最大值:" << (numeric_limits::max)(); 17 | cout << "\t\t最小值:" << endl; 18 | cout << "signed char: \t" 19 | << "所占字节数:" << sizeof(signed char); 20 | cout << "\t最大值:" << (numeric_limits::max)(); 21 | cout << "\t\t最小值:" << endl; 22 | cout << "unsigned char: \t" 23 | << "所占字节数:" << sizeof(unsigned char); 24 | cout << "\t最大值:"; 25 | cout << "\t\t最小值:" << (numeric_limits::min)() << endl; 26 | cout << "wchar_t: \t" 27 | << "所占字节数:" << sizeof(wchar_t); 28 | cout << "\t最大值:" << (numeric_limits::max)(); 29 | cout << "\t\t最小值:" << (numeric_limits::min)() << endl; 30 | cout << "short: \t\t" 31 | << "所占字节数:" << sizeof(short); 32 | cout << "\t最大值:" << (numeric_limits::max)(); 33 | cout << "\t\t最小值:" << (numeric_limits::min)() << endl; 34 | cout << "int: \t\t" 35 | << "所占字节数:" << sizeof(int); 36 | cout << "\t最大值:" << (numeric_limits::max)(); 37 | cout << "\t最小值:" << (numeric_limits::min)() << endl; 38 | cout << "unsigned: \t" 39 | << "所占字节数:" << sizeof(unsigned); 40 | cout << "\t最大值:" << (numeric_limits::max)(); 41 | cout << "\t最小值:" << (numeric_limits::min)() << endl; 42 | cout << "long: \t\t" 43 | << "所占字节数:" << sizeof(long); 44 | cout << "\t最大值:" << (numeric_limits::max)(); 45 | cout << "\t最小值:" << (numeric_limits::min)() << endl; 46 | cout << "unsigned long: \t" 47 | << "所占字节数:" << sizeof(unsigned long); 48 | cout << "\t最大值:" << (numeric_limits::max)(); 49 | cout << "\t最小值:" << (numeric_limits::min)() << endl; 50 | cout << "double: \t" 51 | << "所占字节数:" << sizeof(double); 52 | cout << "\t最大值:" << (numeric_limits::max)(); 53 | cout << "\t最小值:" << (numeric_limits::min)() << endl; 54 | cout << "long double: \t" 55 | << "所占字节数:" << sizeof(long double); 56 | cout << "\t最大值:" << (numeric_limits::max)(); 57 | cout << "\t最小值:" << (numeric_limits::min)() << endl; 58 | cout << "float: \t\t" 59 | << "所占字节数:" << sizeof(float); 60 | cout << "\t最大值:" << (numeric_limits::max)(); 61 | cout << "\t最小值:" << (numeric_limits::min)() << endl; 62 | cout << "size_t: \t" 63 | << "所占字节数:" << sizeof(size_t); 64 | cout << "\t最大值:" << (numeric_limits::max)(); 65 | cout << "\t最小值:" << (numeric_limits::min)() << endl; 66 | cout << "string: \t" 67 | << "所占字节数:" << sizeof(string) << endl; 68 | // << "\t最大值:" << (numeric_limits::max)() << "\t最小值:" << (numeric_limits::min)() << endl; 69 | cout << "type: \t\t" 70 | << "************size**************" << endl; 71 | return 0; 72 | } -------------------------------------------------------------------------------- /C++Lesson/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | cout << "Hello Vscode\n" 6 | << endl; 7 | return 0; 8 | } -------------------------------------------------------------------------------- /C++Lesson/test.txt: -------------------------------------------------------------------------------- 1 | 9/9=1 2 | -------------------------------------------------------------------------------- /C++Practice/1.test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | // #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | int main() 8 | { 9 | // int a[] = {1, 2, 3, 4}; 10 | // int len = sizeof(a) / sizeof(a[0]); //得到数组容量 11 | // for (int index = 0; index < len; ++index) 12 | // { 13 | // if (a[index] == 3) 14 | // { 15 | // cout << index << endl; 16 | // return index; 17 | // } 18 | // } 19 | 20 | // int a[2][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}}; 21 | // for (int row = 0; row < 2; row++) 22 | // { 23 | // for (int col = 0; col < 4; col++) 24 | // { 25 | // cout << a[row][col] << " "; 26 | // } 27 | // cout << endl; 28 | // } 29 | 30 | // vector vec = {1, 2, 3, 4}; 31 | // // 先查看大小,自动扩容 32 | // for (int i = 0; i < vec.size(); i++) 33 | // { 34 | // cout << vec[i] << " " << vec.capacity() << " " << vec.size() << endl; 35 | // } 36 | // cout << "尾部插入" << endl; 37 | // vec.push_back(5); // 尾部插入 38 | // for (int i = 0; i < vec.size(); i++) 39 | // { 40 | // cout << vec[i] << " " << vec.capacity() << " " << vec.size() << endl; 41 | // } 42 | // cout << "尾部删除" << endl; 43 | // vec.pop_back(); // 从尾部删除 44 | // for (int i = 0; i < vec.size(); i++) 45 | // { 46 | // cout << vec[i] << " " << vec.capacity() << " " << vec.size() << endl; 47 | // } 48 | // cout << "指定位置插入" << endl; 49 | // vec.insert(vec.end() - 1, 6); // 指定位置插入 50 | // for (int i = 0; i < vec.size(); i++) 51 | // { 52 | // cout << vec[i] << " " << vec.capacity() << " " << vec.size() << endl; 53 | // } 54 | // cout << "指定位置删除" << endl; 55 | // vec.erase(vec.end() - 2); // 指定位置删除 56 | // for (unsigned int i = 0; i < vec.size(); i++) 57 | // { 58 | // cout << vec[i] << " " << vec.capacity() << " " << vec.size() << endl; 59 | // } 60 | // cout << endl; 61 | 62 | int i = 9; 63 | int a = 1; 64 | int *p = &i; 65 | std::cout << **(&p); 66 | std::cout << "Hello World!\n"; 67 | } -------------------------------------------------------------------------------- /C++Practice/C-SIMS/BU.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Practice/C-SIMS/BU.dat -------------------------------------------------------------------------------- /C++Practice/C-SIMS/C-SIMS.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31402.337 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "C-SIMS", "C-SIMS.vcxproj", "{6A818F35-71E3-441B-B310-0BA281AD8AEE}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {6A818F35-71E3-441B-B310-0BA281AD8AEE}.Debug|x64.ActiveCfg = Debug|x64 17 | {6A818F35-71E3-441B-B310-0BA281AD8AEE}.Debug|x64.Build.0 = Debug|x64 18 | {6A818F35-71E3-441B-B310-0BA281AD8AEE}.Debug|x86.ActiveCfg = Debug|Win32 19 | {6A818F35-71E3-441B-B310-0BA281AD8AEE}.Debug|x86.Build.0 = Debug|Win32 20 | {6A818F35-71E3-441B-B310-0BA281AD8AEE}.Release|x64.ActiveCfg = Release|x64 21 | {6A818F35-71E3-441B-B310-0BA281AD8AEE}.Release|x64.Build.0 = Release|x64 22 | {6A818F35-71E3-441B-B310-0BA281AD8AEE}.Release|x86.ActiveCfg = Release|Win32 23 | {6A818F35-71E3-441B-B310-0BA281AD8AEE}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {20F61302-8850-4E59-BBA7-AC46716AC3B7} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /C++Practice/C-SIMS/C-SIMS.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 源文件 23 | 24 | 25 | 26 | 27 | 头文件 28 | 29 | 30 | -------------------------------------------------------------------------------- /C++Practice/C-SIMS/CS.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Practice/C-SIMS/CS.dat -------------------------------------------------------------------------------- /C++Practice/C-SIMS/MA.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Practice/C-SIMS/MA.dat -------------------------------------------------------------------------------- /C++Practice/C-SIMS/StudIMS.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Practice/C-SIMS/StudIMS.cpp -------------------------------------------------------------------------------- /C++Practice/C-SIMS/Student.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Practice/C-SIMS/Student.cpp -------------------------------------------------------------------------------- /C++Practice/C-SIMS/Student.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | using namespace std; 3 | 4 | class Student 5 | { 6 | private: 7 | static int total; 8 | public: 9 | int studNum = 0; 10 | char name[20] = "0"; 11 | char sex = '0'; 12 | char college[3] = "0"; 13 | int year = 0; 14 | int colNum = 0; 15 | Student() {}; 16 | Student(char name[20], char sex, char college[3], int year, int colNum); 17 | void GenID(int count); 18 | void print(); 19 | int Total(); 20 | void setTotal(int total); 21 | }; -------------------------------------------------------------------------------- /C++Practice/SIMS/BU.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Practice/SIMS/BU.dat -------------------------------------------------------------------------------- /C++Practice/SIMS/CS.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Practice/SIMS/CS.dat -------------------------------------------------------------------------------- /C++Practice/SIMS/MA.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Practice/SIMS/MA.dat -------------------------------------------------------------------------------- /C++Practice/SIMS/SIMS.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31402.337 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SIMS", "SIMS.vcxproj", "{C3D3A093-B9DE-491C-997F-9EE2C609A92D}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {C3D3A093-B9DE-491C-997F-9EE2C609A92D}.Debug|x64.ActiveCfg = Debug|x64 17 | {C3D3A093-B9DE-491C-997F-9EE2C609A92D}.Debug|x64.Build.0 = Debug|x64 18 | {C3D3A093-B9DE-491C-997F-9EE2C609A92D}.Debug|x86.ActiveCfg = Debug|Win32 19 | {C3D3A093-B9DE-491C-997F-9EE2C609A92D}.Debug|x86.Build.0 = Debug|Win32 20 | {C3D3A093-B9DE-491C-997F-9EE2C609A92D}.Release|x64.ActiveCfg = Release|x64 21 | {C3D3A093-B9DE-491C-997F-9EE2C609A92D}.Release|x64.Build.0 = Release|x64 22 | {C3D3A093-B9DE-491C-997F-9EE2C609A92D}.Release|x86.ActiveCfg = Release|Win32 23 | {C3D3A093-B9DE-491C-997F-9EE2C609A92D}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {43049673-912F-495D-8EB9-80D7B9340FAF} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /C++Practice/SIMS/SIMS.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 源文件 23 | 24 | 25 | 源文件 26 | 27 | 28 | 29 | 30 | 头文件 31 | 32 | 33 | 头文件 34 | 35 | 36 | -------------------------------------------------------------------------------- /C++Practice/SIMS/Student.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Practice/SIMS/Student.cpp -------------------------------------------------------------------------------- /C++Practice/SIMS/Student.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Practice/SIMS/Student.h -------------------------------------------------------------------------------- /C++Practice/SIMS/myfunc.cpp: -------------------------------------------------------------------------------- 1 | #include "myfunc.h" 2 | -------------------------------------------------------------------------------- /C++Practice/SIMS/myfunc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void input(); 4 | void display(); 5 | void printAll(); 6 | void Query(); 7 | void Del(); 8 | void Ins(); 9 | void modify(); 10 | void Sort(); 11 | void Save(); 12 | void Read(); -------------------------------------------------------------------------------- /C++Practice/SIMS/stuInfoMS.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Practice/SIMS/stuInfoMS.cpp -------------------------------------------------------------------------------- /C++Practice/demo1/Observer.cpp: -------------------------------------------------------------------------------- 1 | #include "Observer.h" 2 | -------------------------------------------------------------------------------- /C++Practice/demo1/Observer.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Practice/demo1/Observer.h -------------------------------------------------------------------------------- /C++Practice/demo1/Observerable.cpp: -------------------------------------------------------------------------------- 1 | #include "Observerable.h" 2 | -------------------------------------------------------------------------------- /C++Practice/demo1/Observerable.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Practice/demo1/Observerable.h -------------------------------------------------------------------------------- /C++Practice/demo1/Singleton.cpp: -------------------------------------------------------------------------------- 1 | #include "Singleton.h" 2 | Singleton* Singleton::This = NULL; 3 | const Singleton* Singleton::getInstance() { 4 | if (!This) 5 | { 6 | This = new Singleton; 7 | } 8 | return This; 9 | } 10 | -------------------------------------------------------------------------------- /C++Practice/demo1/Singleton.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Practice/demo1/Singleton.h -------------------------------------------------------------------------------- /C++Practice/demo1/demo1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | //#include"Singleton.h" 5 | //#include"Observer.h" 6 | using namespace std; 7 | 8 | //struct B; 9 | //struct A { 10 | // shared_ptrpb; 11 | // ~A() { 12 | // cout << "~A" << endl; 13 | // } 14 | //}; 15 | //struct B 16 | //{ 17 | // shared_ptrpa; 18 | // ~B() { 19 | // cout << "~B" << endl; 20 | // } 21 | //}; 22 | //struct BW; 23 | //struct AW { 24 | // shared_ptrpb; 25 | // ~AW() { 26 | // cout << "~AW" << endl; 27 | // } 28 | //}; 29 | // 30 | //struct BW 31 | //{ 32 | // weak_ptrpa; 33 | // ~BW() { 34 | // cout << "~BW" << endl; 35 | // } 36 | //}; 37 | //// pa和pb存在着循环引用,根据 shared_ptr引用计数的原理,pa和pb都无法被正常的释放 38 | //// weak ptr是为了解决 shared ptr双向引用的问题 39 | //void Test() { 40 | // cout << "Test shared_ptr and shared_ptr:" << endl; 41 | // shared_ptrtA(new A()); 42 | // shared_ptrtB(new B()); 43 | // cout << tA.use_count() << endl; // 1 44 | // cout << tB.use_count() << endl; // 1 45 | // tA->pb = tB; 46 | // tB->pa = tA; 47 | // cout << tA.use_count() << endl; // 2 48 | // cout << tB.use_count() << endl; // 2 49 | //}; 50 | // 51 | //void Test2() { 52 | // cout << "Test weak_ptr and shared_ptr:" << endl; 53 | // shared_ptrtA(new AW()); 54 | // shared_ptrtB(new BW()); 55 | // cout << tA.use_count() << endl; // 1 56 | // cout << tB.use_count() << endl; // 1 57 | // tA->pb = tB; 58 | // tB->pa = tA; 59 | // cout << tA.use_count() << endl; // 1 60 | // cout << tB.use_count() << endl; // 2 61 | //}; 62 | 63 | //class User1 :public Observer { 64 | // virtual void Update(void* pArg) { 65 | // cout << "User1" << endl; 66 | // } 67 | //}; 68 | //class User2 :public Observer { 69 | // virtual void Update(void* pArg) { 70 | // cout << "User2" << endl; 71 | // } 72 | //}; 73 | 74 | // 虚函数 动态类型转换 75 | class Base { 76 | public: 77 | Base() :_i(0) { ; } 78 | virtual void T() { cout << "Base" << endl; } 79 | private: 80 | int _i; 81 | }; 82 | class Derived :public Base 83 | { 84 | public: 85 | Derived() :_j(0) { ; } 86 | virtual void T() { cout << "Derived" << endl; } 87 | private: 88 | int _j; 89 | }; 90 | int main() 91 | { 92 | double a = 1.1; 93 | double e = 2; 94 | int b = int(a); 95 | double c = double(b + a); 96 | cout << b << endl; 97 | cout << b + 0.1 << endl; 98 | cout << c << endl; 99 | cout << e + 0.1 << endl; 100 | 101 | Base cb; 102 | Derived cd; 103 | Base* pcb; 104 | Derived* pcd; 105 | 106 | // 子类——> 父类 107 | pcb = static_cast(&cd); 108 | pcb = dynamic_cast(&cd); 109 | if (pcb == NULL) 110 | { 111 | cout << "unsafe dynamic_cast D to B" << endl; 112 | } 113 | // 父类——> 子类 114 | pcd = static_cast(&cb); 115 | pcd = dynamic_cast(&cb); 116 | if (pcd == NULL) 117 | { 118 | cout << "unsafe dynamic_cast B to D" << endl; 119 | } 120 | 121 | //User1 u1; 122 | //User2 u2; 123 | 124 | //Singleton::getInstance()->Do(); 125 | 126 | 127 | //Test(); 128 | //Test2(); 129 | //void (*p)(); 130 | //p = Test; 131 | 132 | //// unique_ptr 133 | //auto w = std::make_unique(10); 134 | //cout << *(w.get()) << endl; 135 | ////auto w2 = w; // 编译错误如果想要把w复制给w2,是不可以的。 136 | ////因为复制从语义上来说,两个对象将共享同一块内存 137 | 138 | ////unique ptr只支持移动语义,即如下 139 | //auto w2 = std::move(w); 140 | //cout << ((w.get() != nullptr) ? (*w.get()) : -1) << endl; 141 | //cout << ((w2.get() != nullptr) ? (*w2.get()) : -1) << endl; 142 | 143 | //{ 144 | // auto wA = shared_ptr(new int(20)); 145 | // { 146 | // auto wB = wA; 147 | // cout << ((wA.get() != nullptr) ? (*wA.get()) : -1) << endl; //20 148 | // cout << ((wB.get() != nullptr) ? (*wB.get()) : -1) << endl; //20 149 | // cout << wA.use_count() << endl; //2 150 | // cout << wB.use_count() << endl; //2 151 | // } 152 | // //cout << wB.use_count() << endl; 153 | // cout << wA.use_count() << endl; 154 | //} 155 | return 0; 156 | } -------------------------------------------------------------------------------- /C++Practice/demo1/demo1.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31402.337 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "demo1", "demo1.vcxproj", "{9B1AE19A-740B-40EA-9A80-82BCBFD0E9E6}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {9B1AE19A-740B-40EA-9A80-82BCBFD0E9E6}.Debug|x64.ActiveCfg = Debug|x64 17 | {9B1AE19A-740B-40EA-9A80-82BCBFD0E9E6}.Debug|x64.Build.0 = Debug|x64 18 | {9B1AE19A-740B-40EA-9A80-82BCBFD0E9E6}.Debug|x86.ActiveCfg = Debug|Win32 19 | {9B1AE19A-740B-40EA-9A80-82BCBFD0E9E6}.Debug|x86.Build.0 = Debug|Win32 20 | {9B1AE19A-740B-40EA-9A80-82BCBFD0E9E6}.Release|x64.ActiveCfg = Release|x64 21 | {9B1AE19A-740B-40EA-9A80-82BCBFD0E9E6}.Release|x64.Build.0 = Release|x64 22 | {9B1AE19A-740B-40EA-9A80-82BCBFD0E9E6}.Release|x86.ActiveCfg = Release|Win32 23 | {9B1AE19A-740B-40EA-9A80-82BCBFD0E9E6}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {C868B2CD-0296-426C-8059-163715D9008F} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /C++Practice/demo1/demo1.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 源文件 23 | 24 | 25 | 源文件 26 | 27 | 28 | 源文件 29 | 30 | 31 | 32 | 33 | 头文件 34 | 35 | 36 | 头文件 37 | 38 | 39 | 头文件 40 | 41 | 42 | -------------------------------------------------------------------------------- /C++Practice/exam-a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | class Student { 7 | public: 8 | int id; 9 | string name; 10 | char gender; 11 | string institute; 12 | 13 | Student(); 14 | Student(string name, char gender, string institute); 15 | 16 | void GenID(int year,int studNo); 17 | void Print(); 18 | }; 19 | 20 | Student::Student() {}; 21 | 22 | Student::Student(string name, char gender, string institute) { 23 | this->name=name; 24 | this->gender=gender; 25 | this->institute=institute; 26 | }; 27 | 28 | void Student::Print() { 29 | // cout << id << name << " " << gender << " " << institute << " " << endl; 30 | cout << name << " "; 31 | }; 32 | 33 | void Student::GenID(int year,int studNo) { 34 | if(institute == "CS") { 35 | id = 11*10000 + year%100*100 + studNo; 36 | } else if(institute == "MA") { 37 | id = 22*10000 + year%100*100 + studNo; 38 | } else if(institute == "BU") { 39 | id = 33*10000 + year%100*100 + studNo; 40 | } 41 | } 42 | 43 | void PrintInfo(int size, Student arr[]); 44 | 45 | int main() { 46 | // Student stud("张三 ", 'F', "CS", 2019, 34); 47 | // stud.Print(); 48 | Student csArr[20]; 49 | Student maArr[20]; 50 | Student buArr[20]; 51 | int csIndex=0; 52 | int maIndex=0; 53 | int buIndex=0; 54 | // csArr[0]=stud; 55 | // csArr[0].Print(); 56 | 57 | int t=0; 58 | cin>>t; 59 | for(int i=0; i> name >> gender >> institute >> year >> studNo; 66 | Student stud(name, gender, institute); 67 | stud.GenID(year, studNo); 68 | if(institute == "CS") { 69 | csArr[csIndex++]=stud; 70 | } else if(institute == "MA") { 71 | maArr[maIndex++]=stud; 72 | } else if(institute == "BU") { 73 | buArr[buIndex++]=stud; 74 | } 75 | } 76 | 77 | PrintInfo(csIndex, csArr); 78 | PrintInfo(maIndex, maArr); 79 | PrintInfo(buIndex, buArr); 80 | } 81 | 82 | void PrintInfo(int size, Student arr[]) { 83 | if(size==0) { 84 | cout<< "no student"; 85 | } else { 86 | for(int i=0; i 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 3 | # ** DO NOT EDIT ** 4 | 5 | # TARGTYPE "Win32 (x86) Console Application" 0x0103 6 | 7 | CFG=exam-b - Win32 Debug 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, 9 | !MESSAGE use the Export Makefile command and run 10 | !MESSAGE 11 | !MESSAGE NMAKE /f "exam-b.mak". 12 | !MESSAGE 13 | !MESSAGE You can specify a configuration when running NMAKE 14 | !MESSAGE by defining the macro CFG on the command line. For example: 15 | !MESSAGE 16 | !MESSAGE NMAKE /f "exam-b.mak" CFG="exam-b - Win32 Debug" 17 | !MESSAGE 18 | !MESSAGE Possible choices for configuration are: 19 | !MESSAGE 20 | !MESSAGE "exam-b - Win32 Release" (based on "Win32 (x86) Console Application") 21 | !MESSAGE "exam-b - Win32 Debug" (based on "Win32 (x86) Console Application") 22 | !MESSAGE 23 | 24 | # Begin Project 25 | # PROP AllowPerConfigDependencies 0 26 | # PROP Scc_ProjName "" 27 | # PROP Scc_LocalPath "" 28 | CPP=cl.exe 29 | RSC=rc.exe 30 | 31 | !IF "$(CFG)" == "exam-b - Win32 Release" 32 | 33 | # PROP BASE Use_MFC 0 34 | # PROP BASE Use_Debug_Libraries 0 35 | # PROP BASE Output_Dir "Release" 36 | # PROP BASE Intermediate_Dir "Release" 37 | # PROP BASE Target_Dir "" 38 | # PROP Use_MFC 0 39 | # PROP Use_Debug_Libraries 0 40 | # PROP Output_Dir "Release" 41 | # PROP Intermediate_Dir "Release" 42 | # PROP Target_Dir "" 43 | # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c 44 | # ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c 45 | # ADD BASE RSC /l 0x804 /d "NDEBUG" 46 | # ADD RSC /l 0x804 /d "NDEBUG" 47 | BSC32=bscmake.exe 48 | # ADD BASE BSC32 /nologo 49 | # ADD BSC32 /nologo 50 | LINK32=link.exe 51 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 52 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 53 | 54 | !ELSEIF "$(CFG)" == "exam-b - Win32 Debug" 55 | 56 | # PROP BASE Use_MFC 0 57 | # PROP BASE Use_Debug_Libraries 1 58 | # PROP BASE Output_Dir "Debug" 59 | # PROP BASE Intermediate_Dir "Debug" 60 | # PROP BASE Target_Dir "" 61 | # PROP Use_MFC 0 62 | # PROP Use_Debug_Libraries 1 63 | # PROP Output_Dir "Debug" 64 | # PROP Intermediate_Dir "Debug" 65 | # PROP Target_Dir "" 66 | # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c 67 | # ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c 68 | # ADD BASE RSC /l 0x804 /d "_DEBUG" 69 | # ADD RSC /l 0x804 /d "_DEBUG" 70 | BSC32=bscmake.exe 71 | # ADD BASE BSC32 /nologo 72 | # ADD BSC32 /nologo 73 | LINK32=link.exe 74 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 75 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 76 | 77 | !ENDIF 78 | 79 | # Begin Target 80 | 81 | # Name "exam-b - Win32 Release" 82 | # Name "exam-b - Win32 Debug" 83 | # Begin Source File 84 | 85 | SOURCE=".\exam-b.cpp" 86 | # End Source File 87 | # End Target 88 | # End Project 89 | -------------------------------------------------------------------------------- /C++Practice/exam-b.opt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Practice/exam-b.opt -------------------------------------------------------------------------------- /C++Practice/exam-b.plg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Practice/exam-b.plg -------------------------------------------------------------------------------- /C++Practice/noobtest/noobtest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | class MyClass 7 | { 8 | public: 9 | MyClass(); 10 | ~MyClass(); 11 | void print(int); 12 | private: 13 | static int a; 14 | }; 15 | int MyClass::a = 0; 16 | void MyClass::print(int c) { 17 | cout << a++ + c << endl; 18 | } 19 | MyClass::MyClass() 20 | { 21 | } 22 | 23 | MyClass::~MyClass() 24 | { 25 | } 26 | 27 | int main() 28 | { 29 | MyClass cla; 30 | vectorarr; 31 | arr.push_back(cla); 32 | arr.push_back(cla); 33 | arr.push_back(cla); 34 | arr.push_back(cla); 35 | arr.push_back(cla); 36 | MyClass arr2[5]; 37 | for (int i = 0; i < 5; ++i) { 38 | arr2[i] = cla; 39 | arr[i].print(1); 40 | arr2[i].print(2); 41 | } 42 | } -------------------------------------------------------------------------------- /C++Practice/noobtest/noobtest.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31402.337 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "noobtest", "noobtest.vcxproj", "{26429A53-0BC7-4524-ABE6-98DF397EA8B5}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {26429A53-0BC7-4524-ABE6-98DF397EA8B5}.Debug|x64.ActiveCfg = Debug|x64 17 | {26429A53-0BC7-4524-ABE6-98DF397EA8B5}.Debug|x64.Build.0 = Debug|x64 18 | {26429A53-0BC7-4524-ABE6-98DF397EA8B5}.Debug|x86.ActiveCfg = Debug|Win32 19 | {26429A53-0BC7-4524-ABE6-98DF397EA8B5}.Debug|x86.Build.0 = Debug|Win32 20 | {26429A53-0BC7-4524-ABE6-98DF397EA8B5}.Release|x64.ActiveCfg = Release|x64 21 | {26429A53-0BC7-4524-ABE6-98DF397EA8B5}.Release|x64.Build.0 = Release|x64 22 | {26429A53-0BC7-4524-ABE6-98DF397EA8B5}.Release|x86.ActiveCfg = Release|Win32 23 | {26429A53-0BC7-4524-ABE6-98DF397EA8B5}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {FDD83A36-3027-4C4A-A6E5-FD4D9211177C} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /C++Practice/noobtest/noobtest.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /C++Practice/studTest/CS.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Practice/studTest/CS.dat -------------------------------------------------------------------------------- /C++Practice/studTest/Employee.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Practice/studTest/Employee.txt -------------------------------------------------------------------------------- /C++Practice/studTest/cs.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Practice/studTest/cs.txt -------------------------------------------------------------------------------- /C++Practice/studTest/studTest.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31402.337 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "studTest", "studTest.vcxproj", "{2928A46C-714B-4B4F-AA5C-71229F96110C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {2928A46C-714B-4B4F-AA5C-71229F96110C}.Debug|x64.ActiveCfg = Debug|x64 17 | {2928A46C-714B-4B4F-AA5C-71229F96110C}.Debug|x64.Build.0 = Debug|x64 18 | {2928A46C-714B-4B4F-AA5C-71229F96110C}.Debug|x86.ActiveCfg = Debug|Win32 19 | {2928A46C-714B-4B4F-AA5C-71229F96110C}.Debug|x86.Build.0 = Debug|Win32 20 | {2928A46C-714B-4B4F-AA5C-71229F96110C}.Release|x64.ActiveCfg = Release|x64 21 | {2928A46C-714B-4B4F-AA5C-71229F96110C}.Release|x64.Build.0 = Release|x64 22 | {2928A46C-714B-4B4F-AA5C-71229F96110C}.Release|x86.ActiveCfg = Release|Win32 23 | {2928A46C-714B-4B4F-AA5C-71229F96110C}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {198A7453-31D6-4AEA-B5C9-11F89FE59479} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /C++Practice/studTest/studTest.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /C++Practice/studTest/students.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++Practice/studTest/students.cpp -------------------------------------------------------------------------------- /C++Practice/环境搭建.md: -------------------------------------------------------------------------------- 1 | [toc] 2 | 3 | 4 | 5 | ## 一、下载及安装相关 6 | 7 | ffmpeg: 8 | [ffmpeg官网](http://ffmpeg.org/) 9 | Download——左下选择windows图标——Windows builds by Zeranoe——选4.2.2——64位——下载Shared和Dev 10 | 11 | ffmpeg配置 12 | 新建一个文件夹,里边手动添加四个文件夹,分别为bin、include、lib、src,项目文件直接放在src中,ffmpeg_Shared中bin文件下的所有文件放于bin中,ffmpeg_Dev中include文件中所有文件放于include中,lib同理 13 | 14 | QT: 15 | [QT官网](http://download.qt.io/) 16 | archive/——qt/——5.9/——5.9.8/(我用的是5.9.8,但5.9应该都差不多,下最新的版本应该也可以)—— qt-opensource-windows-x86-5.9.8.exe 17 | 18 | * pdb文件也在该目录下 19 | * qtcreator版本为4.8.2 20 | 21 | 安装——组件中必选msvc2015 64-bit,源码Sources可安可不安,Tools中默认勾选Qt Creator即可,如需用qt的gdb进行调试需自行勾选MinGW 22 | 23 | * 尽量不要全部勾选,qt5.9.8在全部勾选好像安装时会有些东西安装失败,貌似是Qt5.9最下方有关qt的组件方面的问题 24 | 25 | QT——VS插件: 26 | 网站相同archive/——vsaddin/(我用的是2.2.2版本,在git中可以找到,最新版里也还有可以支持2015的版本,不知有何区别) 27 | 28 | QT**环境变量**配置: 29 | 1.在系统环境变量中添加名为QTDIR的变量,其值位编译器地址,如xxxx\msvc2015_64 30 | 2.然后再系统变量中Path添加编译器bin目录(uic.exe所处位置),如xxxx\msvc2015_64\bin 31 | 3.在命令符窗口中用uic -version命令查看是否配置成功 32 | 33 | 调试工具——win10sdk, 34 | 网址: https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk 35 | 选择镜像或者安装文件都可,我上传的是镜像文件,前面全部默认即可,在控件选择上只留Debugging Tools for Windows即可 36 | 37 | ## 二、基础准备 38 | 39 | 1. Visual Studio 2015 40 | 2. Win10SDK安装Debugging tools for windows(调试工具) 41 | 3. Qt5.9对应VS安装 42 | 4. 安装VS的qt插件 43 | 5. 配置Qtcreator(先安装Win10SDK再安装Qtcreator应该会自动搜寻,既不用配置) 44 | * 工具——选项——Debuggers配置64位和32位的cdb,默认位于C:\Program Files (x86)Windows Kits\10\Debuggers\x64(或x86)\cdb.exe 45 | 6. VS中选择Qt项中的Qt options配置相应环境只需要选中Qt\5.9下的msvc2015_64即可,32位添加msvc2515 46 | 7. VS创建完项目,为了引入自备的库以及方便管理和挪动,添加相对路径并固定 47 | * 右键项目——属性 48 | * 常规——输出目录改为——..\\..\bin 49 | * 调试——工作目录改为——..\\..\bin 50 | * C/C++——附加包含目录中添加——..\\..\include 51 | * 链接器——附加库目录添加——..\\..\lib 52 | * 链接器——输入——加入需要引用的库 53 | * 链接器——系统——选择子系统——控制台(打开控制台便于查错) 54 | 8. VS的Qt项目转换为Qtcreator项目后编译项目可能会出现dependent 'GeneratedFiles\\moc_vsqt.cpp' does not exist的错误,这是由于Qt没有识别$ (ConfigurationName) 这个宏 55 | * VS——Qt VS Tools——Qt project settings——properties——MocDirectory——将 $(ConfigurationName)改为Debug 56 | * 已经用Qtcreator打开的项目需要先关闭重新生成pro文件,外部修改选择全是,再次打开pro文件 57 | * 构建——清理项目——执行qmake——重新编译 58 | 59 | ## 三、将VS的Qt项目转换为Qtcreator项目 60 | 61 | * 选择Qt VS Tools——Convert Project to Qt VS Tools Project 62 | * 原本灰色的4个选项全部点亮 63 | * 选择Create Basic .pro File(pri文件会保存所有公用信息,便于跨平台开发,可以勾选) 64 | 65 | ## 四、vs编译运行Qt/Qml工程 66 | 67 | vs虽然暂时无法直接创建Qml工程(新版插件可能会提供支持),但可以编译运行Qml项目,故我们需要在Qtcreator中创建Qml项目后在用qmake命令转换为vs工程:(vs编译Qt相关工程,需要下载安装qt-vs-addin,即qt的vs插件) 68 | 69 | 1. 可以先添加qmake和vc的编译环境于**环境变量**path中 70 | * qmake:xxxx\msvcxxxx\bin (qt环境变量也需要) 71 | * vc::C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin (具体看安装路径) 72 | 2. cmd命令符窗口进入项目路径(项目内) 73 | * 执行命令qmake -tp vc 74 | * 运行后目录下应该生成了.vcxproj文件 75 | 76 | -------------------------------------------------------------------------------- /C++基础补充-菜鸟教程.assets/image-20210701020655565.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++基础补充-菜鸟教程.assets/image-20210701020655565.png -------------------------------------------------------------------------------- /C++实战笔记-罗剑锋.md: -------------------------------------------------------------------------------- 1 | [toc] 2 | 3 | # 《罗剑锋的C++实战笔记》课程大纲课前导读 4 | 5 | ## 开篇词| 把C++从“神坛”上拉下来,这次咱这么学课前准备丨搭建实验环境 6 | 7 | # 概论 8 | 9 | ## 01 重新认识C++:生命周期和编程范式 10 | 11 | ## 02 编码阶段能做什么:秀出好的 code style 12 | 13 | ## 03 预处理阶段能做什么:宏定义和条件编译 14 | 15 | ## 04 编译阶段能做什么:属性和静态断言 16 | 17 | ## 05 面向对象编程:怎样才能写出一个“好”的类? 18 | 19 | # 语言特性 20 | 21 | ## 06 auto/decltype:为什么要有自动类型推导 22 | 23 | ## 07 const/olatile/mutable:常量/变量究竟是怎么回事? 24 | 25 | ## 08 smart_ptr:智能指针到底“智能”在哪里? 26 | 27 | ## 09 exception:怎样才能用好异常? 28 | 29 | ## 10 Lambda:函数式编程带来了什么? 30 | 31 | # 标准库 32 | 33 | ## 11 一枝独秀的字符串:C++也能处理文本? 34 | 35 | ## 12 三分天下的容器:恰当选择,事半功倍 36 | 37 | ## 13 五花八门的算法:不要再手写for循环了 38 | 39 | ## 14 十面埋伏的并发:多线程真的很难吗? 40 | 41 | # 技能进阶 42 | 43 | ## 15 序列化:简单通用的数据交换格式有哪些? 44 | 45 | ## 16 网络通信:我不想写原生 Socket 46 | 47 | ## 17 脚本语言:搭建高性能的混合系统8性能优化:该用什么工具?怎么用? 48 | 49 | # 总结篇 50 | 51 | ## 19 设计模式(上):该怎么学设计模式? 52 | 53 | ## 20 设计模式(下):C++里的设计模式 54 | 55 | ## 21 知识串讲(上):带你开发一个书店应用 56 | 57 | ## 22 知识串讲(下):带你开发一个书店应用 58 | 59 | ## 期末测试|这些C++核心知识,你都掌握了吗? 60 | 61 | # 轻松话题 62 | 63 | ## 轻松话题(一)|经典的技术书单大放送 64 | 65 | ## 轻松话题(二)|给你分享我的工作百宝箱 66 | 67 | ## 轻松话题(三)|学习之余,来读点儿不一样的 68 | 69 | ## 轻松话题四)|提高生活质量的手机App 70 | 71 | ## 结束语| The Road Ahead -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020141109034.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020141109034.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020141202556.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020141202556.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020141217839.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020141217839.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020141305130.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020141305130.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020141320169.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020141320169.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020141353469.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020141353469.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020141417347.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020141417347.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020141446629-16347104871251-16347104874922.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020141446629-16347104871251-16347104874922.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020141446629-16347104871251.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020141446629-16347104871251.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020141446629.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020141446629.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020141507906.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020141507906.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020141519022.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020141519022.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020141717472.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020141717472.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020141729565.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020141729565.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020141743039.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020141743039.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020141809730.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020141809730.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020141854587.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020141854587.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020141900449.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020141900449.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020141911534.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020141911534.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020141917357.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020141917357.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020142033914.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020142033914.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020142040534.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020142040534.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020142047142.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020142047142.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020142052313.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020142052313.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020142114604.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020142114604.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020142120036.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020142120036.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020142127909.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020142127909.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020142133397.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020142133397.png -------------------------------------------------------------------------------- /C++实现学生信息管理系统.assets/image-20211020142141791.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C++实现学生信息管理系统.assets/image-20211020142141791.png -------------------------------------------------------------------------------- /C_2Level/1.Fibonacci sequence.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int f, f1 = 0, f2 = 1; 6 | printf("%d,", f1); 7 | do 8 | { 9 | printf("%d,", f2); 10 | f = f1 + f2; 11 | f1 = f2; 12 | f2 = f; 13 | } while (f2 <= 1000); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C_2Level/10.pointerArray.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define M 3 3 | int main() 4 | { 5 | int *p, a[M], i; 6 | for (p = a; p - a < M; p++) 7 | { 8 | scanf("%d", p); 9 | printf("%p,%p\n", a, p); // a为数组首地址 p为数组首地址 10 | } 11 | p -= M; // 重置指针起始位置 12 | for (i = 0; i < M; i++) 13 | { 14 | printf("%d,%d,%d\n", p[i], *(a + i), *(p + i)); // 通过指针获取数组值 数组和指针操作相同; a 是常量,p 是变量 15 | } 16 | } -------------------------------------------------------------------------------- /C_2Level/11.pointerArray2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define M 2 3 | #define N 3 4 | 5 | // 首地址+行数+列数 6 | // void fun(double a[M][N]) 7 | // { 8 | // } 9 | 10 | // 首地址+列数 11 | // void fun2(double a[][N]) 12 | // { 13 | // } 14 | 15 | // 行指针+列数 16 | void fun(double (*a)[N]) 17 | { 18 | // printf("%8.2lf%8.2lf%8.2lf\n", (*a)[0], (*a)[1], (*a)[2]); // 取行地址值【列下标】 19 | printf("%8.2lf%8.2lf%8.2lf\n", (*(a + 1))[0], (*(a + 1))[1], (*(a + 1))[2]); // 取行地址值(行指针+位移)【列下标】 *优先级高于+ 20 | // printf("%8.2lf%8.2lf%8.2lf\n", *(*a), *(*a + 1), *(*a + 2)); // 取值(行指针地址+位移) 21 | printf("%8.2lf%8.2lf%8.2lf\n", *a[1], *(a[1] + 1), *(a[1] + 2)); // 取值(行指针【行下标】+位移) 22 | printf("%8.2lf%8.2lf%8.2lf\n", *(*(a + 1)), *(*(a + 1) + 1), *(*(a + 1) + 2)); // 取值(取行地址值(行指针+位移)+位移) 23 | 24 | printf("%p\n%p\n%p\n%p\n", (&a[0] + 1), (&a[0])[1], &a[1], (&a + 7)); // 相同地址 25 | printf("%8.2lf%8.2lf%8.2lf%8.2lf%8.2lf%8.2lf\n", *((&a[0] + 1)[0]), *((&a[0])[1]), *(*(&a[1])), *(&a[1][0]), *(&a + 7), *(*(&a[0] + 1))); // *逆运算& 26 | 27 | *a[0] = *(*(a + 0)) = **a; // * 等于 [] 28 | *a[1] = *(*(a + 1)); // 下标 等于 指针位移 29 | *(&a) = a; // * 逆运算 & 相互抵消; 由 * 等于 [],推出 [] 也和 & 相互抵消; 30 | printf("%d\n", *a[0] == *(*(a + 0)) == **a); 31 | 32 | *(*(&a[1])) = *(*(a + 1)) = *a[1]; 33 | 34 | *(&a[1][0]) = *(*(&a[1])) = a[1][0] = *a[1]; 35 | *((&a[0])[1]) = *(*(*(&a) + 1)) = *a[1]; 36 | *((&a[0] + 1)[0]) = *(*(*(&a) + 1)) = *(*(a + 1)) = *a[1]; 37 | } 38 | 39 | int main() 40 | { 41 | double s[M][N] = {{1, 2, 3}, {4, 5, 6}}; 42 | fun(s); 43 | } 44 | -------------------------------------------------------------------------------- /C_2Level/12.pointerArray3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define M 5 3 | #define N 3 4 | 5 | // 行指针+列数 6 | void fun(double *a[], int i) // 加括号:(指针)【列数】; 不加括号:指针数组 ;**a 指向指针的指针 7 | { 8 | for (int j = 0; j < N; j++) 9 | { 10 | printf("%8.2lf", a[i][j]); // 首地址【行地址】【列地址】 11 | } 12 | printf("\n"); 13 | } 14 | 15 | int main() 16 | { 17 | double s[M][N] = {{1, 2, 3}, {4, 5, 6}}, *ps[M]; 18 | for (int i = 0; i < M; i++) 19 | { 20 | printf("%p", &s[i]); 21 | ps[i] = s[i]; // 把二维数组每一行的[首地址]存到指针数组里面 22 | fun(ps, i); // 传递指针数组及当前行 23 | // for (int j = 0; j < N; j++) 24 | // { 25 | // printf("%8.2lf", ps[i][j]); // 首地址【行地址】【列地址】 26 | // } 27 | // printf("\n"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /C_2Level/13.pointerChar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char *s; 6 | s = "good!"; 7 | char s2[10]; 8 | scanf("%s", s2); 9 | s2[0] = '?'; 10 | printf("%s\n", s2); 11 | printf("%s", s); 12 | } 13 | -------------------------------------------------------------------------------- /C_2Level/14.CharPractice.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void fun(char *w, int m) 4 | { 5 | char *p1, *p2, s; 6 | p1 = w; 7 | p2 = w + m - 1; // *p2="G"; 8 | while (p1 < p2) 9 | { 10 | s = *p1++; // s="A"; 后++优先级低于= 低于* 加括号也不管用 11 | *p1 = *p2--; // *(p1+1)="G"; 先取值赋值,最后-- 12 | *p2 = s; // *(p2-1)="A"; 13 | } // AG...AG; 14 | } 15 | int main() 16 | { 17 | char a[] = "ABCDEFG"; 18 | fun(a, strlen(a)); 19 | puts(a); 20 | } 21 | -------------------------------------------------------------------------------- /C_2Level/15.funfactorial.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fac(int n) 4 | { 5 | int t; 6 | if (n == 1 || n == 0) 7 | return 1; 8 | else 9 | { 10 | t = n * fac(n - 1); 11 | return t; 12 | } 13 | } 14 | int main() 15 | { 16 | int m, y; 17 | scanf("%d", &m); 18 | if (m < 0) 19 | printf("Input Err!"); 20 | else 21 | { 22 | y = fac(m); 23 | printf("%d!=%d", m, y); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /C_2Level/16.FILEwrite.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(void) 4 | { 5 | FILE *fp; 6 | char ch, fileName[10]; 7 | scanf("%s", fileName); 8 | if ((fp = fopen(fileName, "w")) == NULL) 9 | { 10 | printf("Can't Open File\n"); 11 | exit(0); // 终止程序 12 | } 13 | ch = getchar(); // 接收执行scanf语句时最后输入的回车符 14 | ch = getchar(); // 接收输入的第一个字符 15 | while (ch != '#') 16 | { 17 | fputc(ch, fp); 18 | putchar(ch); 19 | ch = getchar(); 20 | fclose(fp); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /C_2Level/17.FILEread.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(void) 4 | { 5 | FILE *fp; 6 | char ch; 7 | if ((fp = fopen("123", "r")) == NULL) 8 | { 9 | printf("Can't Open File\n"); 10 | exit(0); // 终止程序 11 | } 12 | ch = getc(fp); // 接收一个字符 13 | while (ch != EOF) 14 | { 15 | putchar(ch); 16 | ch = getc(fp); 17 | fclose(fp); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /C_2Level/2.switch.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int i = 10, f; 6 | scanf("%d", &f); 7 | switch (i / f) 8 | { 9 | case 2: 10 | printf("2"); 11 | case 5: 12 | printf("5"); 13 | case 10: 14 | printf("10"); 15 | break; 16 | default: 17 | printf("Null"); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /C_2Level/3.A-aExchange.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | char c; //定义一个字符型变量 5 | while ((c = getchar()) != '\n') //没有读入字符没有到回车时候转换 6 | { 7 | if (c >= 'a' && c <= 'z') 8 | { 9 | c = c - 'a' + 'A'; //或者直接写c=c-32 10 | putchar(c); //输出字符c 11 | } 12 | } 13 | putchar('\n'); 14 | } -------------------------------------------------------------------------------- /C_2Level/4.LettersSum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int s = 0, b = 0, n = 0; //定义变量s为小写字母数量,b为大写字母数量,n数字 5 | char c; 6 | while ((c = getchar()) != '\n') 7 | { 8 | if (c >= 'a' && c <= 'z') 9 | s++; 10 | if (c >= 'A' && c <= 'Z') 11 | b++; 12 | if (c >= '0' && c <= '9') 13 | n++; 14 | } 15 | printf("%d,%d,%d", s, b, n); 16 | } -------------------------------------------------------------------------------- /C_2Level/5.func.c: -------------------------------------------------------------------------------- 1 | char b() 2 | { 3 | printf("bbbb"); 4 | } 5 | #include 6 | double c() 7 | { 8 | printf("ccc"); 9 | } 10 | 11 | double d(); 12 | 13 | // 函数调用与声明 14 | int main() 15 | { 16 | double e(); 17 | a(); 18 | b(); 19 | c(); 20 | d(); 21 | e(); 22 | } 23 | int a() 24 | { 25 | printf("aaaa"); 26 | } 27 | // char a() 28 | // { 29 | // printf("aaaa"); 30 | // } 31 | // double a() 32 | // { 33 | // printf("aaaa"); 34 | // } 35 | 36 | double d() 37 | { 38 | printf("dddd"); 39 | } 40 | double e() 41 | { 42 | printf("eee"); 43 | } 44 | -------------------------------------------------------------------------------- /C_2Level/6.Transfer parameters.c: -------------------------------------------------------------------------------- 1 | #include 2 | void swap(int, int); /*函数说明*/ 3 | int main() 4 | { 5 | int x = 10, y = 20; 6 | printf("(1)x=%d y=%d\n", x, y); 7 | swap(x, y); //值传递 8 | printf("(4)x=%d y=%d\n", x, y); 9 | } 10 | void swap(int a, int b) 11 | { 12 | int t; 13 | printf("(2)a=%d b=%d\n", a, b); 14 | t = a, a = b, b = t; 15 | printf("(3)a=%d b=%d\n", a, b); 16 | } -------------------------------------------------------------------------------- /C_2Level/7.Comma expression.c: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | #include 3 | #include 4 | int main() 5 | { 6 | int a = 1, b = 1; 7 | a = ++a, a + 10, a * 10; 8 | printf("a=%d", a); 9 | b = (++b, b + 10, b * 10); 10 | printf("b=%d", b); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C_2Level/8.pointer.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a, b = 2, *p = NULL; 5 | a = 1; 6 | p = &a; 7 | *p = b; 8 | printf("%d,%d,%p,%p,%p", *p, a, &p, p, &a); 9 | } -------------------------------------------------------------------------------- /C_2Level/9.array.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define M 30 3 | int main() 4 | { 5 | int s[M], i, k = 1; 6 | for (i = 0; i < M; i++) 7 | { 8 | s[i] = k; 9 | k += 2; 10 | } 11 | printf("\nSequence Output: \n"); 12 | for (i = 0; i < M; i++) 13 | { 14 | printf("%4d", s[i]); 15 | if ((i + 1) % 10 == 0) 16 | printf("\n"); 17 | } 18 | printf("\ninvert Output: \n"); 19 | for (i = M - 1; i >= 0; i--) 20 | { 21 | printf("%4d", s[i]); 22 | if (i % 10 == 0) 23 | printf("\n"); 24 | } 25 | printf("\n"); 26 | } -------------------------------------------------------------------------------- /C_C++网络编程,从socket到epoll.assets/image-20210705144109361.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C_C++网络编程,从socket到epoll.assets/image-20210705144109361.png -------------------------------------------------------------------------------- /C_C++网络编程,从socket到epoll.assets/image-20210705224417795.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C_C++网络编程,从socket到epoll.assets/image-20210705224417795.png -------------------------------------------------------------------------------- /C_C++网络编程,从socket到epoll.assets/image-20210705235241828.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/C_C++网络编程,从socket到epoll.assets/image-20210705235241828.png -------------------------------------------------------------------------------- /C_DataStruc/d.c.1.0.time.c: -------------------------------------------------------------------------------- 1 | // #include 2 | // long f(int n) 3 | // { 4 | // if (n == 0) 5 | // return 1; 6 | // else 7 | // return n * f(n - 1); 8 | // } 9 | // int main() 10 | // { 11 | // int m, n = 3; 12 | // m = f(n); 13 | // printf("%d!=%d\n", n, m); 14 | // } 15 | 16 | //  代码实现: 17 | #include 18 | long f(int n) 19 | { 20 | if (n == 1) 21 | return 1; 22 | else 23 | return n * f(n - 1); 24 | } 25 | int main() 26 | { 27 | int m, n = 3; 28 | m = f(n); 29 | printf("%d!=%d\n", n, m); 30 | } 31 | 32 | #define MAXSIZE 20 //设记录不超过 20个 33 | typedef int KeyType; //设关键字为整型量(int 型) 34 | typedef struct 35 | { //定义每个记录(数据元素)的结构 36 | KeyType key; //关键字 37 | InfoType otherinfo; //其它数据项 38 | } RedType; 39 | 40 | typedef struct 41 | { //定义顺序表的结构 42 | RedType r[MAXSIZE + 1]; //存 储顺序表的向量, //r[0]-般作哨兵或缓冲区 43 | int length; //顺序表的长度 44 | } SqList; 45 | typedef struct 46 | { //要背下来 47 | RedType r[MAXSIZE + 1]; 48 | int length; 49 | } SqList; 50 | -------------------------------------------------------------------------------- /C_DataStruc/d.c.1.1.leafnode_num.c: -------------------------------------------------------------------------------- 1 | #include 2 | int leafnode_num(BinTree bt) 3 | { 4 | if (bt == NULL) 5 | return 0; 6 | else if (bt->lchild == NULL && bt->rchild == NULL) 7 | return 1; 8 | else 9 | return leafnode_num(bt->lchlid) + leafnode_num(bt->rchild); 10 | } -------------------------------------------------------------------------------- /C_DataStruc/d.c.1.2.StraightInsertSort.c: -------------------------------------------------------------------------------- 1 | #include 2 | void StraightInsertSort(List R, int n) 3 | { 4 | int i, j; 5 | for (i = 2; i <= n; i++) //n 为表长,从第二个记录进行插入 6 | { 7 | R[0] = R[i]; //第 i 个记录赋值为岗哨 8 | j = i - 1; 9 | while (R[0].key < R[j].key) //与岗哨比较,直至键值不大于岗哨值 10 | { 11 | R[j + 1] = R[j]; //将第 j 个记录赋值给第 j+1 个记录 12 | j--; 13 | } 14 | R[j + 1] = R[0]; //将第 i 个记录插入到序列中 15 | } 16 | } -------------------------------------------------------------------------------- /C_DataStruc/d.c.1.3.InitiateLinkList.c: -------------------------------------------------------------------------------- 1 | #include 2 | const int Maxsize = 20; 3 | typedef struct node 4 | { 5 | DataType key; 6 | struct node *next; 7 | } Node, *LinkList; 8 | LinkList InitiateLinkList() 9 | { 10 | LinkList head; 11 | head = malloc(sizeof(Node)); 12 | head->next = NULL; 13 | return head; 14 | } -------------------------------------------------------------------------------- /C_DataStruc/d.c.1.4.SearchBin.c: -------------------------------------------------------------------------------- 1 | #include 2 | const int Maxsize = 20; 3 | typedef struct 4 | { 5 | KeyType key; 6 | 7 | } TableElem; 8 | typedef struct 9 | { 10 | TableElem elem[Maxsize + 1]; 11 | int n; 12 | } SqTable; 13 | int SearchBin(SqTable T, KeyType key) 14 | { 15 | int low, high, mid; 16 | low = 1; 17 | high = T.length; 18 | while (low <= high) 19 | { 20 | mid = (low + high) / 2; 21 | if (mid == key) 22 | return mid; 23 | else if (key > mid) 24 | low = mid + 1; 25 | else 26 | high = mid - 1; 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /C_DataStruc/d.c.1.5.MM.c: -------------------------------------------------------------------------------- 1 | #include 2 | // 翻转矩阵 3 | int A[10][10]; 4 | void MM(int A[n][n]) 5 | { 6 | int i, j, temp; 7 | for (i = 0; i < n; i++) 8 | { 9 | for (j = 0; j < i; j++) 10 | { 11 | temp = A[i][j]; 12 | A[i][j] = A[j][i]; 13 | A[j][i] = temp; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /C_DataStruc/d.c.1.6.preorder.c: -------------------------------------------------------------------------------- 1 | #include 2 | // 递归 二叉链表 先序遍历 3 | typedef struct btnode 4 | { 5 | DataType data; 6 | struct btnode *lchild, *rchild; 7 | } * BinTree; 8 | void preorder(BinTree bt) 9 | { 10 | if (bt != NULL) 11 | { 12 | visit(bt); 13 | preorder(bt->lchild); 14 | preorder(bt->rchild); 15 | } 16 | } -------------------------------------------------------------------------------- /C_DataStruc/d.c.1.7.Height.c: -------------------------------------------------------------------------------- 1 | #include 2 | // 递归 求树高 3 | typedef struct btnode 4 | { 5 | DataType data; 6 | struct btnode *lchild, *rchild; 7 | } * BinTree; 8 | int Height(BinTree bt) 9 | { 10 | int lh, rh; 11 | if (bt != NULL) 12 | return 0; 13 | else 14 | { 15 | lh = Height(bt->lchild); 16 | rh = Height(bt->rchild); 17 | return 1 + (lh > rh ? lh : rh); 18 | } 19 | } -------------------------------------------------------------------------------- /C_DataStruc/d.c.1.8..c: -------------------------------------------------------------------------------- 1 | #include 2 | // 递归 求树高 3 | typedef struct btnode 4 | { 5 | DataType data; 6 | struct btnode *lchild, *rchild; 7 | } * BinTree; 8 | int Height(BinTree bt) 9 | { 10 | int lh, rh; 11 | if (bt != NULL) 12 | return 0; 13 | else 14 | { 15 | lh = Height(bt->lchild); 16 | rh = Height(bt->rchild); 17 | return 1 + (lh > rh ? lh : rh); 18 | } 19 | } -------------------------------------------------------------------------------- /C_DataStruc/d.c.2.hong.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define R 20 /*宏定义*/ 3 | #define M int main( /*宏定义*/ 4 | #define N(n) n * 10 /*宏定义*/ 5 | #define ADD(a, b) (a + b) /*宏定义 加括号提高计算优先级*/ 6 | int add(int a, int b) { return a + b; } 7 | M) 8 | { 9 | int a = R; 10 | printf("a=%d\n", a); 11 | printf("hello world\n"); 12 | 13 | int b = N(a); // int b=a*10; 14 | printf("b=%d\n", b); 15 | 16 | int c = add(a, b); // 函数 17 | printf("c=%d\n", c); 18 | 19 | int d = ADD(a, b); // 宏函数替换 20 | printf("d=%d\n", d); 21 | 22 | int e = ADD(a, b) * ADD(a, b); // 预处理后 宏替换为:a+b*a+b。运算是编译时执行 23 | printf("e=%d\n", e); 24 | 25 | int f = ADD(10.5, 10); 26 | printf("f=%d\n", f); 27 | 28 | float h = ADD(10.5, 10); // 宏替换不考虑数据类型 29 | printf("h=%f\n", h); 30 | 31 | // 宏替换 条件编译 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /C_DataStruc/d.c.3.struct.c: -------------------------------------------------------------------------------- 1 | #include 2 | struct weapon //自定义类型 3 | { 4 | char name[20]; 5 | int atk; 6 | int price; 7 | } weapon_2; //可以直接在尾部定义变量 8 | int main() 9 | { 10 | int a = 0; 11 | float b = 0.0; 12 | 13 | struct weapon weapon_1 = {"weapon_name", 100, 200}; 14 | printf("%s\n%d\n", weapon_1.name, ++weapon_1.price); 15 | 16 | // 结构体指针 17 | struct weapon *w; 18 | w = &weapon_1; 19 | printf("name=%s\n", (*w).name); //点运算符优先级高于 * ,要加括号 20 | // 使用指针指向运算符 21 | printf("name=%s\n", w->name); 22 | 23 | // 结构体数组的使用方法 24 | struct weapon weapon_2[2] = {"weapon_name1", 100, 200, "weapon_name2", 300, 400}; //每个数据项可以用{}括起来 25 | printf("%s\n%d\n", weapon_2[0].name, weapon_2[1].atk); 26 | 27 | // 指针指针结构体数组 28 | struct weapon *p; 29 | p = weapon_2; // p->name; p 里面是 wapon_2[0].name 30 | printf("name=%s\n", p->name); 31 | // p+1 指针第二个成员 32 | printf("name=%s\n", (++p)->name); 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /C_DataStruc/d.c.4.common.c: -------------------------------------------------------------------------------- 1 | #include 2 | union data //struct 3 | { 4 | int a; // 4字节 5 | char b; // 1字节,填充三字节 6 | int c; // 偏移量为8字节, 结构体总大小12字节, 然后判断是不是最宽变量类型的整数倍 7 | }; 8 | int main() 9 | { 10 | union data data_1; // 初始化表只能有一个常量 11 | data_1.b = 'C'; 12 | data_1.a = 10; // 共用内存,覆盖前面的成员 13 | printf("%d\n %d\n", data_1.b, data_1.a); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C_DataStruc/d.c.5.Linked list.c: -------------------------------------------------------------------------------- 1 | #include 2 | struct weapon //自定义类型作为节点元素 3 | { 4 | int price; 5 | int atk; 6 | struct weapon *next; // 存放下一个节点的地址 7 | }; 8 | int main() 9 | { 10 | struct weapon a, b, c, *head; 11 | a.price = 100; 12 | a.atk = 100; 13 | b.price = 200; 14 | b.atk = 200; 15 | c.price = 300; 16 | c.atk = 300; 17 | // 连成链表 18 | head = &a; 19 | a.next = &b; 20 | b.next = &c; 21 | c.next = NULL; 22 | // 生成指针p 访问结点 23 | struct weapon *p; 24 | p = head; 25 | while (p != NULL) 26 | { 27 | printf("%d,%d\n", p->atk, p->price); 28 | p = p->next; 29 | } 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /C_DataStruc/d.c.6.dynamic linked list.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct weapon //自定义类型作为节点元素 4 | { 5 | int price; 6 | int atk; 7 | struct weapon *next; // 存放下一个节点的地址 8 | }; 9 | 10 | struct weapon *create() 11 | { 12 | struct weapon *head; 13 | struct weapon *p1, *p2; 14 | int n = 0; 15 | // malloc 分配内存 , sizeof 判断数据类型长度 16 | p1 = p2 = (struct weapon *)malloc(sizeof(struct weapon)); 17 | scanf("%d,%d", &p1->price, &p1->atk); // 输入格式: 数据,数据 18 | head = NULL; 19 | while (p1->price != 0) // 输入 0 结束输入 20 | { 21 | n++; 22 | if (n == 1) 23 | head = p1; 24 | else 25 | p2->next = p1; 26 | 27 | p2 = p1; 28 | p1 = (struct weapon *)malloc(sizeof(struct weapon)); 29 | scanf("%d,%d", &p1->price, &p1->atk); 30 | } 31 | p2->next = NULL; 32 | return head; 33 | } 34 | int main() 35 | { 36 | struct weapon *p; 37 | p = create(); 38 | while (p != NULL) 39 | { 40 | printf("%d,%d\n", p->price, p->atk); 41 | p = p->next; 42 | } 43 | return 0; 44 | } -------------------------------------------------------------------------------- /C_DataStruc/d.c.7.Bitwise and.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | // & | ^ ~ << >> 6 | int a = 4; // 00000000 00000000 00000000 00000100 7 | int b = 7; // 00000000 00000000 00000000 00000111 8 | // 00000000 00000000 00000000 00000100 9 | int C = a & b; 10 | printf("%d\n", C); 11 | 12 | // 迅速清零: 与 0 按位与 13 | int zero = a & 0; 14 | printf("%d\n", zero); 15 | 16 | // 保留指定位: b 低八位 置1, a&b, 得到 a 的低八位 17 | // 判断奇偶性: a&1=1 则是奇数,a&1=0 则是偶数 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /C_DataStruc/d.c.8.c: -------------------------------------------------------------------------------- 1 | #include 2 | int func(int n) 3 | { 4 | int r; 5 | if (n < 0) 6 | printf("data error\n"); 7 | else if (n == 0 | n == 1) 8 | r = 1; 9 | else 10 | r = n * func(n - 1); 11 | return r; 12 | } 13 | int main() 14 | { 15 | int n; 16 | printf("pLease input n\n"); 17 | scanf("%d", &n); 18 | int result = func(n); 19 | printf("result = %d\n", result); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /ComputerNetwork/1.gethostbyname.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define WSVERS MAKEWORD(2, 0) 4 | 5 | using namespace std; 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | WSADATA wsadata; 10 | WSAStartup(WSVERS, &wsadata); 11 | struct hostent *h; 12 | h = gethostbyname(argv[1]); 13 | cout << h->h_addr_list << endl; 14 | cout << h->h_name << endl; 15 | cout << h->h_aliases << endl; 16 | cout << h->h_addrtype << endl; 17 | cout << h->h_length << endl; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /ComputerNetwork/TCPdtc.cpp: -------------------------------------------------------------------------------- 1 | /* TCPdtc.cpp - main, TCPdaytime */ 2 | #include 3 | #include 4 | #include 5 | void TCPdaytime(const char *, const char *); 6 | void errexit(const char *, ...); 7 | SOCKET connectTCP(const char *, const char *); 8 | #define LINELEN 128 9 | #define WSVERS MAKEWORD(2, 0) 10 | /*-------------------------------------------------------- 11 | * main - TCP client for DAYTIME service 12 | *-------------------------------------------------------- 13 | */ 14 | int main(int argc, char *argv[]) 15 | { 16 | char *host = "localhost"; /* host to use if none supplied */ 17 | char *service = "daytime"; /* default service port */ 18 | WSADATA wsadata; 19 | switch (argc) 20 | { 21 | case 1: 22 | host = "localhost"; 23 | break; 24 | case 3: 25 | service = argv[2]; 26 | /* FALL THROUGH */ 27 | case 2: 28 | host = argv[1]; 29 | break; 30 | default: 31 | fprintf(stderr, "usage: TCPdaytime [host [port]]\n"); 32 | exit(1); 33 | } 34 | if (WSAStartup(WSVERS, &wsadata) != 0) 35 | errexit("WSAStartup failed\n"); 36 | TCPdaytime(host, service); 37 | WSACleanup(); 38 | return 0; /* exit */ 39 | } 40 | /*----------------------------------------------------- 41 | * TCPdaytime - invoke Daytime on specified host and print results 42 | *----------------------------------------------------- 43 | */ 44 | void TCPdaytime(const char *host, const char *service) 45 | { 46 | char buf[LINELEN + 1]; /* buffer for one line of text */ 47 | SOCKET s; /* socket descriptor */ 48 | int cc; /* recv character count */ 49 | s = connectTCP(host, service); 50 | cc = recv(s, buf, LINELEN, 0); 51 | while (cc != SOCKET_ERROR && cc > 0) 52 | { 53 | buf[cc] = '\0'; /* ensure null-termination */ 54 | (void)fputs(buf, stdout); 55 | cc = recv(s, buf, LINELEN, 0); 56 | } 57 | closesocket(s); 58 | } -------------------------------------------------------------------------------- /ComputerNetwork/TCPdtd.cpp: -------------------------------------------------------------------------------- 1 | /* TCPdtd.cpp - main, TCPdaytimed */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | void errexit(const char *, ...); 7 | void TCPdaytimed(SOCKET); 8 | SOCKET passiveTCP(const char *, int); 9 | #define QLEN 5 10 | #define WSVERS MAKEWORD(2, 0) 11 | /*------------------------------------------------------------------------ 12 | * main - Concurrent TCP server for DAYTIME service 13 | *------------------------------------------------------------------------ 14 | */ 15 | void main(int argc, char *argv[]) 16 | { 17 | struct sockaddr_in fsin; /* the from address of a client */ 18 | char *service = "daytime"; /* service name or port number*/ 19 | SOCKET msock, ssock; /* master & slave sockets */ 20 | int alen; /* from-address length */ 21 | WSADATA wsadata; 22 | switch (argc) 23 | { 24 | case 1: 25 | break; 26 | case 2: 27 | service = argv[1]; 28 | break; 29 | default: 30 | errexit("usage: TCPdaytimed [port]\n"); 31 | } 32 | if (WSAStartup(WSVERS, &wsadata) != 0) 33 | errexit("WSAStartup failed\n"); 34 | msock = passiveTCP(service, QLEN); 35 | while (1) 36 | { 37 | alen = sizeof(struct sockaddr); 38 | ssock = accept(msock, (struct sockaddr *)&fsin, &alen); 39 | if (ssock == INVALID_SOCKET) 40 | errexit("accept failed: error number %d\n", 41 | GetLastError()); 42 | if (_beginthread((void (*)(void *))TCPdaytimed, 0, 43 | (void *)ssock) < 0) 44 | { 45 | errexit("_beginthread: %s\n", strerror(errno)); 46 | } 47 | } 48 | // return 1; /* not reached */ 49 | } 50 | /*---------------------------------------------------------------------- 51 | * TCPdaytimed - do TCP DAYTIME protocol 52 | *----------------------------------------------------------------------- 53 | */ 54 | void TCPdaytimed(SOCKET fd) 55 | { 56 | char *pts; /* pointer to time string */ 57 | time_t now; /* current time */ 58 | (void)time(&now); 59 | pts = ctime(&now); 60 | (void)send(fd, pts, strlen(pts), 0); 61 | (void)closesocket(fd); 62 | } -------------------------------------------------------------------------------- /ComputerNetwork/UDPdtc.cpp: -------------------------------------------------------------------------------- 1 | /* UDPdtc.cpp - main, UDPdaytime */ 2 | #include 3 | #include 4 | #include 5 | void UDPdaytime(const char *, const char *); 6 | void errexit(const char *, ...); 7 | SOCKET connectUDP(const char *, const char *); 8 | #define LINELEN 128 9 | #define WSVERS MAKEWORD(2, 0) 10 | #define MSG "what daytime is it ?\n" 11 | /*-------------------------------------------------------- 12 | * main - UDP client for DAYTIME service 13 | *-------------------------------------------------------- 14 | */ 15 | int main(int argc, char *argv[]) 16 | { 17 | char *host = "localhost"; /* host to use if none supplied */ 18 | char *service = "daytime"; /* default service port */ 19 | WSADATA wsadata; 20 | switch (argc) 21 | { 22 | case 1: 23 | host = "localhost"; 24 | break; 25 | case 3: 26 | service = argv[2]; 27 | /* FALL THROUGH */ 28 | case 2: 29 | host = argv[1]; 30 | break; 31 | default: 32 | fprintf(stderr, "usage: UDPdaytime [host [port]]\n"); 33 | exit(1); 34 | } 35 | if (WSAStartup(WSVERS, &wsadata) != 0) 36 | errexit("WSAStartup failed\n"); 37 | UDPdaytime(host, service); 38 | WSACleanup(); 39 | return 0; /* exit */ 40 | } 41 | /*----------------------------------------------------- 42 | * UDPdaytime - invoke Daytime on specified host and print results 43 | *----------------------------------------------------- 44 | */ 45 | void UDPdaytime(const char *host, const char *service) 46 | { 47 | char buf[LINELEN + 1]; /* buffer for one line of text */ 48 | SOCKET s; /* socket descriptor */ 49 | int n; /* recv character count */ 50 | s = connectUDP(host, service); 51 | (void)send(s, MSG, strlen(MSG), 0); 52 | /* Read the daytime */ 53 | n = recv(s, buf, LINELEN, 0); 54 | if (n == SOCKET_ERROR) 55 | errexit("recv failed: recv() error %d\n", GetLastError()); 56 | else 57 | { 58 | buf[n] = '\0'; /* ensure null-termination */ 59 | (void)fputs(buf, stdout); 60 | } 61 | closesocket(s); 62 | // return 0; /* exit */ 63 | } -------------------------------------------------------------------------------- /ComputerNetwork/UDPdtd.cpp: -------------------------------------------------------------------------------- 1 | /* UDPdtd.cpp - main, UDPdaytimed */ 2 | #include 3 | #include 4 | #include 5 | void errexit(const char *, ...); 6 | SOCKET passiveUDP(const char *); 7 | #define WSVERS MAKEWORD(2, 0) 8 | /*------------------------------------------------------------------------ 9 | * main - Iterative UDP server for DAYTIME service 10 | *------------------------------------------------------------------------ 11 | */ 12 | void main(int argc, char *argv[]) 13 | { 14 | char buf[10]; /* buffer for one line of text */ 15 | struct sockaddr_in fsin; /* the from address of a client */ 16 | char *service = "daytime"; /* service name or port number */ 17 | SOCKET sock; /* socket */ 18 | int alen; /* from-address length */ 19 | char *pts; /* pointer to time string */ 20 | time_t now; /* current time */ 21 | WSADATA wsadata; 22 | switch (argc) 23 | { 24 | case 1: 25 | break; 26 | case 2: 27 | service = argv[1]; 28 | break; 29 | default: 30 | errexit("usage: UDPdaytimed [port]\n"); 31 | } 32 | if (WSAStartup(WSVERS, &wsadata) != 0) 33 | errexit("WSAStartup failed\n"); 34 | sock = passiveUDP(service); 35 | while (1) 36 | { 37 | alen = sizeof(struct sockaddr); 38 | if (recvfrom(sock, buf, sizeof(buf), 0, 39 | (struct sockaddr *)&fsin, &alen) == SOCKET_ERROR) 40 | errexit("recvfrom: error %d\n", GetLastError()); 41 | (void)time(&now); 42 | pts = ctime(&now); 43 | (void)sendto(sock, pts, strlen(pts), 0, 44 | (struct sockaddr *)&fsin, sizeof(fsin)); 45 | } 46 | // return 1; /* not reached */ 47 | } -------------------------------------------------------------------------------- /ComputerNetwork/chatServer/chatServer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/ComputerNetwork/chatServer/chatServer.cpp -------------------------------------------------------------------------------- /ComputerNetwork/chatServer/chatServer.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31402.337 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "chatServer", "chatServer.vcxproj", "{9E357D8A-DF7F-4A95-8C13-CCFAA516807A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {9E357D8A-DF7F-4A95-8C13-CCFAA516807A}.Debug|x64.ActiveCfg = Debug|x64 17 | {9E357D8A-DF7F-4A95-8C13-CCFAA516807A}.Debug|x64.Build.0 = Debug|x64 18 | {9E357D8A-DF7F-4A95-8C13-CCFAA516807A}.Debug|x86.ActiveCfg = Debug|Win32 19 | {9E357D8A-DF7F-4A95-8C13-CCFAA516807A}.Debug|x86.Build.0 = Debug|Win32 20 | {9E357D8A-DF7F-4A95-8C13-CCFAA516807A}.Release|x64.ActiveCfg = Release|x64 21 | {9E357D8A-DF7F-4A95-8C13-CCFAA516807A}.Release|x64.Build.0 = Release|x64 22 | {9E357D8A-DF7F-4A95-8C13-CCFAA516807A}.Release|x86.ActiveCfg = Release|Win32 23 | {9E357D8A-DF7F-4A95-8C13-CCFAA516807A}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {A119C465-3D5D-43E9-81C4-EAA7C0789673} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /ComputerNetwork/chatServer/chatServer.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | -------------------------------------------------------------------------------- /ComputerNetwork/conTCP.cpp: -------------------------------------------------------------------------------- 1 | /* conTCP.cpp - connectTCP */ 2 | #include 3 | SOCKET connectsock(const char *, const char *, const char *); 4 | /*---------------------------------------------------- 5 | * connectTCP - connect to a specified TCP service 6 | * on a specified host 7 | *--------------------------------------------------- 8 | */ 9 | SOCKET connectTCP(const char *host, const char *service) 10 | { 11 | return connectsock(host, service, "tcp"); 12 | } -------------------------------------------------------------------------------- /ComputerNetwork/conUDP.cpp: -------------------------------------------------------------------------------- 1 | /* conUDP.cpp - connectUDP */ 2 | #include 3 | SOCKET connectsock(const char *, const char *, const char *); 4 | /*------------------------------------------------------- 5 | * connectUDP - connect to a specified UDP service 6 | * on a specified host 7 | *----------------------------------------------------- 8 | */ 9 | SOCKET connectUDP(const char *host, const char *service) 10 | { 11 | return connectsock(host, service, "udp"); 12 | } -------------------------------------------------------------------------------- /ComputerNetwork/consock.cpp: -------------------------------------------------------------------------------- 1 | /* consock.cpp - connectsock */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #ifndef INADDR_NONE 7 | #define INADDR_NONE 0xffffffff 8 | #endif /* INADDR_NONE */ 9 | void errexit(const char *, ...); 10 | /*------------------------------------------------------- 11 | * connectsock - allocate & connect a socket using TCP or UDP 12 | *------------------------------------------------------ 13 | */ 14 | 15 | SOCKET connectsock(const char *host, const char *service, const char *transport) 16 | { 17 | struct hostent *phe; /* pointer to host information entry */ 18 | struct servent *pse; /* pointer to service information entry */ 19 | struct protoent *ppe; /* pointer to protocol information entry */ 20 | struct sockaddr_in sin; /* an Internet endpoint address */ 21 | int s, type; /* socket descriptor and socket type */ 22 | memset(&sin, 0, sizeof(sin)); 23 | sin.sin_family = AF_INET; 24 | 25 | /* Map service name to port number */ 26 | if (pse = getservbyname(service, transport)) 27 | sin.sin_port = pse->s_port; 28 | else if ((sin.sin_port = htons((u_short)atoi(service))) == 0) 29 | errexit("can't get \"%s\" service entry\n", service); 30 | /* Map host name to IP address, allowing for dotted decimal */ 31 | if (phe = gethostbyname(host)) 32 | memcpy(&sin.sin_addr, phe->h_addr, phe->h_length); 33 | else if ((sin.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE) 34 | errexit("can't get \"%s\" host entry\n", host); 35 | /* Map protocol name to protocol number */ 36 | if ((ppe = getprotobyname(transport)) == 0) 37 | errexit("can't get \"%s\" protocol entry\n", transport); 38 | 39 | /* Use protocol to choose a socket type */ 40 | if (strcmp(transport, "udp") == 0) 41 | type = SOCK_DGRAM; 42 | else 43 | type = SOCK_STREAM; 44 | /* Allocate a socket */ 45 | s = socket(PF_INET, type, ppe->p_proto); 46 | if (s == INVALID_SOCKET) 47 | errexit("can't create socket: %d\n", GetLastError()); 48 | /* Connect the socket */ 49 | if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) == SOCKET_ERROR) 50 | errexit("can't connect to %s.%s: %d\n", host, service, 51 | GetLastError()); 52 | return s; 53 | } -------------------------------------------------------------------------------- /ComputerNetwork/errexit.cpp: -------------------------------------------------------------------------------- 1 | /* errexit.cpp - errexit */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | /*---------------------------------------------------------- 7 | * errexit - print an error message and exit 8 | *---------------------------------------------------------- 9 | */ 10 | /*VARARGS1*/ 11 | void errexit(const char *format, ...) 12 | { 13 | va_list args; 14 | va_start(args, format); 15 | vfprintf(stderr, format, args); 16 | va_end(args); 17 | WSACleanup(); 18 | exit(1); 19 | } -------------------------------------------------------------------------------- /ComputerNetwork/passTCP.cpp: -------------------------------------------------------------------------------- 1 | /* passTCP.cpp - passiveTCP */ 2 | #include 3 | SOCKET passivesock(const char *, const char *, int); 4 | /*------------------------------------------------------------------------------------ 5 | * passiveTCP - create a passive socket for use in a TCP server 6 | *------------------------------------------------------------------------------------ 7 | */ 8 | SOCKET passiveTCP(const char *service, int qlen) 9 | { 10 | return passivesock(service, "tcp", qlen); 11 | } -------------------------------------------------------------------------------- /ComputerNetwork/passUDP.cpp: -------------------------------------------------------------------------------- 1 | /* passUDP.cpp - passiveUDP */ 2 | #include 3 | SOCKET passivesock(const char *, const char *, int); 4 | /*------------------------------------------------------------------------------------- 5 | * passiveUDP - create a passive socket for use in a UDP server 6 | *------------------------------------------------------------------------------------- 7 | */ 8 | SOCKET passiveUDP(const char *service) 9 | { 10 | return passivesock(service, "udp", 0); 11 | } -------------------------------------------------------------------------------- /ComputerNetwork/passsock.cpp: -------------------------------------------------------------------------------- 1 | /* passsock.cpp - passivesock */ 2 | #include 3 | #include 4 | #include 5 | void errexit(const char *, ...); 6 | /*----------------------------------------------------------------------- 7 | * passivesock - allocate & bind a server socket using TCP or UDP 8 | *------------------------------------------------------------------------ 9 | */ 10 | SOCKET passivesock(const char *service, const char *transport, int qlen) 11 | { 12 | struct servent *pse; /* pointer to service information entry */ 13 | struct protoent *ppe; /* pointer to protocol information entry */ 14 | struct sockaddr_in sin; /* an Internet endpoint address */ 15 | SOCKET s; /* socket descriptor */ 16 | int type; /* socket type (SOCK_STREAM, SOCK_DGRAM)*/ 17 | memset(&sin, 0, sizeof(sin)); 18 | sin.sin_family = AF_INET; 19 | sin.sin_addr.s_addr = INADDR_ANY; 20 | /* Map service name to port number */ 21 | if (pse = getservbyname(service, transport)) 22 | sin.sin_port = (u_short)pse->s_port; 23 | else if ((sin.sin_port = htons((u_short)atoi(service))) == 0) 24 | errexit("can't get \"%s\" service entry\n", service); 25 | /* Map protocol name to protocol number */ 26 | if ((ppe = getprotobyname(transport)) == 0) 27 | errexit("can't get \"%s\" protocol entry\n", transport); 28 | /* Use protocol to choose a socket type */ 29 | if (strcmp(transport, "udp") == 0) 30 | type = SOCK_DGRAM; 31 | else 32 | type = SOCK_STREAM; 33 | /* Allocate a socket */ 34 | s = socket(PF_INET, type, ppe->p_proto); 35 | if (s == INVALID_SOCKET) 36 | errexit("can't create socket: %d\n", GetLastError()); 37 | /* Bind the socket */ 38 | if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) == SOCKET_ERROR) 39 | errexit("can't bind to %s port: %d\n", service, 40 | GetLastError()); 41 | if (type == SOCK_STREAM && listen(s, qlen) == SOCKET_ERROR) 42 | errexit("can't listen on %s port: %d\n", service, 43 | GetLastError()); 44 | return s; 45 | } -------------------------------------------------------------------------------- /ComputerNetwork/timeClient/socketToEpoll.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31402.337 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "socketToEpoll", "socketToEpoll.vcxproj", "{885CA615-89D0-4CC1-9FBF-F92DD035C078}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {885CA615-89D0-4CC1-9FBF-F92DD035C078}.Debug|x64.ActiveCfg = Debug|x64 17 | {885CA615-89D0-4CC1-9FBF-F92DD035C078}.Debug|x64.Build.0 = Debug|x64 18 | {885CA615-89D0-4CC1-9FBF-F92DD035C078}.Debug|x86.ActiveCfg = Debug|Win32 19 | {885CA615-89D0-4CC1-9FBF-F92DD035C078}.Debug|x86.Build.0 = Debug|Win32 20 | {885CA615-89D0-4CC1-9FBF-F92DD035C078}.Release|x64.ActiveCfg = Release|x64 21 | {885CA615-89D0-4CC1-9FBF-F92DD035C078}.Release|x64.Build.0 = Release|x64 22 | {885CA615-89D0-4CC1-9FBF-F92DD035C078}.Release|x86.ActiveCfg = Release|Win32 23 | {885CA615-89D0-4CC1-9FBF-F92DD035C078}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {8C0EAEF3-45BE-4AFF-BE3D-DFB62A2CC189} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /ComputerNetwork/timeClient/socketToEpoll.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /ComputerNetwork/timeClient/timeClient.cpp: -------------------------------------------------------------------------------- 1 | /* TCPdtc.cpp - main, TCPdaytime */ 2 | #include 3 | #include 4 | #include 5 | void TCPdaytime(const char*, const char*); 6 | void errexit(const char*, ...); 7 | SOCKET connectTCP(const char*, const char*); 8 | #define LINELEN 128 9 | #define WSVERS MAKEWORD(2, 0) 10 | /*-------------------------------------------------------- 11 | * main - TCP client for DAYTIME service 12 | *-------------------------------------------------------- 13 | */ 14 | int main(int argc, char* argv[]) 15 | { 16 | char* host = "localhost"; /* host to use if none supplied */ 17 | char* service = "daytime"; /* default service port */ 18 | WSADATA wsadata; 19 | switch (argc) 20 | { 21 | case 1: 22 | host = "localhost"; 23 | break; 24 | case 3: 25 | service = argv[2]; 26 | /* FALL THROUGH */ 27 | case 2: 28 | host = argv[1]; 29 | break; 30 | default: 31 | fprintf(stderr, "usage: TCPdaytime [host [port]]\n"); 32 | exit(1); 33 | } 34 | if (WSAStartup(WSVERS, &wsadata) != 0) 35 | errexit("WSAStartup failed\n"); 36 | TCPdaytime(host, service); 37 | WSACleanup(); 38 | return 0; /* exit */ 39 | } 40 | /*----------------------------------------------------- 41 | * TCPdaytime - invoke Daytime on specified host and print results 42 | *----------------------------------------------------- 43 | */ 44 | void TCPdaytime(const char* host, const char* service) 45 | { 46 | char buf[LINELEN + 1]; /* buffer for one line of text */ 47 | SOCKET s; /* socket descriptor */ 48 | int cc; /* recv character count */ 49 | s = connectTCP(host, service); 50 | cc = recv(s, buf, LINELEN, 0); 51 | while (cc != SOCKET_ERROR && cc > 0) 52 | { 53 | buf[cc] = '\0'; /* ensure null-termination */ 54 | (void)fputs(buf, stdout); 55 | cc = recv(s, buf, LINELEN, 0); 56 | } 57 | closesocket(s); 58 | } 59 | 60 | /* errexit.cpp - errexit */ 61 | /*---------------------------------------------------------- 62 | * errexit - print an error message and exit 63 | *---------------------------------------------------------- 64 | */ 65 | /*VARARGS1*/ 66 | void errexit(const char* format, ...) 67 | { 68 | va_list args; 69 | va_start(args, format); 70 | vfprintf(stderr, format, args); 71 | va_end(args); 72 | WSACleanup(); 73 | exit(1); 74 | } 75 | 76 | /* consock.cpp - connectsock */ 77 | #include 78 | #include 79 | #include 80 | #include 81 | #ifndef INADDR_NONE 82 | #define INADDR_NONE 0xffffffff 83 | #endif /* INADDR_NONE */ 84 | void errexit(const char*, ...); 85 | /*------------------------------------------------------- 86 | * connectsock - allocate & connect a socket using TCP or UDP 87 | *------------------------------------------------------ 88 | */ 89 | 90 | SOCKET connectsock(const char* host, const char* service, const char* transport) 91 | { 92 | struct hostent* phe; /* pointer to host information entry */ 93 | struct servent* pse; /* pointer to service information entry */ 94 | struct protoent* ppe; /* pointer to protocol information entry */ 95 | struct sockaddr_in sin; /* an Internet endpoint address */ 96 | int s, type; /* socket descriptor and socket type */ 97 | memset(&sin, 0, sizeof(sin)); 98 | sin.sin_family = AF_INET; 99 | 100 | /* Map service name to port number */ 101 | if (pse = getservbyname(service, transport)) 102 | sin.sin_port = pse->s_port; 103 | else if ((sin.sin_port = htons((u_short)atoi(service))) == 0) 104 | errexit("can't get \"%s\" service entry\n", service); 105 | /* Map host name to IP address, allowing for dotted decimal */ 106 | if (phe = gethostbyname(host)) 107 | memcpy(&sin.sin_addr, phe->h_addr, phe->h_length); 108 | else if ((sin.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE) 109 | errexit("can't get \"%s\" host entry\n", host); 110 | /* Map protocol name to protocol number */ 111 | if ((ppe = getprotobyname(transport)) == 0) 112 | errexit("can't get \"%s\" protocol entry\n", transport); 113 | 114 | /* Use protocol to choose a socket type */ 115 | if (strcmp(transport, "udp") == 0) 116 | type = SOCK_DGRAM; 117 | else 118 | type = SOCK_STREAM; 119 | /* Allocate a socket */ 120 | s = socket(PF_INET, type, ppe->p_proto); 121 | if (s == INVALID_SOCKET) 122 | errexit("can't create socket: %d\n", GetLastError()); 123 | /* Connect the socket */ 124 | if (connect(s, (struct sockaddr*)&sin, sizeof(sin)) == SOCKET_ERROR) 125 | errexit("can't connect to %s.%s: %d\n", host, service, 126 | GetLastError()); 127 | return s; 128 | } 129 | 130 | /* conTCP.cpp - connectTCP */ 131 | /*---------------------------------------------------- 132 | * connectTCP - connect to a specified TCP service 133 | * on a specified host 134 | *--------------------------------------------------- 135 | */ 136 | SOCKET connectTCP(const char* host, const char* service) 137 | { 138 | return connectsock(host, service, "tcp"); 139 | } 140 | -------------------------------------------------------------------------------- /ComputerNetwork/timeServer/timeServer.cpp: -------------------------------------------------------------------------------- 1 | #pragma warning(disable:4996) // 关闭全部警告 2 | /* TCPdtd.cpp - main, TCPdaytimed */ 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace std; 12 | void errexit(const char*, ...); 13 | void TCPdaytimed(SOCKET); 14 | SOCKET passiveTCP(const char*, int); 15 | #define QLEN 5 16 | #define WSVERS MAKEWORD(2, 0) 17 | /*------------------------------------------------------------------------ 18 | * main - Concurrent TCP server for DAYTIME service 19 | *------------------------------------------------------------------------ 20 | */ 21 | int main(int argc, char* argv[]) 22 | { 23 | struct sockaddr_in fsin; /* the from address of a client */ 24 | const char* service = "daytime"; /* service name or port number*/ 25 | SOCKET msock, ssock; /* master & slave sockets */ 26 | int alen; /* from-address length */ 27 | WSADATA wsadata; 28 | switch (argc) 29 | { 30 | case 1: 31 | break; 32 | case 2: 33 | service = argv[1]; 34 | break; 35 | default: 36 | errexit("usage: TCPdaytimed [port]\n"); 37 | } 38 | if (WSAStartup(WSVERS, &wsadata) != 0) 39 | errexit("WSAStartup failed\n"); 40 | msock = passiveTCP(service, QLEN); 41 | while (1) 42 | { 43 | alen = sizeof(struct sockaddr); 44 | ssock = accept(msock, (struct sockaddr*)&fsin, &alen); 45 | if (ssock == INVALID_SOCKET) 46 | errexit("accept failed: error number %d\n", 47 | GetLastError()); 48 | if (_beginthread((void (*)(void*))TCPdaytimed, 0, (void*)ssock) < 0) 49 | { 50 | errexit("_beginthread: %s\n", strerror(errno)); 51 | } 52 | } 53 | return 1; /* not reached */ 54 | } 55 | /*---------------------------------------------------------------------- 56 | * TCPdaytimed - do TCP DAYTIME protocol 57 | *----------------------------------------------------------------------- 58 | */ 59 | void TCPdaytimed(SOCKET fd) 60 | { 61 | char* pts; /* pointer to time string */ 62 | time_t now; /* current time */ 63 | (void)time(&now); 64 | pts = ctime(&now); 65 | (void)send(fd, pts, strlen(pts), 0); 66 | (void)closesocket(fd); 67 | } 68 | 69 | /* passTCP.cpp - passiveTCP */ 70 | SOCKET passivesock(const char*, const char*, int); 71 | /*------------------------------------------------------------------------------------ 72 | * passiveTCP - create a passive socket for use in a TCP server 73 | *------------------------------------------------------------------------------------ 74 | */ 75 | SOCKET passiveTCP(const char* service, int qlen) 76 | { 77 | return passivesock(service, "tcp", qlen); 78 | } 79 | 80 | /* passsock.cpp - passivesock */ 81 | void errexit(const char*, ...); 82 | /*----------------------------------------------------------------------- 83 | * passivesock - allocate & bind a server socket using TCP or UDP 84 | *------------------------------------------------------------------------ 85 | */ 86 | SOCKET passivesock(const char* service, const char* transport, int qlen) 87 | { 88 | struct servent* pse; /* pointer to service information entry */ 89 | struct protoent* ppe; /* pointer to protocol information entry */ 90 | struct sockaddr_in sin; /* an Internet endpoint address */ 91 | SOCKET s; /* socket descriptor */ 92 | int type; /* socket type (SOCK_STREAM, SOCK_DGRAM)*/ 93 | memset(&sin, 0, sizeof(sin)); 94 | sin.sin_family = AF_INET; 95 | sin.sin_addr.s_addr = INADDR_ANY; 96 | /* Map service name to port number */ 97 | if (pse = getservbyname(service, transport)) 98 | sin.sin_port = (u_short)pse->s_port; 99 | else if ((sin.sin_port = htons((u_short)atoi(service))) == 0) 100 | errexit("can't get \"%s\" service entry\n", service); 101 | /* Map protocol name to protocol number */ 102 | if ((ppe = getprotobyname(transport)) == 0) 103 | errexit("can't get \"%s\" protocol entry\n", transport); 104 | /* Use protocol to choose a socket type */ 105 | if (strcmp(transport, "udp") == 0) 106 | type = SOCK_DGRAM; 107 | else 108 | type = SOCK_STREAM; 109 | /* Allocate a socket */ 110 | s = socket(PF_INET, type, ppe->p_proto); 111 | if (s == INVALID_SOCKET) 112 | errexit("can't create socket: %d\n", GetLastError()); 113 | /* Bind the socket */ 114 | if (bind(s, (struct sockaddr*)&sin, sizeof(sin)) == SOCKET_ERROR) 115 | errexit("can't bind to %s port: %d\n", service, 116 | GetLastError()); 117 | if (type == SOCK_STREAM && listen(s, qlen) == SOCKET_ERROR) 118 | errexit("can't listen on %s port: %d\n", service, 119 | GetLastError()); 120 | return s; 121 | } 122 | 123 | /* errexit.cpp - errexit */ 124 | /*---------------------------------------------------------- 125 | * errexit - print an error message and exit 126 | *---------------------------------------------------------- 127 | */ 128 | /*VARARGS1*/ 129 | void errexit(const char* format, ...) 130 | { 131 | va_list args; 132 | va_start(args, format); 133 | vfprintf(stderr, format, args); 134 | va_end(args); 135 | WSACleanup(); 136 | exit(1); 137 | } -------------------------------------------------------------------------------- /ComputerNetwork/timeServer/timeServer.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31402.337 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "timeServer", "timeServer.vcxproj", "{2F35B535-E74A-4C79-99ED-94C1253CF815}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {2F35B535-E74A-4C79-99ED-94C1253CF815}.Debug|x64.ActiveCfg = Debug|x64 17 | {2F35B535-E74A-4C79-99ED-94C1253CF815}.Debug|x64.Build.0 = Debug|x64 18 | {2F35B535-E74A-4C79-99ED-94C1253CF815}.Debug|x86.ActiveCfg = Debug|Win32 19 | {2F35B535-E74A-4C79-99ED-94C1253CF815}.Debug|x86.Build.0 = Debug|Win32 20 | {2F35B535-E74A-4C79-99ED-94C1253CF815}.Release|x64.ActiveCfg = Release|x64 21 | {2F35B535-E74A-4C79-99ED-94C1253CF815}.Release|x64.Build.0 = Release|x64 22 | {2F35B535-E74A-4C79-99ED-94C1253CF815}.Release|x86.ActiveCfg = Release|Win32 23 | {2F35B535-E74A-4C79-99ED-94C1253CF815}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {49846F11-3001-4929-AA2E-420FDA0C65B0} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /ComputerNetwork/timeServer/timeServer.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /QT/hello.cpp: -------------------------------------------------------------------------------- 1 | #include "hello.h" 2 | 3 | hello::hello(QObject *parent) : QObject(parent) 4 | { 5 | QDebug<<"hello"; 6 | } 7 | -------------------------------------------------------------------------------- /QT/hello.h: -------------------------------------------------------------------------------- 1 | #ifndef HELLO_H 2 | #define HELLO_H 3 | 4 | #include 5 | #include 6 | 7 | class hello : public QObject 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit hello(QObject *parent = nullptr); 12 | 13 | signals: 14 | 15 | }; 16 | 17 | #endif // HELLO_H 18 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # C/C++ 学习代码库 2 | 3 | ## 1. [全国计算机等级考试二级C语言.md](https://github.com/Eished/self-study-exam_notes/blob/master/%E8%AE%A1%E7%AE%97%E6%9C%BA%E4%BA%8C%E7%BA%A7C%E8%AF%AD%E8%A8%80.md) 4 | - [代码](https://github.com/Eished/C-CPP/tree/master/C_2Level) 5 | ## 2. [C语言结构体和数据结构.md](https://github.com/Eished/self-study-exam_notes/blob/master/Linux%20C%E8%AF%AD%E8%A8%80%E7%BB%93%E6%9E%84%E4%BD%93.md) 6 | - [代码](https://github.com/Eished/C-CPP/tree/master/C_DataStruc) 7 | ## 3. [C++程序设计 04737.md](https://github.com/Eished/self-study-exam_notes/blob/master/C%2B%2B%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1.md) 8 | - [代码](https://github.com/Eished/C-CPP/tree/master/C%2B%2BLesson) 9 | ## 4. [C++基础补充-菜鸟教程.md](https://github.com/Eished/C-CPP/blob/master/C%2B%2B%E5%9F%BA%E7%A1%80%E8%A1%A5%E5%85%85-%E8%8F%9C%E9%B8%9F%E6%95%99%E7%A8%8B.md) 10 | - [代码](https://github.com/Eished/C-CPP/tree/master/runoob_C%2B%2B) 11 | ## 5. [C++实战笔记-罗剑锋.md](https://github.com/Eished/C-CPP/blob/master/C%2B%2B%E5%AE%9E%E6%88%98%E7%AC%94%E8%AE%B0-%E7%BD%97%E5%89%91%E9%94%8B.md) 12 | - 代码 13 | ## 6. [重构你的C++知识体系.md](https://github.com/Eished/C-CPP/blob/master/%E9%87%8D%E6%9E%84%E4%BD%A0%E7%9A%84C%2B%2B%E7%9F%A5%E8%AF%86%E4%BD%93%E7%B3%BB.md) 14 | - [代码](https://github.com/Eished/C-CPP/tree/master/C%2B%2BPractice) 15 | ## 7. [C++实现学生信息管理系统.md](https://github.com/Eished/C-CPP/blob/master/C%2B%2B%E5%AE%9E%E7%8E%B0%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F.md) 16 | - [代码](https://github.com/Eished/C-CPP/tree/master/C%2B%2BPractice) 17 | ## 8. [C_C++ 网络编程,从 socket 到 epoll.md](https://github.com/Eished/C-CPP/blob/master/C_C%2B%2B%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B%EF%BC%8C%E4%BB%8Esocket%E5%88%B0epoll.md) 18 | - [代码](https://github.com/Eished/C-CPP/tree/master/ComputerNetwork) 19 | ## 9. [WinSock2 介绍和使用.md](https://github.com/Eished/C-CPP/blob/master/WinSock2%20%E4%BB%8B%E7%BB%8D%E5%92%8C%E4%BD%BF%E7%94%A8.md) 20 | 21 | -------------------------------------------------------------------------------- /runoob_C++/1.enum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | enum num 7 | { 8 | a = 1, 9 | b = 2 10 | } numA; 11 | numA = a; 12 | cout << numA << endl; 13 | return 0; 14 | } -------------------------------------------------------------------------------- /runoob_C++/2.1.time.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | time_t seconds; 7 | 8 | seconds = time(NULL); 9 | printf("自 1970-01-01 起的小时数 = %ld\n", seconds / 3600); 10 | 11 | return (0); 12 | } -------------------------------------------------------------------------------- /runoob_C++/2.2.ctime.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | time_t curtime = time(NULL); 7 | char str[26]; 8 | ctime_s(str, sizeof str, &curtime); 9 | printf("当前时间 = %s", str); 10 | return (0); 11 | } -------------------------------------------------------------------------------- /runoob_C++/2.3.UTC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main(void) 7 | { 8 | // 基于当前系统的当前日期/时间 9 | time_t now = time(NULL); 10 | // 把 now 转换为字符串形式 11 | char *str = ctime(&now); 12 | cout << "本地日期和时间:" << str << endl; 13 | // 把 now 转换为 tm 结构 14 | tm *t = gmtime(&now); 15 | // 返回形式为:day month date hours:minutes:seconds year 16 | char *tt = asctime(t); 17 | cout << "UTC 日期和时间:" << tt << endl; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /runoob_C++/2.3.localtime.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main(void) 7 | { 8 | struct tm t; //tm结构指针 9 | time_t now; //声明time_t类型变量 10 | time(&now); //获取系统日期和时间 11 | localtime_s(&t, &now); //获取当地日期和时间 12 | 13 | //格式化输出本地时间 14 | printf("年:%d\n", t.tm_year + 1900); 15 | printf("月:%d\n", t.tm_mon + 1); 16 | printf("日:%d\n", t.tm_mday); 17 | printf("星期:%d\n", t.tm_wday); 18 | printf("一年中:%d\n", t.tm_yday); 19 | printf("时:%d\n", t.tm_hour); 20 | printf("分:%d\n", t.tm_min); 21 | printf("秒:%d\n", t.tm_sec); 22 | printf("夏令时:%d\n", t.tm_isdst); 23 | system("pause"); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /runoob_C++/3.vector.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | class MyClass 7 | { 8 | public: 9 | MyClass(); 10 | ~MyClass(); 11 | void print(int); 12 | 13 | private: 14 | static int a; 15 | }; 16 | int MyClass::a = 0; 17 | void MyClass::print(int c) 18 | { 19 | cout << a++ + c << endl; 20 | } 21 | MyClass::MyClass() 22 | { 23 | } 24 | 25 | MyClass::~MyClass() 26 | { 27 | } 28 | 29 | int main() 30 | { 31 | MyClass cla; 32 | vector arr; 33 | arr.push_back(cla); 34 | arr.push_back(cla); 35 | arr.push_back(cla); 36 | arr.push_back(cla); 37 | arr.push_back(cla); 38 | MyClass arr2[5]; 39 | for (int i = 0; i < 5; ++i) 40 | { 41 | arr2[i] = cla; 42 | arr[i].print(1); 43 | arr2[i].print(2); 44 | } 45 | } -------------------------------------------------------------------------------- /runoob_C++/4.1.struct.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Book 5 | { 6 | public: 7 | int a = 0, b = 1, c = 2; 8 | Book() 9 | { 10 | cout << a << b << c << endl; 11 | }; 12 | void print() 13 | { 14 | cout << "Print:" << a << endl; 15 | }; 16 | }; 17 | 18 | struct Food 19 | { 20 | char a[10]; 21 | int b; 22 | }; 23 | 24 | struct Rice : Book 25 | { 26 | }; 27 | int main() 28 | { 29 | // class 30 | Book book; 31 | book.print(); 32 | cout << book.a << endl; 33 | book.a = 999; 34 | cout << book.a << endl; 35 | 36 | // struct 37 | Food food; 38 | // food.a = "ljoujo"; 字符串数组,不能直接赋值 39 | // 使用复制字符串函数 40 | strcpy(food.a, "milk"); 41 | cout << food.a << endl; 42 | // 数字可以赋值 43 | food.b = 1; 44 | cout << food.b << endl; 45 | 46 | // 结构体继承类 47 | Rice rice; 48 | rice.print(); 49 | cout << rice.a << endl; 50 | rice.a = 999; 51 | cout << rice.a << endl; 52 | 53 | return 0; 54 | } -------------------------------------------------------------------------------- /runoob_C++/5.1.this.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | class Box 6 | { 7 | public: 8 | // 构造函数定义 9 | Box(double l = 2.0, double b = 2.0, double h = 2.0) 10 | { 11 | cout << "Constructor called." << endl; 12 | length = l; 13 | breadth = b; 14 | height = h; 15 | } 16 | double Volume() 17 | { 18 | return length * breadth * height; 19 | } 20 | int compare(Box box) 21 | { 22 | return this->Volume() > box.Volume(); 23 | } 24 | 25 | private: 26 | double length; // Length of a box 27 | double breadth; // Breadth of a box 28 | double height; // Height of a box 29 | }; 30 | 31 | int main(void) 32 | { 33 | Box Box1(3.3, 1.2, 1.5); // Declare box1 34 | Box Box2(8.5, 6.0, 2.0); // Declare box2 35 | 36 | if (Box1.compare(Box2)) 37 | { 38 | cout << "Box2 is smaller than Box1" << endl; 39 | } 40 | else 41 | { 42 | cout << "Box2 is equal to or larger than Box1" << endl; 43 | } 44 | return 0; 45 | } -------------------------------------------------------------------------------- /runoob_C++/6.1.virtual class.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | //基类 5 | 6 | class D 7 | { 8 | public: 9 | D() { cout << "D()" << endl; } 10 | ~D() { cout << "~D()" << endl; } 11 | 12 | protected: 13 | int d; 14 | }; 15 | 16 | class B : virtual public D 17 | { 18 | public: 19 | B() { cout << "B()" << endl; } 20 | ~B() { cout << "~B()" << endl; } 21 | 22 | protected: 23 | int b; 24 | }; 25 | 26 | class A : virtual public D 27 | { 28 | public: 29 | A() { cout << "A()" << endl; } 30 | ~A() { cout << "~A()" << endl; } 31 | 32 | protected: 33 | int a; 34 | }; 35 | 36 | class C : public B, public A 37 | { 38 | public: 39 | C() { cout << "C()" << endl; } 40 | ~C() { cout << "~C()" << endl; } 41 | 42 | protected: 43 | int c; 44 | }; 45 | 46 | int main() 47 | { 48 | cout << "Hello World!" << endl; 49 | C c; //D, B, A ,C 50 | cout << sizeof(c) << endl; 51 | return 0; 52 | } -------------------------------------------------------------------------------- /runoob_C++/7.1.trycatch.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | double division(int a, int b) 5 | { 6 | if (b == 0) 7 | { 8 | throw "Division by zero condition!"; 9 | } 10 | return (a / b); 11 | } 12 | 13 | int main() 14 | { 15 | int x = 50; 16 | int y = 0; 17 | double z = 0; 18 | 19 | try 20 | { 21 | z = division(x, y); 22 | cout << z << endl; 23 | } 24 | catch (const char *msg) 25 | { 26 | cerr << msg << endl; 27 | } 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /runoob_C++/8.1.file.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | char data[100]; 9 | 10 | // 以写模式打开文件 11 | fstream file; 12 | file.open("afile.dat", ios::in | ios::out | ios::trunc); 13 | 14 | cout << "Writing to the file" << endl; 15 | cout << "Enter your name: "; 16 | cin.getline(data, 100); 17 | 18 | // 向文件写入用户输入的数据 19 | file << data << endl; 20 | 21 | // cout << "Enter your age: "; 22 | // cin >> data; 23 | // cin.ignore(); 24 | 25 | // 再次向文件写入用户输入的数据 26 | // file << data << endl; 27 | 28 | file >> data; 29 | cout << "data:" << data << endl; 30 | 31 | // // 再次从文件读取数据,并显示它 32 | // file >> data; 33 | // cout << "data:" << data << endl; 34 | 35 | file.close(); 36 | return 0; 37 | } -------------------------------------------------------------------------------- /runoob_C++/8.2.fileToObj.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | // Class to define the properties 6 | class Student 7 | { 8 | private: 9 | public: 10 | static int total; 11 | static int csCount; 12 | static int maCount; 13 | static int buCount; 14 | int studNum = 123; 15 | string name = "Johna是撒旦"; 16 | char sex = 'F'; 17 | string college = "CC"; 18 | int year = 2019; 19 | int colNum = 44; 20 | Student(){}; 21 | }; 22 | // int Employee::a = 1; 23 | int main() 24 | { 25 | Student Emp_1; 26 | // // Emp_1.Name = "John"; 27 | // // Emp_1.Employee_ID = 2121; 28 | // // Emp_1.Salary = 11000; 29 | // //Wriring this data to Employee.txt 30 | // ofstream file1; 31 | // file1.open("Employee.txt", ios::out | ios::binary); 32 | // file1.write((char *)&Emp_1, sizeof(Emp_1)); 33 | // file1.close(); 34 | //Reading data from EMployee.txt 35 | ifstream file2; 36 | file2.open("Employee.txt", ios::in | ios::binary); 37 | file2.seekg(0); 38 | file2.read((char *)&Emp_1, sizeof(Emp_1)); 39 | cout << "Name:" << Emp_1.name << endl; 40 | cout << "Employee ID:" << Emp_1.studNum << endl; 41 | cout << "Salary ::" << Emp_1.college << endl; 42 | cout << "a ::" << Emp_1.year << endl; 43 | file2.close(); 44 | return 0; 45 | } -------------------------------------------------------------------------------- /runoob_C++/9.1.strCopy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | class stud 6 | { 7 | public: 8 | char a[10] = "8999"; 9 | }; 10 | int main() 11 | { 12 | stud s; 13 | char b[10] = "234"; 14 | cin >> b; 15 | strcpy_s(s.a, b); 16 | strcmp(s.a, b); 17 | cout << s.a << strcmp(s.a, b) << endl; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /test/test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | int main() 6 | { 7 | char a = 'A'; 8 | char b[3] = "CS"; 9 | char c[3]; 10 | c[0] = a; 11 | std::cout << sizeof(a) << std::endl; 12 | std::cout << sizeof(b) << std::endl; 13 | std::cout << sizeof(c) << c << std::endl; 14 | return 0; 15 | } -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210614151906425.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210614151906425.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210614163449148.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210614163449148.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210614210809551.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210614210809551.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210614210835469.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210614210835469.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210614210912489.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210614210912489.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210614210955598.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210614210955598.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210614211125429.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210614211125429.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210614212540778.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210614212540778.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210614214610073.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210614214610073.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210614214734879.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210614214734879.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210614215222003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210614215222003.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210615030116586.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210615030116586.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210615032854986.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210615032854986.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210615162644999.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210615162644999.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210615172103195.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210615172103195.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210615174553010.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210615174553010.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210615175409247.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210615175409247.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210616151449502.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210616151449502.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210616164751511.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210616164751511.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210616231240853.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210616231240853.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210616233840459.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210616233840459.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210616234259086.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210616234259086.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210616234851389.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210616234851389.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210617020952360.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210617020952360.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210617021008259.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210617021008259.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210617164318813.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210617164318813.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210617164448957.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210617164448957.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210617165343966.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210617165343966.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210617220542688.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210617220542688.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210617220811295.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210617220811295.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210617230304263.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210617230304263.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210620214025500.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210620214025500.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210620214101363.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210620214101363.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210623011547211.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210623011547211.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210623011723074.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210623011723074.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210623165734882.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210623165734882.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210623215619574.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210623215619574.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210623215725958.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210623215725958.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210625024426055.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210625024426055.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210625024752763.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210625024752763.png -------------------------------------------------------------------------------- /重构你的C++知识体系.assets/image-20210625025022609.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eished/C-CPP/a75d6a7d2efc490803d3094de7680f795f1a4f00/重构你的C++知识体系.assets/image-20210625025022609.png --------------------------------------------------------------------------------