《c++做好玩的机房小程序》
其实刚开始学c++的时候,我也很纳闷,难道他就只能用来比赛吗?
所以我搞了一些创新的程序,如
打字通
迷宫
等等之类的,接下来我会一步步教你做出这些小程序
我要做的是打字通
首先,需要用的头文件挺多的,如下
#include
#include
#include
#include
#include
#include 接下来,我们来构思一波程序
打字打字那得有字打吗!
所以
char article[1000] = {"......"};//文章,我之后会简写成a 然后,我们弄一个输入文章编号和开始界面
cout << "输入你要打哪篇文章";
bool t;
char s;
s = _getch();//输入文章编号
t = true;
if(s == '1'){t = true;//判断是否输入if(t == true){system("cls");//清屏cout << "文章1:"; for(int i = 0;i < 16;i++){cout<< a1[i]; //输出文章}}
} 然后学习一个计时的代码(我也不会(doge)
clock_t start,end;//定义开始和结束时间
start = clock();//开始计时
......
end = clock();//结束计时
double endtime=(double)(end-start)/CLOCKS_PER_SEC;//计算时间 弄一个输入文章
if(s == '1'){t = true;if(t == true){system("cls");cout << "文章1:"; for(int i = 0;i < 文章字数;i++){cout<< a1[i]; }}cout << endl<< "input:"<< endl;start=clock();for(int j = 0;j < 文章字数;j++){ch[j] = _getch();(int)ch[j];//将char变量转化为int类型if(ch[j] != 8){//识别退格符cout << ch[j];}else{printf("%c", e);printf(" \b");j--;ch[j]=_getch();cout << ch[j];}if(ch[j] != a1[j]&&ch[j]!=8){sum++;system("color 40");//如果输入错误就改颜色}else{system("color 20");//如果输入正确就改颜色}if(ch[j] == '@'){system("cls");//清屏cout << "你已退出打字,不保存进度";return 0;}}end=clock();double endtime=(double)(end-start)/CLOCKS_PER_SEC;cout << endl<< "用时" << endtime<< "s"<< endl<< "此文章共n个字符,累计输入错误"<< sum<< "字";s = _getch();t = true;if(t == true){return 0;}//结束程序}else if(s != '1'){system("cls");system("title wrong");cout <<"wrong: can't find the article"<< s<< endl<< endl<< endl<< endl<< endl;return 0;}//如果找不到文章就结束程序 1.0版本就好了
#include
#include
#include
#include
#include
#include
using namespace std;
clock_t start,end;
int main(){system("title dzt");//更改输入栏标题char a1[100] = "i love this app";cout << "输入你要打哪篇文章,如在打字过程中想退出打文章,输入“@ ”";bool t;int n;int e = 8;int sum = 0;//求和 char s;char ch[100];//inputs = _getch();if(s == '1'){t = true;if(t == true){system("cls");cout << "文章1:"; for(int i = 0;i < 16;i++){cout<< a1[i]; }}cout << endl<< "input:"<< endl;start=clock();for(int j = 0;j<15;j++){ch[j] = _getch();(int)ch[j];if(ch[j] != 8){cout << ch[j];}else{printf("%c", e);printf(" \b");j--;ch[j]=_getch();cout << ch[j];}if(ch[j] != a1[j]&&ch[j]!=8){sum++;system("color 40");}else{system("color 20");}if(ch[j] == '@'){system("cls");cout << "你已退出打字,不保存进度";return 0;}}end=clock();double endtime=(double)(end-start)/CLOCKS_PER_SEC;cout << endl<< "用时" << endtime<< "s"<< endl<< "此文章共16个字符,累计输入错误"<< sum<< "字";s = _getch();t = true;if(t == true){return 0;}}else if(s != '1'){system("cls");system("title wrong");cout <<"wrong: can't find the article"<< s<< endl<< endl<< endl<< endl<< endl;}
return 0;
}
—————————————————————————————————————————————————————————————————————————
《小白在此》原创哦 c++打字通1.0版本成功运行!!!
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
