Skip to content

Commit 55642fa

Browse files
danieldaniel
authored andcommitted
Add project files.
1 parent 018dee1 commit 55642fa

File tree

6 files changed

+406
-0
lines changed

6 files changed

+406
-0
lines changed

Calculations.cpp

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#include "Calculations.h"
2+
#include <iomanip>
3+
#include <vector>
4+
#include <algorithm>
5+
#include <iterator>
6+
#include <string>
7+
using namespace std;
8+
9+
// Constants
10+
const int w = 12; // setw width
11+
const int MAX = 100; // max array size (max number of factors)
12+
13+
14+
// Function Definitions
15+
void GetValues(int* x, int* y) {
16+
int n1, n2;
17+
18+
std::cout << "Enter the first number: ";
19+
std::cin >> n1;
20+
*x = n1;
21+
22+
std::cout << "Enter the second number: ";
23+
std::cin >> n2;
24+
*y = n2;
25+
26+
std::cout << std::endl;
27+
}
28+
29+
void SortNum(int* x, int* y) {
30+
int numLarge, numSmall;
31+
numSmall = *x;
32+
numLarge = *y;
33+
34+
if (numSmall > numLarge) {
35+
*x = numLarge;
36+
*y = numSmall;
37+
}
38+
}
39+
40+
void FindCommonFactors(int numSmall, int numLarge, vector<int> &cFactors) {
41+
vector<int> sFactors;
42+
vector<int> lFactors;
43+
int remainder{ 0 };
44+
45+
// store vfactors of small number in vector
46+
cout << "Factors of " << numSmall << ": " << setw(w);
47+
for (int i = 1; i <= numSmall; i++) {
48+
remainder = numSmall % i;
49+
if (remainder == 0) {
50+
sFactors.push_back(i);
51+
cout << i << " ";
52+
}
53+
}
54+
cout << "\n";
55+
remainder = 0; // reset value of remainder
56+
57+
// store factors of large number in vector
58+
cout << "Factors of " << numLarge << ": " << setw(w);
59+
for (int i = 1; i <= numLarge; i++) {
60+
remainder = numLarge % i;
61+
if (remainder == 0) {
62+
lFactors.push_back(i);
63+
cout << i << " ";
64+
}
65+
}
66+
cout << "\n";
67+
68+
// resize common factors vector to ensure enough memory is available to hold all common factors
69+
cFactors.resize(sFactors.size() + lFactors.size());
70+
// create an iterator (acts like a pointer to an element in the container - can be used to modify elements as well)
71+
vector<int>::iterator it;
72+
73+
// set_intersection takes in two input ranges and returns an iterator that points to
74+
// the element one past the last element of the output range - in this case cFactors
75+
// It additionally stores elements that are present in both input ranges in cFactors,
76+
// starting at the first memory location of cFactors: cFactors.begin()
77+
int count = set_intersection(
78+
sFactors.begin(), sFactors.end(), // specifies the range of sFactors vector
79+
lFactors.begin(), lFactors.end(), // specifies the range of lFactors vector
80+
cFactors.begin()) - cFactors.begin(); // we're then subtracting the new output range (which is the size of cFactors) by the
81+
82+
// resize common factors vector again to discard any unused memory
83+
cFactors.resize(count);
84+
85+
// TEST
86+
cout << "Common Factors: " << setw(w);
87+
for (it = cFactors.begin(); it != cFactors.end(); it++) {
88+
cout << *it << " ";
89+
}
90+
cout << "\n\n";
91+
}
92+
93+
int CalculateGFC(int numSmall, int numLarge) {
94+
int remainder{ 0 };
95+
int count{ 0 };
96+
97+
do {
98+
remainder = numLarge % numSmall;
99+
numLarge = numSmall;
100+
numSmall = remainder;
101+
count++;
102+
} while (remainder != 0);
103+
104+
return numLarge;
105+
}
106+
107+
void Print(int GCF, int num1, int num2) {
108+
std::cout << "/////////////////////\n";
109+
std::cout << "The Greatest Common Factor of " << num1 << " and " << num2 << " is " << GCF << std::endl;
110+
std::cout << "//////////////\n\n";
111+
}
112+
113+
void UpdateChoice(bool& choice) {
114+
int input;
115+
116+
std::cout << "Would you like to run the program again?\n";
117+
std::cout << "1. Yes\n";
118+
std::cout << "2. No\n";
119+
120+
std::cin >> input;
121+
std::cout << std::endl;
122+
123+
while (input != 1 && input != 2) {
124+
std::cout << "Invalid input\n\n";
125+
std::cout << "Would you like to run the program again?\n";
126+
std::cout << "1. Yes\n";
127+
std::cout << "2. No\n";
128+
129+
std::cin >> input;
130+
}
131+
132+
if (input == 1) {
133+
choice = true;
134+
}
135+
else {
136+
choice = false;
137+
}
138+
}

Calculations.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef CALCULATIONS_H
2+
#define CALCULATIONS_H
3+
4+
#include <iostream>
5+
#include <vector>
6+
using namespace std;
7+
8+
// Function Prototypes
9+
void GetValues(int* x, int* y);
10+
void SortNum(int* x, int* y);
11+
void FindCommonFactors(int numSmall, int numLarge, vector<int> &cFactors);
12+
int CalculateGFC(int numSmall, int numLarge);
13+
void Print(int GCF, int num1, int num2);
14+
void UpdateChoice(bool& choice);
15+
16+
17+
#endif

