Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1a83386
creating functions for working with the stack and testing them
MinyazevR Oct 15, 2021
2549f2f
fixed bugs
MinyazevR Oct 15, 2021
14417f4
Merge branch 'main' of https://github.com/MinyazevR/Homework-1-sem in…
MinyazevR Oct 15, 2021
8d6727e
fixed bugs
MinyazevR Oct 15, 2021
f43380d
start
MinyazevR Oct 15, 2021
d2884fc
start
MinyazevR Oct 16, 2021
e7e22d6
add function
MinyazevR Oct 16, 2021
2f9e2a0
fixed bugs
MinyazevR Oct 16, 2021
9a061fa
writing all functions, adding comments
MinyazevR Oct 16, 2021
a67b184
fixed bugs
MinyazevR Oct 16, 2021
015e87e
fixed bugs
MinyazevR Oct 16, 2021
75fe192
Merge pull request #17 from MinyazevR/Stack
MinyazevR Oct 16, 2021
5c8f0cf
fixed bugs
MinyazevR Oct 22, 2021
d85663e
fixed bugs
MinyazevR Oct 22, 2021
123d94e
Merge pull request #19 from MinyazevR/Stack
MinyazevR Oct 22, 2021
cc6ba23
Merge branch 'PostfixFormEntry' of https://github.com/MinyazevR/Homew…
MinyazevR Oct 22, 2021
6a502c1
fixed bugs
MinyazevR Oct 22, 2021
2ab34ad
Merge pull request #20 from MinyazevR/Stack
MinyazevR Oct 22, 2021
a9965e1
Merge branch 'PostfixFormEntry' of https://github.com/MinyazevR/Homew…
MinyazevR Oct 22, 2021
58913fa
fixed bugs
MinyazevR Oct 22, 2021
e4c55b4
tweaked the code
MinyazevR Oct 22, 2021
e0ec8d8
fixed bugs
MinyazevR Oct 22, 2021
c7141c5
fixed bugs
MinyazevR Oct 23, 2021
7c6d74e
fixed bugs
MinyazevR Oct 23, 2021
cad0914
fixed bugs
MinyazevR Oct 23, 2021
fe7b4ae
fixed bugs
MinyazevR Oct 23, 2021
465c325
changing the type to float for a problem with a postfix form
MinyazevR Oct 23, 2021
ff4b737
replacing int with float(for example, for 92/ = 4.5)
MinyazevR Oct 23, 2021
a759b10
fixed bugs
MinyazevR Oct 23, 2021
3bd1352
fixed bugs
MinyazevR Oct 23, 2021
f6d3e25
fixed bugs
MinyazevR Oct 24, 2021
e0515c6
fixed comments
MinyazevR Oct 24, 2021
18ca3e3
fixed bugs
MinyazevR Oct 24, 2021
c2f8ecf
fixed a bug with the error code
MinyazevR Oct 25, 2021
7fe0b6b
working with error codes, replacing tests, the case is considered whe…
MinyazevR Oct 25, 2021
6dfd83e
removed the unnecessary one .h file
MinyazevR Oct 25, 2021
954d78b
adding const
MinyazevR Oct 25, 2021
98a42e2
adding const
MinyazevR Oct 25, 2021
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 Postfixform/Postfixform.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.31410.357
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Postfixform", "Postfixform\Postfixform.vcxproj", "{15009E36-9D86-441E-A9EA-947AAC734F19}"
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
{15009E36-9D86-441E-A9EA-947AAC734F19}.Debug|x64.ActiveCfg = Debug|x64
{15009E36-9D86-441E-A9EA-947AAC734F19}.Debug|x64.Build.0 = Debug|x64
{15009E36-9D86-441E-A9EA-947AAC734F19}.Debug|x86.ActiveCfg = Debug|Win32
{15009E36-9D86-441E-A9EA-947AAC734F19}.Debug|x86.Build.0 = Debug|Win32
{15009E36-9D86-441E-A9EA-947AAC734F19}.Release|x64.ActiveCfg = Release|x64
{15009E36-9D86-441E-A9EA-947AAC734F19}.Release|x64.Build.0 = Release|x64
{15009E36-9D86-441E-A9EA-947AAC734F19}.Release|x86.ActiveCfg = Release|Win32
{15009E36-9D86-441E-A9EA-947AAC734F19}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C330BC54-81A6-4E6B-9775-51E396ACC586}
EndGlobalSection
EndGlobal
34 changes: 34 additions & 0 deletions Postfixform/Postfixform/Main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "../../Stack/Stack/Stack.h"
#include "Postfix.h"
#include "PostfixFormTest.h"
#include <stdio.h>

int main()
{
if (!areTestPassingPostfixForm())
{
printf("Test failed");
return -1;
}
char postfixEntry[250] = { '\0' };
printf("enter the expression in postfix form\n");
scanf_s("%[^\n]s", postfixEntry, (unsigned)sizeof(postfixEntry));
int errorCode = 0;
const float answer = countTheExpression(postfixEntry, &errorCode);
if (errorCode == 1)
{
printf("Incorrect input of an expression in postfix form");
return -1;
}
if (errorCode == 2)
{
printf("invalid character in the expression entry");
return -1;
}
if (errorCode == 3)
{
printf("it is impossible to divide by 0");
return -1;
}
printf("%f", answer);
}
77 changes: 77 additions & 0 deletions Postfixform/Postfixform/Postfix.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include "../../Stack/Stack/Stack.h"
#include "Postfix.h"
#include <stdlib.h>

