C++程序三件套

大家好啊!我是一位2010年的编程爱好者!😆😆😆

 

我又来了!🌈🌈🌈


最近闲着没事,做了几个简单的程序,但都只做了0.000000001点点,最近又好久好久没发文章了,就准备把几个程序的代码挂出来,如果大家有兴趣也可以续写下去,我后面也会抽空更新的。

冒险挖矿[0.7.1版本]

 之前这个游戏做了一点,详解见:

C++冒险挖矿[0.6版本]

C++冒险挖矿[0.7版本]

我改了个小bug,做了一个box()函数,就是优化“空箱子”的,但是box()函数只有一个不算雏形的雏形,还要增加很多代码。

#include <iostream>
#include <fstream>
#include <ctime>
#include <string>
using namespace std;
int planet = 1, depth = 0, coins = 0, pointofskills = 0, playerlifevalue = 10, playeraggressivity = 1, headarmorvalue = 0, bodyarmorvalue = 0, legarmorvalue = 0, check = 1;
string bag[15] = { "" };
int bag_num = 0;
string instructions;
string ordinary_word[10] = { "香蕉皮", "被子", "拖鞋", "手机壳", "垃圾桶", "枯叶", "拉链", "水杯", "玻璃", "镜子" };
int auxiliary = 0;
bool in(string str_chatter, string str_chatterBot)
{
	if (str_chatter.find(str_chatterBot) != string::npos)
	{
		return true;
	}
	else
	{
		return false;
	}
}
void box()
{
	bag[bag_num++] = ordinary_word[rand() % 10];
	return;
}
void rne(int minimum_1_1, int biggest_1_1, int minimum_1_2, int biggest_1_2, int minimum_2_1, int biggest_2_1, int minimum_2_2, int biggest_2_2, int minimum_3_1, int biggest_3_1, int minimum_3_2, int biggest_3_2, int minimum_4, int biggest_4, int monsterhealthvalue, int monsteraggressivity/*金币:1,技能点:2,炸弹:3*/)
{
	auxiliary = rand() % 110;
	if (auxiliary >= minimum_1_1 && auxiliary <= biggest_1_1)
	{
		srand(time(0));
		auxiliary = rand() % (biggest_1_2 - minimum_1_2 + 1) + minimum_1_2;
		cout << "你挖到了" << auxiliary << "个金币。" << endl;
		coins += auxiliary;
	}
	else if (auxiliary >= minimum_2_1 && auxiliary <= biggest_2_1)
	{
		srand(time(0));
		auxiliary = rand() % (biggest_2_2 - minimum_2_2 + 1) + minimum_2_2;
		cout << "你找到了" << auxiliary << "个技能点。" << endl;
		pointofskills += auxiliary;
	}
	else if (auxiliary >= minimum_3_1 && auxiliary <= biggest_3_1)
	{
		srand(time(0));
		auxiliary = rand() % (biggest_3_2 - minimum_3_2 + 1) + minimum_3_2;
		if (auxiliary > coins)auxiliary = coins;
		if (auxiliary == 0)
		{
			box();
		}
		else
		{
			cout << "你踩到了一个炸弹,丢了" << auxiliary << "个金币。" << endl;
			coins -= auxiliary;
		}
	}
	else if (auxiliary >= minimum_4 && auxiliary <= biggest_4)
	{
		if (monsterhealthvalue / playeraggressivity <= (playerlifevalue + headarmorvalue + bodyarmorvalue + legarmorvalue) / monsteraggressivity)
		{
			auxiliary = (monsterhealthvalue / playeraggressivity) * monsteraggressivity - (headarmorvalue + bodyarmorvalue + legarmorvalue);
			if (auxiliary < 0)auxiliary = 0;
			cout << "你遇到了一只怪兽,你杀死了它,获得了" << playerlifevalue + playeraggressivity + headarmorvalue + bodyarmorvalue + legarmorvalue << "个金币,剩余" << playerlifevalue - auxiliary << "点生命。" << endl;
			playerlifevalue -= auxiliary;
			coins += (playerlifevalue + playeraggressivity + headarmorvalue + bodyarmorvalue + legarmorvalue);
		}
		else
		{
			cout << "你在与怪兽战斗时死了。" << endl;
			planet = 1, depth = 0, coins = 0, pointofskills = 0, playerlifevalue = 10, playeraggressivity = 1, headarmorvalue = 0, bodyarmorvalue = 0, legarmorvalue = 0;
		}
	}
	else
	{
		box();
	}
}
void gt(int dplanet)
{
	if (coins >= dplanet * 2000)
	{
		cout << "去" << (dplanet == 1 ? "地球" : "") << (dplanet == 2 ? "月球" : "") << (dplanet == 3 ? "火星" : "") << (dplanet == 4 ? "泰坦星" : "") << (dplanet == 5 ? "金银星" : "") << "需要" << (dplanet == 1 ? "2000" : "") << (dplanet == 2 ? "4000" : "") << (dplanet == 3 ? "6000" : "") << (dplanet == 4 ? "8000" : "") << (dplanet == 5 ? "10000" : "") << "个金币,你有" << coins << "个金币,要前往吗?" << endl;
		cin >> instructions;
		if (in(instructions, "是") || in(instructions, "好") || in(instructions, "要"))
		{
			system("cls");
			coins -= dplanet * 2000;
			planet = dplanet;
			cout << "您已到达" << (planet == 1 ? "地球" : "") << (planet == 2 ? "月球" : "") << (planet == 3 ? "火星" : "") << (planet == 4 ? "泰坦星" : "") << (planet == 5 ? "金银星" : "") << "!" << endl;
		}
		else
		{
			system("cls");
			cout << "好的!" << endl;
		}
	}
	else
	{
		cout << "去" << (dplanet == 1 ? "地球" : "") << (dplanet == 2 ? "月球" : "") << (dplanet == 3 ? "火星" : "") << (dplanet == 4 ? "泰坦星" : "") << (dplanet == 5 ? "金银星" : "") << "需要" << dplanet * 2000 << "个金币,你只有" << coins << "个金币,无法前往!" << endl;
	}
}
void save()
{
	ofstream out("save.dll");
	check = (planet + depth + coins + pointofskills) % (playerlifevalue + playeraggressivity + headarmorvalue + bodyarmorvalue + legarmorvalue);
	out << planet << " " << depth << " " << coins << " " << pointofskills << " " << playerlifevalue << " " << playeraggressivity << " " << headarmorvalue << " " << bodyarmorvalue << " " << legarmorvalue << " " << check;
	out.close();
}
void read()
{
	ifstream in("save.dll");
	in >> planet >> depth >> coins >> pointofskills >> playerlifevalue >> playeraggressivity >> headarmorvalue >> bodyarmorvalue >> legarmorvalue >> check;
	in.close();
	if (check != (planet + depth + coins + pointofskills) % (playerlifevalue + playeraggressivity + headarmorvalue + bodyarmorvalue + legarmorvalue))
	{
		ofstream out("save.dll");
		out.close();
		planet = 1, depth = 0, coins = 0, pointofskills = 0, playerlifevalue = 10, playeraggressivity = 1, headarmorvalue = 0, bodyarmorvalue = 0, legarmorvalue = 0;
		save();
		cout << "呵呵,被发现了吧!我不喜欢作弊的人哦!" << endl;
		system("pause");
		system("cls");
	}
}
int main()
{
	system("color F0");
	srand((unsigned int)time(NULL));
	while (true)
	{
		read();
		cout << "欢迎来到冒险挖矿!" << endl;
		cout << "你现在在" << (planet == 1 ? "地球" : "") << (planet == 2 ? "月球" : "") << (planet == 3 ? "火星" : "") << (planet == 4 ? "泰坦星" : "") << (planet == 5 ? "金银星" : "") << ",挖了" << depth << "米" << ",有" << coins << "个金币" << "和" << pointofskills << "个技能点" << endl;
		cout << "请问你想干什么?" << endl;
		cin >> instructions;
		if (in(instructions, "下") || in(instructions, "左") || in(instructions, "右"))
		{
			if (depth == 0 && (in(instructions, "左") || in(instructions, "右")))
			{
				system("pause");
				system("cls");
				save();
				continue;
			}
			if (in(instructions, "下"))
			{
				depth++;
			}
			if (planet == 1)
			{
				if (depth <= 50)
				{
					rne(1, 70, 1, 10, 71, 80, 1, 10, 81, 95, 1, 10, 96, 100, 2, 1);
				}
				else
				{
					rne(1, 60, 1, 15, 61, 80, 1, 15, 81, 95, 1, 20, 96, 100, 5, 2);
				}
			}
			if (planet == 2)
			{
				if (depth <= 50)
				{
					rne(1, 65, 10, 20, 66, 75, 10, 20, 76, 90, 15, 20, 91, 100, 8, 3);
				}
				else
				{
					rne(1, 60, 10, 25, 61, 75, 10, 25, 76, 90, 20, 30, 91, 100, 10, 3);
				}
			}
			if (planet == 3)
			{
				if (depth <= 50)
				{
					rne(1, 60, 30, 100, 61, 80, 1, 20, 81, 95, 1, 80, 96, 100, 30, 5);
				}
				else
				{
					rne(1, 75, 40, 110, 76, 85, 20, 50, 86, 99, 1, 30, 100, 100, 50, 10);
				}
			}
			if (planet == 4)
			{
				if (depth <= 50)
				{
					rne(1, 60, 55, 120, 56, 65, 30, 60, 66, 80, 50, 100, 81, 100, 100, 15);
				}
				else
				{
					rne(1, 40, 80, 150, 41, 60, 50, 80, 61, 80, 80, 100, 81, 100, 150, 20);
				}
			}
			if (planet == 5)
			{
				if (depth <= 50)
				{
					rne(1, 10, 100, 200, 11, 20, 100, 200, 21, 80, 150, 250, 81, 100, 200, 20);
				}
				else
				{
					rne(1, 10, 150, 250, 11, 20, 150, 250, 21, 80, 200, 400, 81, 100, 500, 100);
				}
			}
		}
		else if (in(instructions, "去"))
		{
			if (in(instructions, "地球"))
			{
				if (planet == 1)
				{
					cout << "你已经在地球了哦!" << endl;
				}
				else
				{
					system("cls");
					gt(1);
				}
			}
			if (in(instructions, "月球"))
			{
				if (planet == 2)
				{
					cout << "你已经在月球了哦!" << endl;
				}
				else
				{
					system("cls");
					gt(2);
				}
			}
			if (in(instructions, "火星"))
			{
				if (planet == 3)
				{
					cout << "你已经在火星了哦!" << endl;
				}
				else
				{
					system("cls");
					gt(3);
				}
			}
			if (in(instructions, "泰坦星"))
			{
				if (planet == 4)
				{
					cout << "你已经在泰坦星了哦!" << endl;
				}
				else
				{
					system("cls");
					gt(4);
				}
			}
			if (in(instructions, "金银星"))
			{
				if (planet == 5)
				{
					cout << "你已经在金银星了哦!" << endl;
				}
				else
				{
					system("cls");
					gt(5);
				}
			}
		}
		else if (in(instructions, "抹掉"))
		{
			cout << "确定要抹掉存档吗?" << endl;
			cin >> instructions;
			if (in(instructions, "是") || in(instructions, "好") || in(instructions, "要"))
			{
				ofstream in("save.dll");
				in.close();
				planet = 1, depth = 0, coins = 0, pointofskills = 0, playerlifevalue = 10, playeraggressivity = 1, headarmorvalue = 0, bodyarmorvalue = 0, legarmorvalue = 0;
				save();
				cout << "已抹掉!" << endl;
			}
			system("pause");
			system("cls");
			continue;
		}
		else if (in(instructions, "帮助"))
		{
			cout << "一.关键词" << endl;
			cout << "1.向下、向左、向右:下、左、右" << endl;
			cout << "2.去某个星球:去(哪里,星球分别有地球、月球、火星、泰坦星、金银星,此处按危险程度排序,在越危险的地方遇到金币,金币将会更多)" << endl;
			cout << "3.抹掉存档:抹掉" << endl;
			cout << "4.确认:是、好、要\t取消:其它短语均可" << endl;
			cout << "5.帮助:帮助" << endl;
			cout << "6.输入无关内容,将跳过" << endl;
			cout << "二.关于挖矿" << endl;
			cout << "1.在第0米处只能往下挖" << endl;
			cout << "三.其它" << endl;
			cout << "1.游戏将自动保存!" << endl;
		}
		system("pause");
		system("cls");
		save();
	}
}

 学生管理系统[0.5版本]