Euclid's Algorithm.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.33424.131
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Euclid's Algorithm", "Euclid's Algorithm.vcxproj", "{37C28221-1855-4503-8314-355512D7F2DC}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{37C28221-1855-4503-8314-355512D7F2DC}.Debug|x64.ActiveCfg = Debug|x64
17+
{37C28221-1855-4503-8314-355512D7F2DC}.Debug|x64.Build.0 = Debug|x64
18+
{37C28221-1855-4503-8314-355512D7F2DC}.Debug|x86.ActiveCfg = Debug|Win32
19+
{37C28221-1855-4503-8314-355512D7F2DC}.Debug|x86.Build.0 = Debug|Win32
20+
{37C28221-1855-4503-8314-355512D7F2DC}.Release|x64.ActiveCfg = Release|x64
21+
{37C28221-1855-4503-8314-355512D7F2DC}.Release|x64.Build.0 = Release|x64
22+
{37C28221-1855-4503-8314-355512D7F2DC}.Release|x86.ActiveCfg = Release|Win32
23+
{37C28221-1855-4503-8314-355512D7F2DC}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {6DAE4D14-E8F6-4DB2-BE21-D7AB50DAA9D8}
30+
EndGlobalSection
31+
EndGlobal

Euclid's Algorithm.vcxproj

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>16.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{37c28221-1855-4503-8314-355512d7f2dc}</ProjectGuid>
25+
<RootNamespace>EuclidsAlgorithm</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>Application</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v143</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>Application</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v143</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>Application</ConfigurationType>
44+
<UseDebugLibraries>true</UseDebugLibraries>
45+
<PlatformToolset>v143</PlatformToolset>
46+
<CharacterSet>Unicode</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>Application</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v143</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74+
<ClCompile>
75+
<WarningLevel>Level3</WarningLevel>
76+
<SDLCheck>true</SDLCheck>
77+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
78+
<ConformanceMode>true</ConformanceMode>
79+
</ClCompile>
80+
<Link>
81+
<SubSystem>Console</SubSystem>
82+
<GenerateDebugInformation>true</GenerateDebugInformation>
83+
</Link>
84+
</ItemDefinitionGroup>
85+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
86+
<ClCompile>
87+
<WarningLevel>Level3</WarningLevel>
88+
<FunctionLevelLinking>true</FunctionLevelLinking>
89+
<IntrinsicFunctions>true</IntrinsicFunctions>
90+
<SDLCheck>true</SDLCheck>
91+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
92+
<ConformanceMode>true</ConformanceMode>
93+
</ClCompile>
94+
<Link>
95+
<SubSystem>Console</SubSystem>
96+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
97+
<OptimizeReferences>true</OptimizeReferences>
98+
<GenerateDebugInformation>true</GenerateDebugInformation>
99+
</Link>
100+
</ItemDefinitionGroup>
101+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
102+
<ClCompile>
103+
<WarningLevel>Level3</WarningLevel>
104+
<SDLCheck>true</SDLCheck>
105+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
106+
<ConformanceMode>true</ConformanceMode>
107+
</ClCompile>
108+
<Link>
109+
<SubSystem>Console</SubSystem>
110+
<GenerateDebugInformation>true</GenerateDebugInformation>
111+
</Link>
112+
</ItemDefinitionGroup>
113+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
114+
<ClCompile>
115+
<WarningLevel>Level3</WarningLevel>
116+
<FunctionLevelLinking>true</FunctionLevelLinking>
117+
<IntrinsicFunctions>true</IntrinsicFunctions>
118+
<SDLCheck>true</SDLCheck>
119+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
120+
<ConformanceMode>true</ConformanceMode>
121+
</ClCompile>
122+
<Link>
123+
<SubSystem>Console</SubSystem>
124+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
125+
<OptimizeReferences>true</OptimizeReferences>
126+
<GenerateDebugInformation>true</GenerateDebugInformation>
127+
</Link>
128+
</ItemDefinitionGroup>
129+
<ItemGroup>
130+
<ClCompile Include="Calculations.cpp" />
131+
<ClCompile Include="main.cpp" />
132+
</ItemGroup>
133+
<ItemGroup>
134+
<ClInclude Include="Calculations.h" />
135+
</ItemGroup>
136+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
137+
<ImportGroup Label="ExtensionTargets">
138+
</ImportGroup>
139+
</Project>

Euclid's Algorithm.vcxproj.filters

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="main.cpp">
19+
<Filter>Source Files</Filter>
20+
</ClCompile>
21+
<ClCompile Include="Calculations.cpp">
22+
<Filter>Source Files</Filter>
23+
</ClCompile>
24+
</ItemGroup>
25+
<ItemGroup>
26+
<ClInclude Include="Calculations.h">
27+
<Filter>Header Files</Filter>
28+
</ClInclude>
29+
</ItemGroup>
30+
</Project>

0 commit comments

Comments
 (0)