float countTheExpression(const char* postfixEntry, int* errorCode)
{
Stack* head = NULL;
int counter = 0;
int error = 0;
while (postfixEntry[counter] != '\0')
{
if (postfixEntry[counter] >= '0' && postfixEntry[counter] <= '9')
{
push(&head, (float)postfixEntry[counter] - '0');
counter++;
continue;
}
else if (postfixEntry[counter] == ' ')
{
counter++;
continue;
}
float secondNumber = pop(&head, &error);
if (error == 1)
{
*errorCode = error;
return 0;
}
float firstNumber = pop(&head, &error);
if (error == 1)
{
*errorCode = error;
return 0;
}
if (postfixEntry[counter] == '-')
{
push(&head, (firstNumber - secondNumber));
}
else if (postfixEntry[counter] == '+')
{
push(&head, firstNumber + secondNumber);
}
else if (postfixEntry[counter] == '*')
{
push(&head, firstNumber * secondNumber);
}
else if (postfixEntry[counter] == '/')
{
if (secondNumber == 0)
{
*errorCode = 3;
return 0;
}
push(&head, firstNumber / secondNumber);
}
else
{
deleteStack(&head);
*errorCode = 2;
return 0;

This comment was marked as resolved.

}
counter++;
}
const float answer = pop(&head, &error);
if (error == 1)
{
*errorCode = error;
return 0;
}
if (!isEmpty(head))
{
deleteStack(&head);
*errorCode = 1;
return 0;
}
return answer;
}
4 changes: 4 additions & 0 deletions Postfixform/Postfixform/Postfix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

// Function for calculating the value of an expression in postfix form
float countTheExpression(const char* postfixEntry, int* errorCode);
31 changes: 31 additions & 0 deletions Postfixform/Postfixform/PostfixFormTest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "PostfixFormTest.h"
#include "Postfix.h"

bool areTestPassingPostfixForm()
{
const char firstCorrectPostfixEntry[250] = "3 2 - 4 5 * + 2 9 - *";
const char secondCorrectPostfixEntry[250] = "2 3 - 4 5 * +";
const char thirdCorrectPostfixEntry[250] = "9 6 - 1 2 + *";
const char fourthCorrectPostfixEntry[250] = "9 6 - 5 2 / +";
const char fifthCorrectPostfixEntry[250] = "9 6 - 3 -";

const char firstIncorrectPostfixEntry[250] = "3 5 a";
const char secondIncorrectPostfixEntry[250] = "4 0 /";
const char thirdIncorrectPostfixEntry[250] = "34 - 345";
const char fourthIncorrectPostfixEntry[250] = "12 - 34 + 4";
const char fifthIncorrectPostfixEntry[250] = "1234 - 12";

int errorCode[10] = {0};

return countTheExpression(firstCorrectPostfixEntry, &errorCode[0]) == -147 && errorCode[0] == 0
&& countTheExpression(secondCorrectPostfixEntry, &errorCode[1]) == 19 && errorCode[1] == 0
&& countTheExpression(thirdCorrectPostfixEntry, &errorCode[2]) == 9 && errorCode[2] == 0
&& countTheExpression(fourthCorrectPostfixEntry, &errorCode[3]) == 5.5 && errorCode[3] == 0
&& countTheExpression(fifthCorrectPostfixEntry, &errorCode[4]) == 0 && errorCode[4] == 0

&& countTheExpression(firstIncorrectPostfixEntry, &errorCode[5]) == 0 && errorCode[5] == 2
&& countTheExpression(secondIncorrectPostfixEntry, &errorCode[6]) == 0 && errorCode[6] == 3
&& countTheExpression(thirdIncorrectPostfixEntry, &errorCode[7]) == 0 && errorCode[7] == 1
&& countTheExpression(fourthIncorrectPostfixEntry, &errorCode[8]) == 0 && errorCode[8] == 1
&& countTheExpression(fifthIncorrectPostfixEntry, &errorCode[9]) == 0 && errorCode[9] == 1;
}
5 changes: 5 additions & 0 deletions Postfixform/Postfixform/PostfixFormTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once
#include <stdbool.h>

// Function for testing a function that translates an expression from a postfix form
bool areTestPassingPostfixForm();
170 changes: 170 additions & 0 deletions Postfixform/Postfixform/Postfixform.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\Stack\Stack\Stack.c" />
<ClCompile Include="Main.c" />
<ClCompile Include="Postfix.c" />
<ClCompile Include="PostfixFormTest.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\Stack\Stack\Stack.h" />
<ClInclude Include="Postfix.h" />
<ClInclude Include="PostfixFormTest.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{15009e36-9d86-441e-a9ea-947aac734f19}</ProjectGuid>
<RootNamespace>Postfixform</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
<Import Project="$(VCTargetsPath)\BuildCustomizations\ImageContentTask.props" />
<Import Project="$(VCTargetsPath)\BuildCustomizations\lc.props" />
<Import Project="$(VCTargetsPath)\BuildCustomizations\marmasm.props" />
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props" />
<Import Project="$(VCTargetsPath)\BuildCustomizations\MeshContentTask.props" />
<Import Project="$(VCTargetsPath)\BuildCustomizations\ShaderGraphContentTask.props" />
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<ProjectReference>
<UseLibraryDependencyInputs>false</UseLibraryDependencyInputs>
</ProjectReference>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\ImageContentTask.targets" />
<Import Project="$(VCTargetsPath)\BuildCustomizations\lc.targets" />
<Import Project="$(VCTargetsPath)\BuildCustomizations\marmasm.targets" />
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
<Import Project="$(VCTargetsPath)\BuildCustomizations\MeshContentTask.targets" />
<Import Project="$(VCTargetsPath)\BuildCustomizations\ShaderGraphContentTask.targets" />
</ImportGroup>
</Project>
Loading