Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
71 changes: 71 additions & 0 deletions 01-lets_get_started/01.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* Square generating program */
#include <iostream>
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 << " ";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check indentation.

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;
}
19 changes: 19 additions & 0 deletions 02-generalize/02.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* Program to illustrate drawing of a Square using Object and Class in C++ Programming */


#include <iostream>
#include "Square.cpp"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a line before using namespace std;

using namespace std;

int main()
{
int side;
char symbol;
cout << "Enter Symbol to draw\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a separate function to accept input.

cin >> symbol;
cout << "Enter side of Square Box\n";
cin >> side;
Square square;
square.square_generate(symbol,side);
return 0;
}
69 changes: 69 additions & 0 deletions 02-generalize/Square.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*Program illustrates the drawing of a Square Box in C++ programming*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try not to use obvious comments. If you really have to use it, make it very short & simple. Consider:

/* Square pattern generating class */


#include <iostream>
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider indenting the statements of the preceding if/else.

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);
}
};