Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Hly-123 authored Nov 3, 2021
1 parent de25fe9 commit c422d09
Show file tree
Hide file tree
Showing 25 changed files with 499 additions and 0 deletions.
Binary file added 算法控制系统/Debug/算法控制系统.exe
Binary file not shown.
Binary file added 算法控制系统/Debug/算法控制系统.ilk
Binary file not shown.
Binary file added 算法控制系统/Debug/算法控制系统.pdb
Binary file not shown.
31 changes: 31 additions & 0 deletions 算法控制系统/算法控制系统.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.539
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "算法控制系统", "算法控制系统\算法控制系统.vcxproj", "{9BC10348-13DA-4763-992D-0A4359D78CA8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9BC10348-13DA-4763-992D-0A4359D78CA8}.Debug|x64.ActiveCfg = Debug|x64
{9BC10348-13DA-4763-992D-0A4359D78CA8}.Debug|x64.Build.0 = Debug|x64
{9BC10348-13DA-4763-992D-0A4359D78CA8}.Debug|x86.ActiveCfg = Debug|Win32
{9BC10348-13DA-4763-992D-0A4359D78CA8}.Debug|x86.Build.0 = Debug|Win32
{9BC10348-13DA-4763-992D-0A4359D78CA8}.Release|x64.ActiveCfg = Release|x64
{9BC10348-13DA-4763-992D-0A4359D78CA8}.Release|x64.Build.0 = Release|x64
{9BC10348-13DA-4763-992D-0A4359D78CA8}.Release|x86.ActiveCfg = Release|Win32
{9BC10348-13DA-4763-992D-0A4359D78CA8}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {32F70CDD-4C2C-4E50-8D57-E9F3D07782EE}
EndGlobalSection
EndGlobal
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
e:\卓面备份资料\c++\算法控制系统\算法控制系统\debug\vc141.pdb
e:\卓面备份资料\c++\算法控制系统\算法控制系统\debug\vc141.idb
e:\卓面备份资料\c++\算法控制系统\算法控制系统\debug\算法控制.obj
e:\卓面备份资料\c++\算法控制系统\算法控制系统\debug\函数实现.obj
e:\卓面备份资料\c++\算法控制系统\debug\算法控制系统.ilk
e:\卓面备份资料\c++\算法控制系统\debug\算法控制系统.exe
e:\卓面备份资料\c++\算法控制系统\debug\算法控制系统.pdb
e:\卓面备份资料\c++\算法控制系统\算法控制系统\debug\算法控制系统.tlog\cl.command.1.tlog
e:\卓面备份资料\c++\算法控制系统\算法控制系统\debug\算法控制系统.tlog\cl.read.1.tlog
e:\卓面备份资料\c++\算法控制系统\算法控制系统\debug\算法控制系统.tlog\cl.write.1.tlog
e:\卓面备份资料\c++\算法控制系统\算法控制系统\debug\算法控制系统.tlog\link.command.1.tlog
e:\卓面备份资料\c++\算法控制系统\算法控制系统\debug\算法控制系统.tlog\link.read.1.tlog
e:\卓面备份资料\c++\算法控制系统\算法控制系统\debug\算法控制系统.tlog\link.write.1.tlog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
 算法控制系统.vcxproj -> E:\卓面备份资料\C++\黄林仪 Project1\算法控制系统\Debug\算法控制系统.exe
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.17763.0
Debug|Win32|E:\卓面备份资料\C++\黄林仪 Project1\算法控制系统\|
30 changes: 30 additions & 0 deletions 算法控制系统/算法控制系统/algorithm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include<iostream>
#include<stdlib.h>
#include<conio.h>
#include<ctime>
#include<cmath>
#include<stdio.h>
#define random(a,b) (rand()%(b-a)+a)
using namespace std;

class algorithm
{
private:
int ques_num;
char opera;
double range;
int score;
int right;
int wrong;
double pre_time;
int ans;
double consumeTime;
double allTime;
double thinkTime;

public:
algorithm();
clock_t timekeeper(int ans, double thinkTime, double allTime);
//计时与清屏函数(考虑到未按键盘的思考时间和键入时的作答时间)
~algorithm();
};
251 changes: 251 additions & 0 deletions 算法控制系统/算法控制系统/function.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
#include<iostream>
#include"algorithm.h"
using namespace std;