这个程序是觉得好玩做的,接下来要做的是成绩录入。

class.h:

#pragma once
#include<string>
struct Stu {
public:
	std::string Name;
	int Id;
	int Gen;//1男2女
	std::string Sub[15] = { "语文",
							"数学",
							"英语",
							"政治",
							"地理",
							"物理",
							"化学",
							"生物",
							"体育",
							"音乐",
							"美术",
							"计算机"};
	int Ach[15][100][2];//Full Act
};
struct Cla {
public:
	float Cla;
	Stu stu[100];
	int Num;
	std::string Tea[15][2] = { "语文","",
							   "数学","",
							   "英语","",
							   "政治","",
							   "地理","",
							   "物理","",
							   "化学","",
							   "生物","",
							   "体育","",
							   "音乐","",
							   "美术","",
							   "计算机",""};
	int SubNum = 0;
};

main.cpp:

#include<iostream>
#include<conio.h>
#include<fstream>
#include<Windows.h>
#include"class.h"
using namespace std;
bool init;
string s;
Cla cla;
int m, n;
void Read();
void Save();
void Init();
void Menu();
void SetPos(short int h, short int l);
void Print();
int main() {
	Read();
	while (1) {
		Menu();
		Save();
	}
	return 0;
}
void Init() {
	cout << "欢迎使用蒲公英学生管理系统!" << endl;
	Sleep(2000);
	cout << "请按提示完成班级信息初始化!" << endl;
	Sleep(2000);
	cout << "请输入班级(如5.1,代表5年级1班):";
	cin >> cla.Cla;
	system("cls");
	for (int i = 0; i < 12; i++) {
		cout << "请输入" << cla.Tea[i][0] << "老师姓名(如需跳过,输入-1即可):";
		cin >> cla.Tea[i][1];
		if ("-1" == cla.Tea[i][1]) {
			cla.Tea[i][1] = "暂未开设";
		}
		system("cls");
	}
Num:
	cout << "请输入班级人数:";
	cin >> cla.Num;
	if (cla.Num > 100) {
		cout << "抱歉!一个班级最多100人!请重新输入!" << endl;
		system("pause");
		system("cls");
		goto Num;
	}
	cout << "请依次录入学生信息!" << endl;
	Sleep(2000);
	FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
	for (int i = 1; i <= cla.Num; i++) {
		system("cls");
		cout << "学号:" << i << endl;
		cla.stu[i - 1].Id = i;
		cout << "姓名:";
		cin >> cla.stu[i - 1].Name;
		cout << "性别(男或女):";
		cin >> s;
		if ("男" == s)cla.stu[i - 1].Gen = 1;
		else if ("女" == s)cla.stu[i - 1].Gen = 2;
	}
	system("cls");
	return;
}
void Read() {
	ifstream in("save.txt");
	in >> init;
	if (!init) {
		in.close();
		Init();
	}
	in >> cla.Cla;
	for (int i = 0; i < 12; i++) {
		in >> cla.Tea[i][1];
	}
	in >> cla.Num;
	for (int i = 1; i <= cla.Num; i++) {
		in >> cla.stu[i - 1].Id >> cla.stu[i - 1].Name >> cla.stu[i - 1].Gen;
	}
	in.close();
	return;
}
void Save() {
	ofstream out("save.txt");
	out << 1 << endl << cla.Cla << endl;
	for (int i = 0; i < 12; i++) {
		out << cla.Tea[i][1] << endl;
	}
	out << endl << cla.Num << endl;
	for (int i = 1; i <= cla.Num; i++) {
		out << cla.stu[i - 1].Id << endl << cla.stu[i - 1].Name << endl << cla.stu[i - 1].Gen << endl;
	}
	out.close();
	return;
}
void Menu() {
	cout << "---------------------------------------------------蒲公英学生管理系统---------------------------------------------------";
	cout << "|                                                                                                                      |";
	cout << "|                                                     1、查看学生                                                      |";
	cout << "|                                                     2、管理学生                                                      |";
	cout << "|                                                     3、录入成绩                                                      |";
	cout << "|                                                                                                                      |";
	cout << "------------------------------------------------------------------------------------------------------------------------";
	n = _getch();
	system("cls");
	if ('1' == n) {
		Print();
	}
	else if ('2' == n) {
		cout << "请问您要对学生进行什么操作?\n1、修改\n2、删除\n3、增加\n0、退出" << endl;
		cin >> n;
		system("cls");
		if (0 == n) {
			return;
		}
		else if (1 == n) {
			Print();
			cout << "请输入学生学号:";
			cin >> n;
			cout << "请输入姓名:";
			cin >> cla.stu[n - 1].Name;
			cout << "请输入性别:";
			cin >> s;
			if ("男" == s)cla.stu[n - 1].Gen = 1;
			else if ("女" == s)cla.stu[n - 1].Gen = 2;
			cout << "修改成功!" << endl;
		}
		else if (2 == n) {
			Print();
			cout << "请输入学生学号:";
			cin >> n;
			cla.Num--;
			for (int i = n; i < n; i++) {
				cla.stu[i - 1].Name = cla.stu[i].Name;
				cla.stu[i - 1].Gen = cla.stu[i].Gen;
			}
			cout << "删除成功!" << endl;
		}
		else if (3 == n) {
			if (100 == cla.Num) {
				cout << "抱歉!一个班级最多100人!" << endl;
			}
			else {
				cout << "请输入姓名:";
				cin >> cla.stu[cla.Num].Name;
				cout << "请输入性别:";
				cin >> s;
				if ("男" == s)cla.stu[cla.Num].Gen = 1;
				else if ("女" == s)cla.stu[cla.Num].Gen = 2;
				cla.Num++;
				cla.stu[cla.Num].Id = cla.Num;
			}
		}
	}
	else if ('3' == n) {
		cout << "请选择科目:" << endl;
		cout << "1、语文\n2、数学\n3、英语\n4、政治\n5、地理\n6、物理\n7、化学\n8、生物\n9、体育\n10、音乐\n11、美术\n12、计算机\n";
		cin >> n;
	}
	system("pause");
	system("cls");
}
void SetPos(short int h, short int l) {
	COORD pos = { l - 1,h - 1 };
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(hOut, pos);
	return;
}
void Print() {
	cout << "学号        姓名        性别" << endl;
	for (int i = 0; i < cla.Num; i++) {
		if (1 == cla.stu[i].Gen)s = "男";
		else if (2 == cla.stu[i].Gen)s = "女";
		SetPos(i + 2, 1);
		cout << i + 1;
		SetPos(i + 2, 13);
		cout << cla.stu[i].Name;
		SetPos(i + 2, 25);
		cout << s;
	}
	cout << endl;
}

