注释转换<C注释-->C++注释>

# 本篇博客为简单的注释转换实现,功能为将简单的C注释段落转换为CPP注释



@ 注意: 代码中所用到的fopen,fwrite,fread等文件操作函数在通讯录文件流博客中做了介


@ ungetc 函数是将从文件中读取的一个字符还回到缓冲区,即文件中去;

@ 分析思路图

@分析思路图

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#include <iostream> #include <ctime> using namespace std; struct userNode { int key; bool sex; int birthday; struct userNode *next = NULL; }; userNode *HashTable[288]; int Hash(int key) { int res = 0; while (key) { res += key % 100; key /= 100; } return res - 10; } userNode *Login(int key) { int afterHash = Hash(key); userNode *p = HashTable[afterHash]; while (p && p->key != key) { p = p->next; } if (p && (p->key == key)) { return p; } else { return NULL; } return NULL; } int Register(userNode *newUser) { int afterHash = Hash(newUser->key); // userNode p = HashTable[afterHash]; // while (p) // { // p = p->next; // } newUser->next = HashTable[afterHash]; HashTable[afterHash] = newUser; return 0; } int main() { userNode nowTmp; int tmp; while (1) { system("cls"); cout << "请输入你的PP号:" << endl; tmp=0; while (tmp<100000 || tmp>999999) { cin >> tmp; } nowTmp = Login(tmp); if (nowTmp) { system("cls"); cout << "-------------------------------------------" << endl << "| 登录成功! |" << endl << "| PP号:" << nowTmp->key << " |" << endl << "| 性别:" << (nowTmp->sex ? "男" : "女") << " |" << endl << "| 生日:" << nowTmp->birthday << " |" << endl << "-------------------------------------------" << endl; system("pause"); } else { // 自动注册 srand(time(0)); nowTmp = new userNode; nowTmp->key=tmp; nowTmp->birthday= 2002 + rand() % 21; nowTmp->birthday=100; nowTmp->birthday+= 1 + rand() % 12; nowTmp->birthday=100; nowTmp->birthday+= 1 + rand() % 28; nowTmp->sex= rand() % 2; Register(nowTmp); cout << "这个PP号还没注册!帮你注册了!请重新登录!" << endl; system("pause"); } } //散列情况展示部分 // int a[288]; // for (int i = 0; i <= 287; i++) // { // a[i]=0; // } // for (int i = 100000; i <= 999999; i++) // { // a[Hash(i)]++; // } // for (int i = 0; i <= 287; i++) // { // cout<<"a["<<i<<"]="<<a[i]<<endl; // } return 0; }写注释
06-08
好的,以下是代码的注释: ```c++ #include <iostream> #include <ctime> // 用于获取系统时间 using namespace std; // 定义用户结构体 struct userNode { int key; // 用户的PP号 bool sex; // 用户性别,true表示男,false表示女 int birthday; // 用户生日,格式为YYYYMMDD struct userNode *next = NULL; // 用于解决哈希冲突的指针 }; userNode *HashTable[288]; // 定义哈希表,大小为288,即0~287 // 哈希函数,将给定的key映射到哈希表中的位置 int Hash(int key) { int res = 0; while (key) { res += key % 100; // 取key的后两位进行累加 key /= 100; // 将key的后两位去掉 } return res - 10; // 避免哈希值为负数 } // 登录函数,根据给定的PP号查找用户信息 userNode *Login(int key) { int afterHash = Hash(key); // 计算哈希值 userNode *p = HashTable[afterHash]; // 指向该位置的第一个用户 while (p && p->key != key) { // 没有到达链表尾部且没有找到指定的用户 p = p->next; // 指向下一个用户 } if (p && (p->key == key)) { // 找到了指定的用户 return p; } else { // 没有找到指定的用户 return NULL; } return NULL; } // 注册函数,将给定的新用户加入哈希表 int Register(userNode *newUser) { int afterHash = Hash(newUser->key); // 计算哈希值 newUser->next = HashTable[afterHash]; // 将新用户插入到该位置的链表头部 HashTable[afterHash] = newUser; return 0; } int main() { userNode nowTmp; // 用于保存当前登录的用户信息 int tmp; // 用于保存用户输入的PP号 while (1) { // 无限循环,直到用户主动退出 system("cls"); // 清屏 cout << "请输入你的PP号:" << endl; tmp=0; // 将tmp初始化为0 while (tmp<100000 || tmp>999999) { // 判断用户输入的PP号是否合法 cin >> tmp; } nowTmp = Login(tmp); // 尝试登录 if (nowTmp) { // 登录成功 system("cls"); cout << "-------------------------------------------" << endl << "| 登录成功! |" << endl << "| PP号:" << nowTmp->key << " |" << endl << "| 性别:" << (nowTmp->sex ? "男" : "女") << " |" << endl << "| 生日:" << nowTmp->birthday << " |" << endl << "-------------------------------------------" << endl; system("pause"); } else { // 登录失败,自动注册 srand(time(0)); // 用系统时间作为随机数的种子 nowTmp = new userNode; // 创建新用户 nowTmp->key=tmp; // 将PP号赋值给新用户 nowTmp->birthday= 2002 + rand() % 21; // 生成随机的出生年份 nowTmp->birthday=100; // 这里应该是nowTmp->birthday +=,而不是nowTmp->birthday= nowTmp->birthday+= 1 + rand() % 12; // 生成随机的出生月份 nowTmp->birthday=100; // 这里应该是nowTmp->birthday +=,而不是nowTmp->birthday= nowTmp->birthday+= 1 + rand() % 28; // 生成随机的出生日期 nowTmp->sex= rand() % 2; // 生成随机的性别 Register(nowTmp); // 将新用户加入哈希表 cout << "这个PP号还没注册!帮你注册了!请重新登录!" << endl; system("pause"); } } // 下面是用于展示哈希表散列情况的代码,可以暂时忽略 // int a[288]; // for (int i = 0; i <= 287; i++) // { // a[i]=0; // } // for (int i = 100000; i <= 999999; i++) // { // a[Hash(i)]++; // } // for (int i = 0; i <= 287; i++) // { // cout<<"a["<<i<<"]="<<a[i]<<endl; // } return 0; } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值