algorithm::algorithm()
{
score = 0; right = 0; wrong = 0;
cout << "欢迎您来到算术计算测试系统!\n\n"
<< "请选择测试的题数:";
cin >> ques_num;
cout << "测试的算法(可供输入有:“+”、“-”、“*”或“/”):";

//在用户输入的测试算法有误时,及时进行提醒,逐个字符的提取使得提醒效率提升
opera = char(_getch());
cout << opera << endl;
while (true)
{
if (opera == '+' || opera == '-' || opera == '*' || opera == '/')
{
cout << "测试算法输入正确!" << endl;
break;
}
else
{
cout << "请从提供的算法中选择噢!" << endl;
opera = char(_getch());
cout << opera << endl;
}
}

cout << "请输入进行几位数以内的运算(输入数字):";
cin >> range;
cout << "请您输入此次考试计划完成的时间(以秒为单位):" << endl;
cin >> pre_time;
cout << "\n本次测试即将开始,满分为" << ques_num * 10
<< ",每道题分值为10。\n请您做好准备,输入ok进入考试" << endl;
char*s1 = new char[5];
cin >> s1;
//当输入的提示语不是ok时将提醒用户重新输入
while (true)
{
if (!strcmp(s1, "ok"))
{
cout << "\n**************************考试开始*****************************" << endl;
break;
}
else
{
cout << "请输入正确提示语“ok”进入考试" << endl;
cin >> s1;
}
}
delete[] s1;
this->ques_num = ques_num;
this->opera = opera;
this->range = range;

int num1, num2;
allTime = 0;
srand((int)time(0));

switch (opera)
{
case'+':
for (int i = 1; i <= ques_num; i++)
{
num1 = random(0, int(pow(10, range)));
num2 = random(0, int(pow(10, range)));
cout << '\n' << num1 << "+" << num2 << "=";
//调用成员函数进行计时,若超出计划时长未作答则清屏
clock_t start = timekeeper(ans, allTime, thinkTime);
clock_t end = clock();
if (allTime + thinkTime >= pre_time)
{
allTime += thinkTime;
break;
}
if (ans == num1 + num2)
{
cout << "恭喜您答对了!加10分" << endl;
score += 10;
right += 1;
}
else
{
cout << "很遗憾答错了!不得分" << endl;
wrong += 1;
}
consumeTime = (double)(end - start) / CLOCKS_PER_SEC;
allTime += consumeTime;
cout << "该题用时" << consumeTime << "s" << endl;
if (allTime >= pre_time)
{
system("cls");
cout << "很遗憾,考试时间已到!" << endl;
break;
}
}break;

case '-':
for (int i = 1; i <= ques_num; i++)
{
num1 = random(0, int(pow(10, range)));
num2 = random(0, int(pow(10, range)));
cout << '\n' << num1 << "-" << num2 << "=";
//调用成员函数进行计时,若超出计划时长未作答则清屏
clock_t start = timekeeper(ans, allTime, thinkTime);
clock_t end = clock();
if (allTime + thinkTime >= pre_time)
{
allTime += thinkTime;
break;
}

if (ans == num1 - num2)
{
cout << "恭喜您答对了!加10分" << endl;
score += 10;
right += 1;
}
else
{
cout << "很遗憾答错了!不得分" << endl;
wrong += 1;
}
consumeTime = (double)(end - start) / CLOCKS_PER_SEC;
allTime += consumeTime;
cout << "该题用时" << consumeTime << "s" << endl;
if (thinkTime < pre_time && allTime >= pre_time)
{
system("cls");
cout << "很遗憾,考试时间已到!" << endl;
break;
}
}break;

case '*':
for (int i = 1; i <= ques_num;i++)
{
num1 = random(0, int(pow(10, range)));
num2 = random(0, int(pow(10, range)));
cout << '\n' << num1 << "*" << num2 << "=";
//调用成员函数进行计时,若超出计划时长未作答则清屏
clock_t start = timekeeper(ans, allTime, thinkTime);
clock_t end = clock();
if (allTime + thinkTime >= pre_time)
{
allTime += thinkTime;
break;
}
if (ans == num1 * num2)
{
cout << "恭喜您答对了!加10分" << endl;
score += 10;
right += 1;
}
else
{
cout << "很遗憾答错了!不得分" << endl;
wrong += 1;
}
consumeTime = (double)(end - start) / CLOCKS_PER_SEC;
allTime += consumeTime;
cout << "该题用时" << consumeTime << "s" << endl;
if (allTime >= pre_time)
{
system("cls");
cout << "很遗憾,考试时间已到!" << endl;
break;
}
}break;
case '/':
for (int i = 1; i <= ques_num;i++)
{
num1 = random(0, int(pow(10, range)));
while (true)
{
if (num1 == 0)
{
num1 = random(0, int(pow(10, range)));
}
else break;
}
num2 = num1 * random(0, int(pow(10, range)));
cout << '\n' << num2 << "/" << num1 << "=";
//调用成员函数进行计时,若超出计划时长未作答则清屏
clock_t start = timekeeper(ans, allTime, thinkTime);
clock_t end = clock();
if (allTime + thinkTime >= pre_time)
{
allTime += thinkTime;
break;
}
if (ans == num2 / num1)
{
cout << "恭喜您答对了!加10分" << endl;
score += 10;
right += 1;
}
else
{
cout << "很遗憾答错了!不得分" << endl;
wrong += 1;
}
consumeTime = (double)(end - start) / CLOCKS_PER_SEC;
allTime += consumeTime;
cout << "该题用时" << consumeTime << "s" << endl;
if (allTime >= pre_time)
{
system("cls");
cout << "很遗憾,考试时间已到!" << endl;
break;
}
}break;
default:
break;
}
};

clock_t algorithm::timekeeper(int ans, double thinkTime, double allTime)
{
clock_t start = clock();
//一定程度上解决了无按键回车时cin会堵塞程序的情况,实现超时则立刻清屏
while (true)
{
if (_kbhit())
{
cin >> ans;
break;
}
clock_t end1 = clock();
thinkTime = (double)(end1 - start) / CLOCKS_PER_SEC;

if ((this->allTime + thinkTime) >= pre_time)//ques_num
{
system("cls");
cout << "很遗憾,考试时间已到!" << endl;
break;
}
}
this->ans = ans;
this->thinkTime = thinkTime;
return start;
};

algorithm::~algorithm()
{
cout << "\n您本次测试总分为:" << score
<< "\n答对了" << right << "题,答错了" << wrong
<< "\n用时" << allTime << "s\n" << "计划时长" << pre_time << "s" << endl;
};
10 changes: 10 additions & 0 deletions 算法控制系统/算法控制系统/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include<iostream>
#include"algorithm.h"
//#pragma warning(disable:4996)

int main()
{
{algorithm stu;}//使析构函数在暂停显示前执行
system("pause");
return 0;
}
Loading

0 comments on commit c422d09

Please sign in to comment.