地球模拟器[0.2版本] 

这个游戏才做了一点,把框架给做了。代码如下:

#include<iostream>
#include<math.h>
#include<thread>
#include<string>
#include<Windows.h>
#include<tchar.h>
#include<fstream>
#include<conio.h>
using namespace std;

struct God{
	int happypoint = 100;
	int point = 0;
	int level = 0;
}god;
struct Earth {
	struct Biology {
		int num = 0;
		string name = "";
	}biology[100] = {};
	int biologynum = 0;
}earth;

bool isinit;
int n;
void BOOM() {
	for (int i = 0; i < 8; i++) {
		system("color 41");
		Sleep(80);
		system("color 14");
		Sleep(80);
	}
	return;
}
void out(string s){
	srand((unsigned int)time(NULL));
	for (int i = 0; i < s.length(); i++)
	{
		cout << s[i];
		Sleep(rand()%51+50);
	}
	return;
}
void out(int n) {
	srand((unsigned int)time(NULL));
	int length = 0, temp = n;
	for (int i = 1; i *= 10; (temp / i % 10 > 0)) {
		if (temp / i % 10 > 0)length++;
	}
	for (int i = int(pow(10, length)); i > 0; i /= 10) {
		cout << n / i % 10;
		Sleep(rand() % 51 + 50);
	}
	return;
}
void read() {
	ifstream in("save.txt");
	in >> isinit;
	in.close();
	return;
}
void save() {
	ofstream out("save.txt");
	out << isinit;
	out.close();
	return;
}
void init() {
	out("该游戏纯属虚构,不喜勿喷!");
	Sleep(1000);
	system("cls");
	out("你是上帝……\n");
	thread t1(BOOM);
	t1.detach();
	out("BOOM——你被宇宙大爆炸炸死了……\n");
	out("(导演:诶诶诶,看一下剧本!!!)\n");
	out("额,对不起,重来!\n");
	Sleep(2000);
	system("color F0");
	system("cls");
	out("你是上帝……\n");
	out("BOOM——你没被宇宙大爆炸炸死……\n");
	out("你发现了一颗适合生物生存的星球——地球……\n");
	isinit = 1;
	save();
	return;
}
void game() {
	while (1) {
		system("cls");
		cout << "你现在有" << god.happypoint << "个幸福点。" << endl;
		cout << "1、添加生物" << endl;
		if ('1' == _getch()) {
			system("cls");
			for (int i = 0; i < earth.biologynum; i++) {
				out(i + 1); out("、"); out(earth.biology[i].name.c_str()); out("\n");
			}
			cin >> n;
			for (int i = 0; i < earth.biologynum; i++) {
				if (i + 1 == n) {
					if (god.happypoint > earth.biology[i].num * (i + 1) + 1) {
						out("增加"); out(earth.biology[i].name); out("需要"); out(earth.biology[i].num * (i + 1) + 1); out("幸福点,是否增加?(y/n)\n");
						if ('y' == _getch()) {
							earth.biology[i].num++;
							god.happypoint -= earth.biology[i].num * (i + 1) + 1;
							out("已添加"); out(earth.biology[i].name); out("\n");
							save();
						}
						else if ('n' == _getch()) {
							out("好的!");
						}
						else {
							MessageBox(NULL, _T("请勿乱输"),_T("地球模拟器"), MB_OK);
						}
					}
					else {
						out("你没有那么多钱!");
					}
				}
			}
		}
	}
	return;
}
int main() {
	earth.biologynum = 1;
	earth.biology[0].name = "兔子";
	system("color F0");
	read();
	if(!isinit)init();
	game();
	return 0;
}

好了今天就到这里了!还请大家多多指教!互关必回!🙏🙏🙏

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

H.Y_C ⁹⁹⁹⁹⁹⁹⁺

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值