From b70fc122193850d952f050f38e53b2c86f11331e Mon Sep 17 00:00:00 2001 From: jinnudeveloper Date: Tue, 30 Aug 2016 21:07:56 +0530 Subject: [PATCH 01/17] Add square.cpp --- square.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 square.cpp diff --git a/square.cpp b/square.cpp new file mode 100644 index 0000000..22ada8a --- /dev/null +++ b/square.cpp @@ -0,0 +1,34 @@ +//Code Compile and Run by codechef IDE + +#include +using namespace std; + +int main() +{ + int size; + cout << "Enter Box Size\n"; + cin >> size; + + for(int col=0;col 1) + { + cout << "\n"; + for(int row=0;row Date: Tue, 30 Aug 2016 23:35:27 +0530 Subject: [PATCH 02/17] square.cpp removed --- square.cpp | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 square.cpp diff --git a/square.cpp b/square.cpp deleted file mode 100644 index 22ada8a..0000000 --- a/square.cpp +++ /dev/null @@ -1,34 +0,0 @@ -//Code Compile and Run by codechef IDE - -#include -using namespace std; - -int main() -{ - int size; - cout << "Enter Box Size\n"; - cin >> size; - - for(int col=0;col 1) - { - cout << "\n"; - for(int row=0;row Date: Tue, 30 Aug 2016 23:41:42 +0530 Subject: [PATCH 03/17] Add Square cpp pgm --- 01-lets_get_started/01.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 01-lets_get_started/01.cpp diff --git a/01-lets_get_started/01.cpp b/01-lets_get_started/01.cpp new file mode 100644 index 0000000..262b8a1 --- /dev/null +++ b/01-lets_get_started/01.cpp @@ -0,0 +1,35 @@ +//Code Compile and Run by codechef IDE + +#include +using namespace std; + +int main() +{ + int size; + cout << "Enter Box Size\n"; + cin >> size; + + for(int col=0;col 1) + { + cout << "\n"; + for(int row=0;row Date: Wed, 31 Aug 2016 17:51:43 +0530 Subject: [PATCH 04/17] Square pgm using class in Cpp --- 01-lets_get_started/01.cpp | 62 ++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/01-lets_get_started/01.cpp b/01-lets_get_started/01.cpp index 262b8a1..7832b99 100644 --- a/01-lets_get_started/01.cpp +++ b/01-lets_get_started/01.cpp @@ -1,35 +1,37 @@ -//Code Compile and Run by codechef IDE +/* Program to illustrate drawing of a Square using Object and Class in C++ Programming */ #include using namespace std; - -int main() +class square { - int size; - cout << "Enter Box Size\n"; - cin >> size; - - for(int col=0;col 1) - { - cout << "\n"; - for(int row=0;row> side; + top_bottom(); + if(side > 1){ + cout << "\n"; + left_right(); + top_bottom(); + } + } + void top_bottom(){ + for(column=0; column Date: Thu, 1 Sep 2016 00:36:20 +0530 Subject: [PATCH 05/17] Modified file using exception handling technique --- 01-lets_get_started/01.cpp | 53 ++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/01-lets_get_started/01.cpp b/01-lets_get_started/01.cpp index 7832b99..baabbb1 100644 --- a/01-lets_get_started/01.cpp +++ b/01-lets_get_started/01.cpp @@ -1,7 +1,9 @@ /* Program to illustrate drawing of a Square using Object and Class in C++ Programming */ +/*Exception Handling is applied*/ #include using namespace std; + class square { private: @@ -10,28 +12,51 @@ class square void square_data(){ cout << "Enter side of Square\n"; cin >> side; - top_bottom(); - if(side > 1){ - cout << "\n"; - left_right(); - top_bottom(); - } + + if(cin) + { + try{ + if(side < 1) + throw side; + else if(side == 1) + top_bottom(side); + else + square_draw(side); + } + + catch(int exp){ + cout << "Bad Integer value!\n"; + square_draw(3); + } } - void top_bottom(){ - for(column=0; column Date: Thu, 1 Sep 2016 16:00:42 +0530 Subject: [PATCH 06/17] Input validate square pgm --- 02-generalize/02.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 02-generalize/02.cpp diff --git a/02-generalize/02.cpp b/02-generalize/02.cpp new file mode 100644 index 0000000..baabbb1 --- /dev/null +++ b/02-generalize/02.cpp @@ -0,0 +1,62 @@ +/* Program to illustrate drawing of a Square using Object and Class in C++ Programming */ +/*Exception Handling is applied*/ + +#include +using namespace std; + +class square +{ + private: + int side,column,row; + public: + void square_data(){ + cout << "Enter side of Square\n"; + cin >> side; + + if(cin) + { + try{ + if(side < 1) + throw side; + else if(side == 1) + top_bottom(side); + else + square_draw(side); + } + + catch(int exp){ + cout << "Bad Integer value!\n"; + square_draw(3); + } + } + else + cout << "Sorry you entered an invalid input"; + } + + void top_bottom(int s1){ + for(column = 0; column < s1; ++column) + cout << "#"; + } + + void left_right(int s2){ + for(row = 0; row < s2-2; ++row){ + cout << "#"; + for(column=0; column < s2-2; ++column) + cout << " "; + cout << "#\n"; + } + } + + void square_draw(int s3){ + top_bottom(s3); + cout << "\n"; + left_right(s3); + top_bottom(s3); + } +}; + + int main(){ + square obj; + obj.square_data(); + return 0; + } From 0e39d3fdc3e5c017be16513d9c0aebc9d7c00aea Mon Sep 17 00:00:00 2001 From: jinnudeveloper Date: Thu, 1 Sep 2016 16:06:41 +0530 Subject: [PATCH 07/17] Square pgm using class --- 01-lets_get_started/01.cpp | 52 ++++++++++---------------------------- 1 file changed, 14 insertions(+), 38 deletions(-) diff --git a/01-lets_get_started/01.cpp b/01-lets_get_started/01.cpp index baabbb1..df34b01 100644 --- a/01-lets_get_started/01.cpp +++ b/01-lets_get_started/01.cpp @@ -1,5 +1,4 @@ /* Program to illustrate drawing of a Square using Object and Class in C++ Programming */ -/*Exception Handling is applied*/ #include using namespace std; @@ -12,51 +11,28 @@ class square void square_data(){ cout << "Enter side of Square\n"; cin >> side; - - if(cin) - { - try{ - if(side < 1) - throw side; - else if(side == 1) - top_bottom(side); - else - square_draw(side); - } - - catch(int exp){ - cout << "Bad Integer value!\n"; - square_draw(3); - } + top_bottom(); + if(side > 1){ + cout << "\n"; + left_right(); + top_bottom(); + } } - else - cout << "Sorry you entered an invalid input"; - } - - void top_bottom(int s1){ - for(column = 0; column < s1; ++column) + void top_bottom(){ + for(column = 0; column < side; ++column) cout << "#"; - } - - void left_right(int s2){ - for(row = 0; row < s2-2; ++row){ - cout << "#"; - for(column=0; column < s2-2; ++column) + } + void left_right(){ + for(row = 0; row < side-2; ++row){ + cout<< "#"; + for(column=0; column < side-2; ++column) cout << " "; cout << "#\n"; } } - - void square_draw(int s3){ - top_bottom(s3); - cout << "\n"; - left_right(s3); - top_bottom(s3); - } }; - int main(){ square obj; obj.square_data(); return 0; - } + } From 454c21dc533fab8b5bd5c670c8e234ebda3dc4e4 Mon Sep 17 00:00:00 2001 From: jinnudeveloper Date: Thu, 1 Sep 2016 16:30:17 +0530 Subject: [PATCH 08/17] Indentation corrected --- 01-lets_get_started/01.cpp | 67 +++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/01-lets_get_started/01.cpp b/01-lets_get_started/01.cpp index df34b01..3f79aa4 100644 --- a/01-lets_get_started/01.cpp +++ b/01-lets_get_started/01.cpp @@ -5,34 +5,41 @@ using namespace std; class square { - private: - int side,column,row; - public: - void square_data(){ - cout << "Enter side of Square\n"; - cin >> side; - top_bottom(); - if(side > 1){ - cout << "\n"; - left_right(); - top_bottom(); - } - } - void top_bottom(){ - for(column = 0; column < side; ++column) - cout << "#"; - } - void left_right(){ - for(row = 0; row < side-2; ++row){ - cout<< "#"; - for(column=0; column < side-2; ++column) - cout << " "; - cout << "#\n"; - } - } +private: + int side,column,row; +public: + void square_data() + { + cout << "Enter side of Square\n"; + cin >> side; + top_bottom(); + if(side > 1) + { + cout << "\n"; + left_right(); + top_bottom(); + } + } + void top_bottom() + { + for(column = 0; column < side; ++column) + cout << "#"; + } + void left_right() + { + for(row = 0; row < side-2; ++row) + { + cout<< "#"; + for(column=0; column < side-2; ++column) + cout << " "; + cout << "#\n"; + } + } }; - int main(){ - square obj; - obj.square_data(); - return 0; - } +int main() +{ + square obj; + obj.square_data(); + return 0; +} + From 4c55a1b4142df0948b8c9d4561e2d0868a07d23c Mon Sep 17 00:00:00 2001 From: jinnudeveloper Date: Thu, 1 Sep 2016 17:10:05 +0530 Subject: [PATCH 09/17] Indentation corrected --- 02-generalize/02.cpp | 118 ++++++++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 53 deletions(-) diff --git a/02-generalize/02.cpp b/02-generalize/02.cpp index baabbb1..8475b8e 100644 --- a/02-generalize/02.cpp +++ b/02-generalize/02.cpp @@ -1,62 +1,74 @@ /* Program to illustrate drawing of a Square using Object and Class in C++ Programming */ -/*Exception Handling is applied*/ +/*Exception Handling is applied for Validation*/ #include using namespace std; class square { - private: - int side,column,row; - public: - void square_data(){ - cout << "Enter side of Square\n"; - cin >> side; - - if(cin) - { - try{ - if(side < 1) - throw side; - else if(side == 1) - top_bottom(side); - else - square_draw(side); - } - - catch(int exp){ - cout << "Bad Integer value!\n"; - square_draw(3); - } - } - else - cout << "Sorry you entered an invalid input"; - } - - void top_bottom(int s1){ - for(column = 0; column < s1; ++column) - cout << "#"; - } - - void left_right(int s2){ - for(row = 0; row < s2-2; ++row){ - cout << "#"; - for(column=0; column < s2-2; ++column) - cout << " "; - cout << "#\n"; - } - } - - void square_draw(int s3){ - top_bottom(s3); - cout << "\n"; - left_right(s3); - top_bottom(s3); - } +private: + int side,column,row; + char character; +public: + void square_data() + { + cout << "Enter character to print\n"; + cin >> character; + cout << "Enter side of Square\n"; + cin >> side; + + + if(cin) + { + try + { + if(side < 1) + throw side; + else if(side == 1) + top_bottom(side); + else + square_draw(side); + } + + catch(int exp) + { + cerr << "Sorry! Expected Positive Integer Value For Box Side!\n"; + square_draw(3); + } + } + else + cerr << "Please Confirm Both Values Are Inserted or Wrong Data!"; + } + + void top_bottom(int var1) + { + for(column = 0; column < var1; ++column) + cout << character; + } + + void left_right(int var2) + { + for(row = 0; row < var2-2; ++row) + { + cout << character; + for(column=0; column < var2-2; ++column) + cout << " "; + cout << character<<"\n"; + } + } + + void square_draw(int var3) + { + top_bottom(var3); + cout << "\n"; + left_right(var3); + top_bottom(var3); + } }; - int main(){ - square obj; - obj.square_data(); - return 0; - } +int main() +{ + square obj; + obj.square_data(); + return 0; +} From 7fb3218ca3d50503ae2a8b7425ab11981cefdaed Mon Sep 17 00:00:00 2001 From: jinnudeveloper Date: Fri, 2 Sep 2016 08:20:46 +0530 Subject: [PATCH 10/17] Modify pgm by passing arguments along class object --- 02-generalize/02.cpp | 75 ++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/02-generalize/02.cpp b/02-generalize/02.cpp index 8475b8e..b28049d 100644 --- a/02-generalize/02.cpp +++ b/02-generalize/02.cpp @@ -4,20 +4,19 @@ #include using namespace std; -class square +class Square { + private: - int side,column,row; - char character; + int column,row,side; + char symbol; + public: - void square_data() + void square_generate(char function_symbol,int function_side) { - cout << "Enter character to print\n"; - cin >> character; - cout << "Enter side of Square\n"; - cin >> side; - - + symbol = function_symbol; + side = function_side; + if(cin) { try @@ -25,50 +24,58 @@ class square if(side < 1) throw side; else if(side == 1) - top_bottom(side); - else + top_bottomSide(side); + else square_draw(side); } - - catch(int exp) + + catch(int errorVariable) { - cerr << "Sorry! Expected Positive Integer Value For Box Side!\n"; + cerr << "Error: Expected Positive Integer Value For Box Side!\n"; square_draw(3); } } else - cerr << "Please Confirm Both Values Are Inserted or Wrong Data!"; + cerr << "Error: Confirm Both Values Are Inserted or Wrong Data!"; } - - void top_bottom(int var1) + + void top_bottomSide(int temporary_variable) { - for(column = 0; column < var1; ++column) - cout << character; + for(column = 1; column <= temporary_variable; column++) + cout << symbol; + cout << "\n"; } - - void left_right(int var2) + + void left_rightSide(int temporary_variable) { - for(row = 0; row < var2-2; ++row) + for(row = 1; row <= temporary_variable-2; row++) { - cout << character; - for(column=0; column < var2-2; ++column) + cout << symbol; + for(column=1; column <= temporary_variable-2; column++) cout << " "; - cout << character<<"\n"; + cout << symbol; + cout << "\n"; } } - - void square_draw(int var3) + + void square_draw(int draw_variable) { - top_bottom(var3); - cout << "\n"; - left_right(var3); - top_bottom(var3); + top_bottomSide(draw_variable); + left_rightSide(draw_variable); + top_bottomSide(draw_variable); } }; int main() { - square obj; - obj.square_data(); + int side; + char symbol; + cout << "Enter Symbol to draw\n"; + cin >> symbol; + cout << "Enter side of Square Box\n"; + cin >> side; + Square obj; + obj.square_generate(symbol,side); return 0; } + From 50732931b81525d790474240b6756f0ff5c33892 Mon Sep 17 00:00:00 2001 From: jinnudeveloper Date: Fri, 2 Sep 2016 08:54:40 +0530 Subject: [PATCH 11/17] Modify pgm by including Square.cpp file --- 02-generalize/02.cpp | 64 ++------------------------------------------ 1 file changed, 2 insertions(+), 62 deletions(-) diff --git a/02-generalize/02.cpp b/02-generalize/02.cpp index b28049d..9e35d6d 100644 --- a/02-generalize/02.cpp +++ b/02-generalize/02.cpp @@ -1,70 +1,10 @@ /* Program to illustrate drawing of a Square using Object and Class in C++ Programming */ -/*Exception Handling is applied for Validation*/ + #include +#include "Square.cpp" using namespace std; -class Square -{ - -private: - int column,row,side; - char symbol; - -public: - void square_generate(char function_symbol,int function_side) - { - symbol = function_symbol; - side = function_side; - - if(cin) - { - try - { - if(side < 1) - throw side; - else if(side == 1) - top_bottomSide(side); - else - square_draw(side); - } - - catch(int errorVariable) - { - cerr << "Error: Expected Positive Integer Value For Box Side!\n"; - square_draw(3); - } - } - else - cerr << "Error: Confirm Both Values Are Inserted or Wrong Data!"; - } - - void top_bottomSide(int temporary_variable) - { - for(column = 1; column <= temporary_variable; column++) - cout << symbol; - cout << "\n"; - } - - void left_rightSide(int temporary_variable) - { - for(row = 1; row <= temporary_variable-2; row++) - { - cout << symbol; - for(column=1; column <= temporary_variable-2; column++) - cout << " "; - cout << symbol; - cout << "\n"; - } - } - - void square_draw(int draw_variable) - { - top_bottomSide(draw_variable); - left_rightSide(draw_variable); - top_bottomSide(draw_variable); - } -}; int main() { From e0b01f447cc6baff1d9c83947ade8acd194c6f6a Mon Sep 17 00:00:00 2001 From: jinnudeveloper Date: Fri, 2 Sep 2016 08:55:34 +0530 Subject: [PATCH 12/17] Square draw pgm --- 02-generalize/Square.cpp | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 02-generalize/Square.cpp diff --git a/02-generalize/Square.cpp b/02-generalize/Square.cpp new file mode 100644 index 0000000..8767bec --- /dev/null +++ b/02-generalize/Square.cpp @@ -0,0 +1,67 @@ +/*Program illustrates the drawing of a Square Box in C++ programming*/ + +#include +using namespace std; + +class Square +{ + +private: + int column,row,side; + char symbol; + +public: + void square_generate(char function_symbol,int function_side) + { + symbol = function_symbol; + side = function_side; + + if(cin) + { + try + { + if(side < 1) + throw side; + else if(side == 1) + top_bottomSide(side); + else + square_draw(side); + } + + catch(int errorVariable) + { + cerr << "Error: Expected Positive Integer Value For Box Side!\n"; + square_draw(3); + } + } + else + cerr << "Error: Confirm Both Values Are Inserted or Wrong Data!"; + } + + void top_bottomSide(int temporary_variable) + { + for(column = 1; column <= temporary_variable; column++) + cout << symbol; + cout << "\n"; + } + + void left_rightSide(int temporary_variable) + { + for(row = 1; row <= temporary_variable-2; row++) + { + cout << symbol; + for(column=1; column <= temporary_variable-2; column++) + cout << " "; + cout << symbol; + cout << "\n"; + } + } + + void square_draw(int draw_variable) + { + top_bottomSide(draw_variable); + left_rightSide(draw_variable); + top_bottomSide(draw_variable); + } +}; + From 8add87758d75ca12b1e4166cf4774672a904f07c Mon Sep 17 00:00:00 2001 From: jinnudeveloper Date: Fri, 2 Sep 2016 13:15:58 +0530 Subject: [PATCH 13/17] Modify by passing argument through object --- 01-lets_get_started/01.cpp | 70 ++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 21 deletions(-) diff --git a/01-lets_get_started/01.cpp b/01-lets_get_started/01.cpp index 3f79aa4..9465d86 100644 --- a/01-lets_get_started/01.cpp +++ b/01-lets_get_started/01.cpp @@ -3,43 +3,71 @@ #include using namespace std; -class square +class Square { + private: - int side,column,row; + int column,row,side; + public: - void square_data() + void square_generate(int temporary_variable) { - cout << "Enter side of Square\n"; - cin >> side; - top_bottom(); - if(side > 1) + side = temporary_variable; + + if(cin) { - cout << "\n"; - left_right(); - top_bottom(); + try + { + if(side < 1) + throw side; + else if(side == 1) + top_bottomSide(side); + else + square_draw(side); + } + + catch(int errorVariable) + { + cerr << "Error: Expected Positive Integer Value For Box Side!\n"; + } } + else + cerr << "Error: Wrong Data!" << endl; } - void top_bottom() + + void top_bottomSide(int temporary_variable) { - for(column = 0; column < side; ++column) - cout << "#"; + for(column = 1; column <= temporary_variable; column++) + cout << '#'; + cout << "\n"; } - void left_right() + + void left_rightSide(int temporary_variable) { - for(row = 0; row < side-2; ++row) + for(row = 1; row <= temporary_variable-2; row++) { - cout<< "#"; - for(column=0; column < side-2; ++column) + cout << '#'; + for(column=1; column <= temporary_variable-2; column++) cout << " "; - cout << "#\n"; + cout << '#'; + cout << "\n"; } } + + void square_draw(int draw_variable) + { + top_bottomSide(draw_variable); + left_rightSide(draw_variable); + top_bottomSide(draw_variable); + } }; + int main() { - square obj; - obj.square_data(); + int side; + cout << "Enter side of Square Box\n"; + cin >> side; + Square obj; + obj.square_generate(side); return 0; } - From e6f420e7934fac50b47eaa3e45f4c2774fe125de Mon Sep 17 00:00:00 2001 From: jinnudeveloper Date: Mon, 5 Sep 2016 21:49:49 +0530 Subject: [PATCH 14/17] Rename Object --- 02-generalize/02.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/02-generalize/02.cpp b/02-generalize/02.cpp index 9e35d6d..4725c42 100644 --- a/02-generalize/02.cpp +++ b/02-generalize/02.cpp @@ -5,7 +5,6 @@ #include "Square.cpp" using namespace std; - int main() { int side; @@ -14,8 +13,7 @@ int main() cin >> symbol; cout << "Enter side of Square Box\n"; cin >> side; - Square obj; - obj.square_generate(symbol,side); + Square square; + square.square_generate(symbol,side); return 0; } - From 1a8a57f2846d68f9c6e039b6afd57d4881096acc Mon Sep 17 00:00:00 2001 From: jinnudeveloper Date: Mon, 5 Sep 2016 21:50:44 +0530 Subject: [PATCH 15/17] Add spaces and modify --- 02-generalize/Square.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/02-generalize/Square.cpp b/02-generalize/Square.cpp index 8767bec..b49ed9b 100644 --- a/02-generalize/Square.cpp +++ b/02-generalize/Square.cpp @@ -5,9 +5,8 @@ using namespace std; class Square { - private: - int column,row,side; + int column, row, side; char symbol; public: @@ -23,14 +22,14 @@ class Square if(side < 1) throw side; else if(side == 1) - top_bottomSide(side); + top_bottom_side(side); else square_draw(side); } catch(int errorVariable) { - cerr << "Error: Expected Positive Integer Value For Box Side!\n"; + cerr << "Error: Invalid Input. Expected Positive Integer!\n"; square_draw(3); } } @@ -38,19 +37,19 @@ class Square cerr << "Error: Confirm Both Values Are Inserted or Wrong Data!"; } - void top_bottomSide(int temporary_variable) + void top_bottom_side(int temp) { - for(column = 1; column <= temporary_variable; column++) + for(column = 1; column <= temp; column++) cout << symbol; cout << "\n"; } - void left_rightSide(int temporary_variable) + void left_right_side(int temp) { - for(row = 1; row <= temporary_variable-2; row++) + for(row = 1; row <= temp - 2; row++) { cout << symbol; - for(column=1; column <= temporary_variable-2; column++) + for(column=1; column <= temp - 2; column++) cout << " "; cout << symbol; cout << "\n"; @@ -59,9 +58,8 @@ class Square void square_draw(int draw_variable) { - top_bottomSide(draw_variable); - left_rightSide(draw_variable); - top_bottomSide(draw_variable); + top_bottom_side(draw_variable); + left_right_side(draw_variable); + top_bottom_side(draw_variable); } }; - From 37b53cbd1ae290e2026b5a7318ba58dd98415ae5 Mon Sep 17 00:00:00 2001 From: jinnudeveloper Date: Mon, 5 Sep 2016 22:25:26 +0530 Subject: [PATCH 16/17] Rename object and temporary variables --- 01-lets_get_started/01.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/01-lets_get_started/01.cpp b/01-lets_get_started/01.cpp index 9465d86..d5788c7 100644 --- a/01-lets_get_started/01.cpp +++ b/01-lets_get_started/01.cpp @@ -1,18 +1,16 @@ -/* Program to illustrate drawing of a Square using Object and Class in C++ Programming */ - +/* Square generating program */ #include using namespace std; class Square { - private: int column,row,side; public: - void square_generate(int temporary_variable) + void square_generate(int temp_side) { - side = temporary_variable; + side = temp_side; if(cin) { @@ -21,39 +19,39 @@ class Square if(side < 1) throw side; else if(side == 1) - top_bottomSide(side); + top_bottom_side(side); else square_draw(side); } catch(int errorVariable) { - cerr << "Error: Expected Positive Integer Value For Box Side!\n"; + cerr << "Error: Invalid data. Expected positive integer!\n"; } } else cerr << "Error: Wrong Data!" << endl; } - void top_bottomSide(int temporary_variable) + void top_bottom_side(int temp) { - for(column = 1; column <= temporary_variable; column++) + for(column = 1; column <= temp; column++) cout << '#'; cout << "\n"; } - void left_rightSide(int temporary_variable) + void left_right_side(int temp) { - for(row = 1; row <= temporary_variable-2; row++) + for(row = 1; row <= temp - 2; row++) { cout << '#'; - for(column=1; column <= temporary_variable-2; column++) + for(column=1; column <= temp - 2; column++) cout << " "; cout << '#'; cout << "\n"; } } - + void square_draw(int draw_variable) { top_bottomSide(draw_variable); @@ -65,9 +63,9 @@ class Square int main() { int side; + Square square; cout << "Enter side of Square Box\n"; cin >> side; - Square obj; - obj.square_generate(side); + square.square_generate(side); return 0; } From 2ce51b4228170a57e0d97218cabf5aea714caf33 Mon Sep 17 00:00:00 2001 From: jinnudeveloper Date: Mon, 5 Sep 2016 22:26:51 +0530 Subject: [PATCH 17/17] Modify Indentation --- 02-generalize/Square.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/02-generalize/Square.cpp b/02-generalize/Square.cpp index b49ed9b..dc629dd 100644 --- a/02-generalize/Square.cpp +++ b/02-generalize/Square.cpp @@ -40,7 +40,9 @@ class Square void top_bottom_side(int temp) { for(column = 1; column <= temp; column++) - cout << symbol; + { + cout << symbol; + } cout << "\n"; } @@ -50,7 +52,9 @@ class Square { cout << symbol; for(column=1; column <= temp - 2; column++) - cout << " "; + { + cout << " "; + } cout << symbol; cout << "\n"; }