# 计网编程题作业 **Repository Path**: xuehuixin/network-programming-homework ## Basic Information - **Project Name**: 计网编程题作业 - **Description**: No description available - **Primary Language**: C++ - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-17 - **Last Updated**: 2026-05-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #include #include #include #include using namespace std; void sendBit(int bit) { if (bit == 0) cout << "发送:白光(代表比特 0)" << endl; else cout << "发送:黑光(代表比特 1)" << endl; } int receiveBit() { return rand() % 2; } void sendOctal(int val) { val = val & 7; cout << "发送八进制信号:" << val << endl; } int receiveOctal() { return rand() % 8; } int main() { srand((unsigned)time(NULL)); cout << "===== 可见光通信模拟 =====" << endl; cout << "\n----- 比特传输测试 -----" << endl; vector bits = {1, 0, 1, 1, 0}; for (int b : bits) { sendBit(b); cout << "接收端解码:" << receiveBit() << "\n" << endl; } cout << "\n----- 八进制传输测试 -----" << endl; for (int i = 0; i <= 7; ++i) { sendOctal(i); cout << "接收端解码:" << receiveOctal() << "\n" << endl; } cout << "===== 通信模拟结束 =====" << endl; return 0; }