diff --git a/01-lets_get_started/01.cpp b/01-lets_get_started/01.cpp new file mode 100644 index 0000000..d5788c7 --- /dev/null +++ b/01-lets_get_started/01.cpp @@ -0,0 +1,71 @@ +/* Square generating program */ +#include +using namespace std; + +class Square +{ +private: + int column,row,side; + +public: + void square_generate(int temp_side) + { + side = temp_side; + + if(cin) + { + try + { + if(side < 1) + throw side; + else if(side == 1) + top_bottom_side(side); + else + square_draw(side); + } + + catch(int errorVariable) + { + cerr << "Error: Invalid data. Expected positive integer!\n"; + } + } + else + cerr << "Error: Wrong Data!" << endl; + } + + void top_bottom_side(int temp) + { + for(column = 1; column <= temp; column++) + cout << '#'; + cout << "\n"; + } + + void left_right_side(int temp) + { + for(row = 1; row <= temp - 2; row++) + { + cout << '#'; + for(column=1; column <= temp - 2; column++) + cout << " "; + cout << '#'; + cout << "\n"; + } + } + + void square_draw(int draw_variable) + { + top_bottomSide(draw_variable); + left_rightSide(draw_variable); + top_bottomSide(draw_variable); + } +}; + +int main() +{ + int side; + Square square; + cout << "Enter side of Square Box\n"; + cin >> side; + square.square_generate(side); + return 0; +} diff --git a/02-generalize/02.cpp b/02-generalize/02.cpp new file mode 100644 index 0000000..4725c42 --- /dev/null +++ b/02-generalize/02.cpp @@ -0,0 +1,19 @@ +/* Program to illustrate drawing of a Square using Object and Class in C++ Programming */ + + +#include +#include "Square.cpp" +using namespace std; + +int main() +{ + int side; + char symbol; + cout << "Enter Symbol to draw\n"; + cin >> symbol; + cout << "Enter side of Square Box\n"; + cin >> side; + Square square; + square.square_generate(symbol,side); + return 0; +} diff --git a/02-generalize/Square.cpp b/02-generalize/Square.cpp new file mode 100644 index 0000000..dc629dd --- /dev/null +++ b/02-generalize/Square.cpp @@ -0,0 +1,69 @@ +/*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_bottom_side(side); + else + square_draw(side); + } + + catch(int errorVariable) + { + cerr << "Error: Invalid Input. Expected Positive Integer!\n"; + square_draw(3); + } + } + else + cerr << "Error: Confirm Both Values Are Inserted or Wrong Data!"; + } + + void top_bottom_side(int temp) + { + for(column = 1; column <= temp; column++) + { + cout << symbol; + } + cout << "\n"; + } + + void left_right_side(int temp) + { + for(row = 1; row <= temp - 2; row++) + { + cout << symbol; + for(column=1; column <= temp - 2; column++) + { + cout << " "; + } + cout << symbol; + cout << "\n"; + } + } + + void square_draw(int draw_variable) + { + top_bottom_side(draw_variable); + left_right_side(draw_variable); + top_bottom_side(draw_variable); + } +};