Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

600612158 Lab0 #572

Open
wants to merge 39 commits into
base: Lab0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b3a77a1
Complete all required function for lab 1
pruet Aug 22, 2017
84d1a9f
Rename the placeholding form to MainForm.
pruet Aug 22, 2017
b205641
Implementing sequence operations.
pruet Aug 25, 2017
4868c3d
Add memory function in UI
pruet Aug 28, 2017
6dde73b
Complete unary operator
pruet Aug 28, 2017
125fb99
Compete UI for extended form.
pruet Aug 28, 2017
efcd4e4
Complete all (simple version of) extended calculator function
pruet Aug 29, 2017
440af70
Reduce the number of fraction to 4, for better UX
pruet Aug 29, 2017
06bd545
Complete separation of calculatorengine
pruet Aug 29, 2017
2a3113e
Migrate string processing code to engine.
pruet Aug 29, 2017
b57c0fe
Merge from upstream
pruet Aug 29, 2017
9cd6292
Complete separation of calculator engine
pruet Sep 1, 2017
6ba025b
Complete sequence calculation
pruet Sep 4, 2017
8f91150
Update calculation engine to support sequence calculation
pruet Sep 4, 2017
9a74666
Merge from dev back to master
pruet Sep 4, 2017
377ffa7
Update lab2 for RPN calculator
pruet Sep 4, 2017
c5a1a3f
Merge pull request #5 from pruet/master
pruet Sep 5, 2017
0b796f3
Add comment for CalculatorEngine.Process
pruet Sep 8, 2017
955fa76
Merge pull request #8 from pruet/Dev
pruet Sep 8, 2017
707f865
Fix multiple operator bug
pruet Sep 8, 2017
68aadb8
Merge branch 'Lab2'
pruet Sep 12, 2017
3c4933c
Merge branch 'master' of https://github.com/cpe200-160/CalculatorLab
pruet Sep 12, 2017
5f676cf
Complete Lab 2 solution
pruet Sep 12, 2017
ab21e98
Add all unit test for lab3
pruet Sep 12, 2017
5d61ffa
Update README.md
pruet Sep 4, 2018
e1316ff
Add unit tests for CalculatorEngine and RPNCalculatorEngine
pruet Sep 4, 2018
6aa1fe9
Merge pull request #116 from pruet/Lab2
pruet Sep 4, 2018
c7a117e
Update README.md
pruet Sep 18, 2018
187d133
commit_lab3_600612158
Sep 21, 2018
5656333
600612158_lab3_update
Sep 21, 2018
477c108
Merge branch 'Lab3' into Lab3
navadon Sep 25, 2018
114c2e9
Merge pull request #352 from navadon/Lab3
navadon Sep 27, 2018
c17ebed
Merge pull request #3 from cpe200-161/Lab3
pattdon Sep 28, 2018
5594b13
update man
Sep 28, 2018
ce8ae5e
lab3
Sep 28, 2018
b9b6b2b
update why
Oct 18, 2018
5750c48
LoL
Oct 18, 2018
3b4d6c6
lab4
Oct 26, 2018
3797d46
600612158 lab4
Nov 20, 2018
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
17 changes: 16 additions & 1 deletion CPE200Lab1/CPE200Lab1.sln
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.8
VisualStudioVersion = 15.0.26730.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CPE200Lab1", "CPE200Lab1\CPE200Lab1.csproj", "{C2B44135-F1AC-48A9-BD70-3BE2C38C2A15}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CPE200Lab1Tests", "CPE200Lab1Tests\CPE200Lab1Tests.csproj", "{C92330F4-DC76-46B0-970C-73126DE55500}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CPE200Lab1Test", "CPE200Lab1Test\CPE200Lab1Test.csproj", "{0E964631-C30F-4089-ADD6-D2F374C1E02D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +19,17 @@ Global
{C2B44135-F1AC-48A9-BD70-3BE2C38C2A15}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2B44135-F1AC-48A9-BD70-3BE2C38C2A15}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2B44135-F1AC-48A9-BD70-3BE2C38C2A15}.Release|Any CPU.Build.0 = Release|Any CPU

{C92330F4-DC76-46B0-970C-73126DE55500}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C92330F4-DC76-46B0-970C-73126DE55500}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C92330F4-DC76-46B0-970C-73126DE55500}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C92330F4-DC76-46B0-970C-73126DE55500}.Release|Any CPU.Build.0 = Release|Any CPU

{0E964631-C30F-4089-ADD6-D2F374C1E02D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E964631-C30F-4089-ADD6-D2F374C1E02D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E964631-C30F-4089-ADD6-D2F374C1E02D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E964631-C30F-4089-ADD6-D2F374C1E02D}.Release|Any CPU.Build.0 = Release|Any CPU

EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
22 changes: 17 additions & 5 deletions CPE200Lab1/CPE200Lab1/CPE200Lab1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,28 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<Compile Include="CalculatorEngine.cs" />
<Compile Include="ExtendForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
<Compile Include="ExtendForm.Designer.cs">
<DependentUpon>ExtendForm.cs</DependentUpon>
</Compile>
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
<Compile Include="RPNCalculatorEngine.cs" />
<Compile Include="SimpleCalculatorEngine.cs" />
<EmbeddedResource Include="ExtendForm.resx">
<DependentUpon>ExtendForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
Expand Down
93 changes: 93 additions & 0 deletions CPE200Lab1/CPE200Lab1/CalculatorEngine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPE200Lab1
{
public class CalculatorEngine
{
protected bool isNumber(string str)//--------------------------use-----------------------------------
{
double retNum;
return Double.TryParse(str, out retNum);
}

protected bool isOperator(string str)//-------------------------use-----------------------------------
{
switch(str) {
case "+":
case "-":
case "X":
case "÷":
return true;
}
return false;
}

public virtual string Process(string str)//---------------------------use---------------------------
{
//Split input string to multiple parts by space
List<string> parts = str.Split(' ').ToList<string>();
string result;
//As long as we have more than one part
while(parts.Count > 1)
{
//Check if the first three is ready for calcuation
if(!(isNumber(parts[0]) && isOperator(parts[1]) && isNumber(parts[2])))
{
return "E";
} else
{
//Calculate the first three
result = calculate(parts[1], parts[0], parts[2], 4);
//Remove the first three
parts.RemoveRange(0, 3);
// Put back the result
parts.Insert(0, result);
}
}
return parts[0];
}

public string calculate(string operate, string firstOperand, string secondOperand, int maxOutputSize = 8)//---------------------use----------------
{
switch (operate)
{
case "+":
return (Convert.ToDouble(firstOperand) + Convert.ToDouble(secondOperand)).ToString();
case "-":
return (Convert.ToDouble(firstOperand) - Convert.ToDouble(secondOperand)).ToString();
case "X":
return (Convert.ToDouble(firstOperand) * Convert.ToDouble(secondOperand)).ToString();
case "÷":
// Not allow devide be zero
if (secondOperand != "0")
{
double result;
string[] parts;
int remainLength;

result = (Convert.ToDouble(firstOperand) / Convert.ToDouble(secondOperand));
// split between integer part and fractional part
parts = result.ToString().Split('.');
// if integer part length is already break max output, return error
if (parts[0].Length > maxOutputSize)
{
return "E";
}
// calculate remaining space for fractional part.
remainLength = maxOutputSize - parts[0].Length - 1;
// trim the fractional part gracefully. =
return result.ToString("N" + remainLength);
}
break;
case "%":
//your code here
break;
}
return "E";
}
}
}
Loading