⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getchegm.cpp

📁 C++的常用算法
💻 CPP
字号:
//这个程序在本书所带软盘中,文件名为GETCHEGM.CPP
//这个程序用getche()进行单个字符的非缓冲式输入。

#include <iostream.h>
#include <conio.h>
#include <time.h>

void main(void)
{
	time_t  start_time, current_time;
	char    ch1, ch2, ch3, ch4, ch5;

	cout << "这个程序用来判断你的记忆力。" << endl;
    cout << "首先注意记住在屏幕上显示的五个字符,它们只显示一秒钟..." << endl;
	cout << "然后,这个程序将要求你按次序分别输入这五个字符..." << endl;
	cout << "最后,程序将把你输入的字符与计算机要求的字符显示到屏幕上..." << endl;
	cout << "如果你的输入全部正确  -- 你有超常的记忆力!!!" << endl;
	cout << "如果你的输入错了一个  -- 你有很好的记忆力!!" << endl;
	cout << "如果你的输入错了两个  -- 你的记忆力正常。" << endl;
	cout << "你的输入错了三个以上  -- 需要进行记忆锻炼..." << endl;
	cout << endl << "注意, 按任意一个键开始..." << endl;

	ch1 = getche();             //暂时存放用户按下的开始键
	cout << "yvzjq" << endl;

	time(&start_time);          //把系统当前时间记录到时间变量start_time中
	do {                        //此循环不断把系统当前时间记录到current_time
	    time(&current_time);    //中,并与start_time 的值比较,如果它们的差<1,
	} while ((current_time - start_time) < 1);  //将继续循环,否则跳出循环

	clrscr();					//清空屏幕

	cout << endl << "第一个字符是:";
	ch1 = getche();
	cout << endl << "第二个字符是:";
	ch2 = getche();
	cout << endl << "第三个字符是:";
	ch3 = getche();
	cout << endl << "第四个字符是:";
	ch4 = getche();
	cout << endl << "最后一个字符是:";
	ch5 = getche();

	cout << endl << "计算机显示的五个字符是:" << "yvzjq" << endl;
	cout << "你输入的五个字符是:" << ch1 << ch2 << ch3 << ch4 << ch5 << endl;
	cout << endl << "欢迎你再次使用。" << endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -