C++小助手1.0.3

去看新版

C++小助手1.0.3-CSDN博客

大更啦大更啦!!!

此系列时隔多年终于迎来大更!!!(bushi

当然,没有你们想象的那么多。

小助手代码

#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>

using namespace std;

// 显示带有动画效果的文本
void ccc(const string &s, int delay = 50)
{
	for (char c : s)
	{
		cout << c;
		Sleep(delay);
	}
	cout << endl;
}

// 加密字符串(简单的移位加密)
string encrypt(string str, int shift = 4)
{
	for (char &c : str)
	{
		c += shift;
	}
	return str;
}

// 解密字符串
string decrypt(string str, int shift = 4)
{
	for (char &c : str)
	{
		c += shift;
		if (c > '9')
			c = 0;
	}
	return str;
}

// 保存用户名和密码到文件
void saveUser(const string &username, const string &password)
{
	ofstream file("users.txt", ios::app);
	if (file.is_open())
	{
		file << username << " " << encrypt(password) << endl;
		file << "已经经过加密!";
		file.close();
	}
	else
	{
		ccc("无法打开用户文件进行写入!请检查文件权限或磁盘空间。");
	}
}

// 检查用户名和密码是否存在并正确
bool authenticateUser(const string &username, const string &password)
{
	ifstream file("users.txt");
	if (!file.is_open())
	{
		ccc("无法打开用户文件进行读取!请检查文件是否存在或权限是否正确。");
		return false;
	}

	string savedUsername, savedPassword;
	while (file >> savedUsername >> savedPassword)
	{
		if (savedUsername == username && savedPassword == encrypt(password))
		{
			return true;
		}
	}
	return false;
}

// 检查用户名是否已存在
bool isUsernameExists(const string &username)
{
	ifstream file("users.txt");
	if (!file.is_open())
	{
		return false;
	}

	string savedUsername, savedPassword;
	while (file >> savedUsername >> savedPassword)
	{
		if (savedUsername == username)
		{
			return true;
		}
	}
	return false;
}

// 注册新用户
void registerUser()
{
	string username, password;
	ccc("请输入要注册的用户名:");
	cin >> username;
	while (isUsernameExists(username))
	{
		ccc("该用户名已存在,请重新输入。");
		cin >> username;
	}
	while (true)
	{
		ccc("请输入要注册的密码:");
		char ch;
		password = "";
		while ((ch = _getch()) != '\r')
		{
			if (ch == '\b')
			{
				if (!password.empty())
				{
					cout << "\b \b";
					password.pop_back();
				}
			}
			else
			{
				cout << '*';
				password += ch;
			}
		}
		cout << endl;
		ccc("请再次输入密码确认:");
		string confirmPassword = "";
		while ((ch = _getch()) != '\r')
		{
			if (ch == '\b')
			{
				if (!confirmPassword.empty())
				{
					cout << "\b \b";
					confirmPassword.pop_back();
				}
			}
			else
			{
				cout << '*';
				confirmPassword += ch;
			}
		}
		cout << endl;
		if (password == confirmPassword)
		{
			break;
		}
		else
		{
			ccc("两次输入的密码不一致,请重新输入。");
		}
	}
	saveUser(username, password);
	ccc("注册成功!");
	Sleep(2000);
}

// 显示菜单
void showMenu()
{
	ccc("欢迎使用小助手APP!");
	ccc("1. 打开网站");
	ccc("2. 显示北京时间");
	ccc("3. 简单计算器");
	ccc("4. 记事本");
	ccc("5. 温度转换");
	ccc("6. 打开 U 盘");
	ccc("7. 猜数游戏");
	ccc("8. 退出");
}

// 处理打开网站功能
void openWebsite()
{
	ccc("输入网站名:");
	string s;
	cin >> s;
	map<string, string> websites =
	{
		{"YLCZ", "https://ylcz.top/"},
		{"百度", "https://www.baidu.com/"},
		{"CSDN", "https://www.csdn.net/"},
		{"洛谷", "https://www.luogu.com/"},
		{"上海月赛", "https://iai.sh.cn/"},
		{"CHATGPT", "http://ai.qujiami.cn/"}
	};

	if (websites.count(s))
	{
		system(("start " + websites[s]).c_str());
	}
	else
	{
		ccc("啊哦,暂时没有这个网站呢TAT");
	}
}

// 处理时间显示功能
void showTime()
{
	SYSTEMTIME time;
	while (true)
	{
		GetLocalTime(&time);
		printf("%04d/%02d/%02d %02d:%02d:%02d\n", time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond);
		Sleep(1000);
		system("cls");
	}
}

// 处理简单计算器功能
void calculator()
{
	ccc("简单计算器:");
	double num1, num2;
	char op;
	ccc("请输入计算 (如: 1 + 1): ");
	cin >> num1 >> op >> num2;

	double result;
	switch (op)
	{
		case '+':
			result = num1 + num2;
			break;
		case '-':
			result = num1 - num2;
			break;
		case '*':
			result = num1 * num2;
			break;
		case '/':
			if (num2 != 0)
			{
				result = num1 / num2;
			}
			else
			{
				ccc("除数不能为零!");
				return;
			}
			break;
		default:
			ccc("无效的操作符!");
			return;
	}
	cout << "结果是: " << result << endl;
	Sleep(2000);
}

// 处理记事本功能
void notepad()
{
	ccc("记事本功能:");
	ccc("请输入内容,输入 'exit' 保存并退出:");
	string line;
	ofstream file("notepad.txt", ios::app);
	if (!file.is_open())
	{
		ccc("无法打开记事本文件进行写入!请检查文件权限或磁盘空间。");
		return;
	}

	cin.ignore(); // 清除之前的换行符
	while (true)
	{
		getline(cin, line);
		if (line == "exit")
		{
			break;
		}
		file << line << endl;
	}
	file.close();
	ccc("内容已保存到 notepad.txt");
	Sleep(2000);
}

// 打开 U 盘功能
void openUplate()
{
	ccc("请输入 U 盘的驱动器号(例如:E:):");
	string driveLetter;
	cin >> driveLetter;
	if (driveLetter.length() == 2 && driveLetter[1] == ':')
	{
		string command = "start " + driveLetter + "\\";
		system(command.c_str());
	}
	else
	{
		ccc("无效的驱动器号!");
	}
}

// 处理温度转换功能
void temperatureConverter()
{
	ccc("温度转换 (摄氏度<->华氏度):");
	ccc("请输入温度值和单位(C/F),例如 32 C 或 100 F:");
	double temp;
	char unit;
	cin >> temp >> unit;

	if (unit == 'C' || unit == 'c')
	{
		double f = temp * 9 / 5 + 32;
		cout << temp << " C = " << f << " F" << endl;
	}
	else if (unit == 'F' || unit == 'f')
	{
		double c = (temp - 32) * 5 / 9;
		cout << temp << " F = " << c << " C" << endl;
	}
	else
	{
		ccc("无效的温度单位!");
	}
	Sleep(2000);
}

// 猜数游戏功能
void guessNumberGame()
{
	srand(static_cast<unsigned int>(time(nullptr)));
	int targetNumber = rand() % 100 + 1;
	int guess;
	int attempts = 0;
	ccc("欢迎来到猜数游戏!我已经想好了一个 1 到 100 之间的数字,你来猜猜看。");
	do
	{
		ccc("请输入你的猜测(1-100):");
		cin >> guess;
		attempts++;
		if (guess < targetNumber)
		{
			ccc("你的猜测太小了!");
		}
		else if (guess > targetNumber)
		{
			ccc("你的猜测太大了!");
		}
		Sleep(2500);
		system("cls");
	}
	while (guess != targetNumber);
	ccc("恭喜你猜对了!你用了" + to_string(attempts) + "次。");
	Sleep(2000);
}

// 主函数
int main()
{
	int a;
	ccc("Welcome!");
	ccc("By XuJunRui");
	Sleep(3000);

	string name, password, choice;

	while (true)
	{
		system("cls");
		cout << "_________________________" << endl;
		cout << "|                       |" << endl;
		cout << "|                       |" << endl;
		cout << "|       登录/注册       |" << endl;
		cout << "|                       |" << endl;
		cout << "|_______________________|" << endl;
		ccc("1. 登录");
		ccc("2. 注册");
		cin >> choice;

		if (choice == "1")
		{
			ccc("请输入用户名:");
			cin >> name;
			ccc("请输入密码:");
			char ch;
			password = "";
			while ((ch = _getch()) != '\r')
			{
				if (ch == '\b')
				{
					if (!password.empty())
					{
						cout << "\b \b";
						password.pop_back();
					}
				}
				else
				{
					cout << '*';
					password += ch;
				}
			}
			cout << endl;

			if (authenticateUser(name, password))
			{
				ccc("登录成功!");
				Sleep(1000);
				system("cls");

				while (true)
				{
					showMenu();
					cin >> a;
					system("cls");

					switch (a)
					{
						case 1:
							openWebsite();
							break;
						case 2:
							showTime();
							break;
						case 3:
							calculator();
							break;
						case 4:
							notepad();
							break;
						case 5:
							temperatureConverter();
							break;
						case 6:
							openUplate();
							break;
						case 7:
							guessNumberGame();
							break;
						case 8:
							ccc("再见!");
							return 0;
						default:
							ccc("无效选项,请重新选择。");
							break;
					}
					system("cls");
				}
			}
			else
			{
				ccc("用户名或密码错误!");
				Sleep(2000);
			}
		}
		else if (choice == "2")
		{
			registerUser();
		}
		else
		{
			ccc("无效选项,请重新选择。");
			Sleep(2000);
		}
	}

	return 0;
}

更新日志:

1.0.0   小助手出现了
1.0.1   新增"打开U盘"功能
1.0.2   解决了"打开U盘"功能中"找不到此驱动"的现象
1.0.3   1、打开小助手页面更新了
           2、增加了"猜数游戏"功能
           3、在输入密码时变成"*",保证了隐蔽性
           4、保证了不会有重复账户
           5、在"users"(账户保存文件)中,将密码进行加密
           6、修复了已知bug
xdown1.0.3.是一个下载工具。它是一个经过优化和改进的版本,旨在提供更好的下载体验和更高的下载速度。xdown1.0.3.具有多个功能和特点,使得用户可以更方便地下载他们需要的文件。 首先,xdown1.0.3.具有简单直观的用户界面,使得用户可以轻松使用。它提供了各种选择,包括下载文件的不同格式和类型。用户只需输入下载链接或浏览所需文件的位置,然后点击下载按钮即可开始下载。界面上的进度条可以让用户清楚地了解下载进度。 其次,xdown1.0.3.支持断点续传功能,即使在下载过程中遇到网络中断或其他问题,用户也可以在修复问题后继续下载。这个功能对于大型文件的下载非常有帮助,用户不需要重新开始下载整个文件,而只需要从中断的地方继续下载。 此外,xdown1.0.3.还提供了下载速度的优化功能。它可以自动检测用户的网络速度和连接质量,并采取相应的优化措施来提高下载速度。如果用户的网络速度较慢,xdown1.0.3.可以使用多个终端来同时下载文件,以加快下载速度。 总之,xdown1.0.3.是一个功能强大的下载工具,可以为用户提供更好的下载体验。它具有简单易用的界面,支持断点续传和下载速度优化,可以满足用户下载文件的不同需求。无论是下载小型文件还是大型文件,xdown1.0.3.都能提供快速和可靠的下载服务。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值