發表文章

目前顯示的是 7月, 2023的文章

Code Maintenance & Programming Rules

 This guide outlines essential best practices spanning code style, architectural design, debugging, testing, performance, and portability—all aimed at reducing the long-term cognitive load of code maintenance. 🎨 1. Style Code is written for humans to read, and only incidentally for computers to execute. Variable Naming : Use descriptive names for global variables, and short names for local variables. Precision and Consistency : Use active names for functions (e.g., calculateTotal ). Above all, keep your coding style consistent throughout the project. Structure & Expressions : Use a consistent indentation and brace ( {} ) style to show program structure visually. Use the natural form for expressions. Use parentheses to make the semantics unambiguous. Break up overly complex expressions to keep them clear. Side Effects & Macros : Beware of functions with side effects. Avoid function-like macros; if unavoidable, parenthesize the macro body and arguments carefully. Magic Numbe...

C++程式語言陣列與迴圈的應用:MS-DOS Color Background and Text

在 Windows 系統下可以使用system搭配 MS-DOS 的 color 指令(可參考此篇文章 更改 命令提示字元 Command Prompt (cmd) 的顯示顏色 )與 cls 來達成文字顏色的動畫。 color 指令示範影片: C++程式碼: // 陣列與迴圈的應用:MS-DOS Color Background and Text #include <iostream> #include <Windows.h> using namespace std; int main () {     system ( "pause" );     char hex [ 17 ] = "0123456789ABCDEF" ;     char cmd [ 20 ] = "color 00" ;     // bg: backgroud     for ( int bg = 0 ; bg <= 15 ; bg++) {         cmd [ 6 ] = hex [bg];         // fg: foreground         for ( int fg = 0 ; fg <= 15 ; fg++) {             cmd [ 7 ] = hex [fg];             //cout << cmd << endl;             system (cmd);             cout << "YunlinSong" ;             Sleep ( 200 );       ...