C++小助手1.0.0

注:

只能在C++6.7.5编译

小助手代码:

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

using namespace std;

// 显示带有动画效果的文本
void ccc(string s)
{
	for (char c : s)
	{
		cout << c;
		Sleep(50);
	}
	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;
	}
	return str;
}
// 保存用户名和密码到文件
void saveUser(const string& username, const string& password)
{
	ofstream file("users.txt", ios::app);
	file << username << " " << encrypt(password) << endl;
	file.close();
}

// 检查用户名和密码是否存在并正确
bool authenticateUser(const string& username, const string& password)
{
	ifstream file("users.txt");
	string savedUsername, savedPassword;
	while (file >> savedUsername >> savedPassword)
	{
		if (savedUsername == username && savedPassword == encrypt(password))
		{
			return true;
		}
	}
	return false;
}

// 注册新用户
void registerUser()
{
	string username, password;
	ccc("请输入要注册的用户名:");
	cin >> username;
	ccc("请输入要注册的密码:");
	cin >> password;
	saveUser(username, password);
	ccc("注册成功!");
	Sleep(2000);
}

// 显示菜单
void showMenu()
{
	ccc("1. 打开网站");
	ccc("2. 北京时间");
	ccc("3. 简单计算器");
	ccc("4. 记事本");
	ccc("5. 温度转换");
	ccc("6. 退出");
}

// 处理打开网站功能
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);

	while (true)
	{
		getline(cin, line);
		if (line == "exit")
			break;
		file << line << endl;
	}
	file.close();
	ccc("内容已保存到 notepad.txt");
	Sleep(2000);
}

// 处理温度转换功能
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);
}
// 主函数
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("请输入密码:");
			cin >> password;

			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:
							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   小助手出现了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值