From 35409ace8a7d8912a1840c6aa106a40b017b9b72 Mon Sep 17 00:00:00 2001 From: kbuffardi Date: Wed, 18 Apr 2018 12:17:25 -0700 Subject: [PATCH 1/5] Buggy implementation --- main.cpp | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index a4ade7a..33d9807 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,8 @@ #include using namespace std; +int sortDescending(int, int, int); + int main() { //DO NOT CHANGE WITHIN THIS AREA... @@ -9,13 +11,36 @@ int main() cin>>red>>green>>blue; //...END OF "DO NOT CHANGE" AREA - - - + sortDescending(int red, int green, int blue); //DO NOT CHANGE WITHIN THIS AREA... cout<<"Rearranged....\n"; cout<<"RGB: "< Date: Wed, 18 Apr 2018 12:25:32 -0700 Subject: [PATCH 2/5] Add bugs in sortDescending function --- main.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index 33d9807..186a59a 100644 --- a/main.cpp +++ b/main.cpp @@ -11,7 +11,7 @@ int main() cin>>red>>green>>blue; //...END OF "DO NOT CHANGE" AREA - sortDescending(int red, int green, int blue); + sortDescending(red, green, blue); //DO NOT CHANGE WITHIN THIS AREA... cout<<"Rearranged....\n"; @@ -24,17 +24,17 @@ int sortDescending(int first, int second, int third) { int temp; - if( first < second ) + if( red < green ) { temp = first; first = second; second = temp; } - if( second < third ) + if( green < blue ) { temp = second; second = third; - thired = temp; + third = temp; } if( first < second ) { @@ -43,4 +43,3 @@ int sortDescending(int first, int second, int third) second = temp; } } -} From a789325ff0e1fcc292bfba52e24206db56b492fb Mon Sep 17 00:00:00 2001 From: Kevin Buffardi Date: Tue, 19 Feb 2019 19:23:04 -0800 Subject: [PATCH 3/5] Refactored algorithm with swap and sort functions; still buggy --- .gitignore | 32 -------------------------------- Makefile | 2 ++ main.cpp | 54 ++++++++++++++++++++++++++---------------------------- 3 files changed, 28 insertions(+), 60 deletions(-) delete mode 100644 .gitignore create mode 100644 Makefile diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 259148f..0000000 --- a/.gitignore +++ /dev/null @@ -1,32 +0,0 @@ -# Prerequisites -*.d - -# Compiled Object files -*.slo -*.lo -*.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod -*.smod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out -*.app diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8d03a55 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +all: + g++ -Wfatal-errors main.cpp diff --git a/main.cpp b/main.cpp index 186a59a..e4f9ae8 100644 --- a/main.cpp +++ b/main.cpp @@ -1,45 +1,43 @@ #include -using namespace std; +using std::cout; +using std::cin; +using std::endl; -int sortDescending(int, int, int); +void sortDescending(int,int,int); +void swap(int&,int&); int main() { - //DO NOT CHANGE WITHIN THIS AREA... - int red, blue, green; - cout<<"Enter Red, Green, and Blue values: "; - cin>>red>>green>>blue; - //...END OF "DO NOT CHANGE" AREA + int numA, numB, numC; + cout<<"Enter any three numbers: "; + cin>>numA>>numB>>numC; - sortDescending(red, green, blue); - - //DO NOT CHANGE WITHIN THIS AREA... - cout<<"Rearranged....\n"; - cout<<"RGB: "< Date: Tue, 19 Feb 2019 19:34:58 -0800 Subject: [PATCH 4/5] Adds basic getting started documentation --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..78ed664 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Trio + +This C++ program receives three integers and tells the user the numbers in descending (largest-to-smallest) order. + +## Getting Started + +To run the program do the following in your command line interface prompt ($): + +``` +$make +$./a.out +``` From b7dc4582aab2ba2fa316d54a5adff5b0d4fadc76 Mon Sep 17 00:00:00 2001 From: Kevin Buffardi Date: Wed, 20 Feb 2019 11:09:59 -0800 Subject: [PATCH 5/5] Refactor variable names --- main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index e4f9ae8..0912a25 100644 --- a/main.cpp +++ b/main.cpp @@ -35,9 +35,9 @@ void sortDescending(int first, int second, int third) } } -void swap(int &first, int &second) +void swap(int &a, int &b) { - int temp = first; - first = second; - second = temp; + int temp = a; + a = b; + b = temp; }