Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions BigTent0/Calculator/Calculator.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 Version 16
VisualStudioVersion = 16.0.28803.156
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Calculator", "Calculator\Calculator.csproj", "{A7CFDE3F-B126-4ED3-8E32-74D29DB8C739}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CalculatorTests", "CalculatorTests\CalculatorTests.csproj", "{62DEEA24-A8B8-4784-8FC2-20F6EB2C25FF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A7CFDE3F-B126-4ED3-8E32-74D29DB8C739}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A7CFDE3F-B126-4ED3-8E32-74D29DB8C739}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7CFDE3F-B126-4ED3-8E32-74D29DB8C739}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A7CFDE3F-B126-4ED3-8E32-74D29DB8C739}.Release|Any CPU.Build.0 = Release|Any CPU
{62DEEA24-A8B8-4784-8FC2-20F6EB2C25FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{62DEEA24-A8B8-4784-8FC2-20F6EB2C25FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{62DEEA24-A8B8-4784-8FC2-20F6EB2C25FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{62DEEA24-A8B8-4784-8FC2-20F6EB2C25FF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5CC477C2-CFC9-46F7-AD65-EB835E57D1C4}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions BigTent0/Calculator/Calculator/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
54 changes: 54 additions & 0 deletions BigTent0/Calculator/Calculator/Calculator.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A7CFDE3F-B126-4ED3-8E32-74D29DB8C739}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Calculator</RootNamespace>
<AssemblyName>Calculator</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="maker.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
20 changes: 20 additions & 0 deletions BigTent0/Calculator/Calculator/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Calculator
{
class Program
{
//maker mymaker = new maker();
static void Main(string[] args)
{
maker mymaker = new maker();
int num = int.Parse(Console.ReadLine());
mymaker.makequi(num);
Console.ReadLine();
}
}
}
36 changes: 36 additions & 0 deletions BigTent0/Calculator/Calculator/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Calculator")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Calculator")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]

// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("a7cfde3f-b126-4ed3-8e32-74d29db8c739")]

// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
172 changes: 172 additions & 0 deletions BigTent0/Calculator/Calculator/maker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/*算法描述
*先由随机数得到运算符的个数,存入到一个列表中
*根据得到符号的个数,得到运算数的个数,用随机数生产并存入列表中
*将得到的数和符号依次入栈,如果遇到乘号和除号就出栈一个和下一个数运算
* 并得出结果,然后入栈。最后得到的就只有加减运算。按次序计算便可得出结果
* 最后将数字符号和结果按次序打印出来
* 为了符号好入栈,所以加减乘除都用数字代替 依次是100 101 102 103
*
*
*/
namespace Calculator
{
public class maker
{
//产生随机数
Random random = new Random();


//产生随机符号
public int makeSign()
{
int sign=100;
int choseFlag;
choseFlag = random.Next(1, 5);
switch(choseFlag)//用数字代表符号
{
case 1:
sign = 100;//加法
break;
case 2:
sign = 101;//减法
break;
case 3:
sign = 102;//乘法
break;
case 4:
sign = 103;//除法
break;
}
return sign;
}

public int makeNumber(int sign)
{//根据产生的符号产生随机数。如果上一个符号为/号,则不能产生0
int number=0;
if(sign==103)
{
number = random.Next(1, 100);
}
else
number = random.Next(0, 100);
return number;
}

public float getResult(List<int> sign, List<int> number)
{//根据产生的符号和数字计算出结果

int[] items = new int[10];
int top = 0;
float result;
items[0] = number[0];

for(int i=0;i<sign.Count;i++)
{
if (sign[i] == 102 || sign[i] == 103)
{
if(sign[i]==102)
{
items[top] *= number[i + 1];
}
else
{
double temp = (double)items[top] / (double)number[i + 1] * 1.0;
items[top] /= number[i + 1];

if(temp-items[top]>0)
{
return -1000000;
}
}
}
else
{
items[++top] = sign[i];
items[++top] = number[i + 1];
}
}

int k = top;
result = items[0];
if (top == 0)
{
return result;

}
else
{
for (int i = 1; i < top+1 ; i += 2)
{
if (items[i] == 100)
{
result += items[i + 1];
}
if (items[i] == 101)
{
result -= items[i + 1];
}
}
}
return result;

}


//sum为运算符号个数
public void makequi(int quistionNum)
{//将产生的题目打印出来
int k = 0;
int num = random.Next(2, 4);
List<int> signs = new List<int>();
List<int> numbers = new List<int>();
while (k <= quistionNum)
{
for (int i = 0; i < num; i++)
{
signs.Add(makeSign());
}
numbers.Add(random.Next(0, 100));
for (int i = 0; i < num; i++)
{
numbers.Add(makeNumber(signs[i]));
}
float result = getResult(signs, numbers);
if(result!=-1000000)
{
Console.Write(numbers[0]);
for (int i = 0; i < signs.Count; i++)
{

switch (signs[i])
{
case 100:
Console.Write("+");
break;
case 101:
Console.Write("-");
break;
case 102:
Console.Write("*");
break;
case 103:
Console.Write("/");
break;
}
Console.Write(numbers[i + 1]);
}
Console.Write("=" + result + "\n");

k++;
}
signs.Clear();
numbers.Clear();
}

}
}
}
Loading