#include<bits/stdc++.h>
using namespace std;
void halfPyramid();
void fullPyramid();
void rectangle();
void hollowRectangle();
void butterfly();
int main() {
int choice;
// Give options to the user.
cout << "!!! Press 0 to Exit !!!"<<endl;
cout << "1. Print Half Pyramid of Stars"<<endl;
cout << "2. Print Full Pyramid of Stars"<<endl;
cout << "3. Print Rectangle of Stars"<<endl;
cout << "4. Print Hollow Rectangle of Stars"<<endl;
cout << "5. Print Butterefly of stars"<<endl;
do {
// Take input of choice
cin>>choice;
cout << "\nEnter the Choice: "<<choice<<endl;
switch (choice) {
// If he entered 0, exit.
case 0:
return 0;
// Print half pyramid on entering 1.
case 1:
halfPyramid();
break;
// Print full pyramid on entering 2.
case 2:
fullPyramid();
break;
// Print rectangle on entering 3.
case 3:
rectangle();
break;
// Print hollow rectangle on entering 4.
case 4:
hollowRectangle();
break;
// Print butterfly on entering 5.
case 5:
butterfly();
break;
// If the choice doesn't match, print the following message
default:
cout << "\n !!! Incorrect Choice !!!";
}
} while (choice != 0);
return 0;
}
void halfPyramid() {
int rows;
cin >> rows;
cout <<"Triangle of "<<rows<<" using *:"<<endl;
// Main logic to print triangle.
for (int i = 0; i < rows; i++) {
for (int j = 0; j <= i; j++) {
cout << "* ";
}
cout << endl;
}
}
void fullPyramid() {
int rows;
cin >> rows;
cout << "Full Pyramid of "<<rows<<" using *"<<endl;
// Main logic to print full pyramid.
for (int i = 0; i < rows; i++) {
int spaces = rows - i;
for (int j = 0; j < spaces; j++) {
cout << " ";
}
for (int j = 0; j < 2 * i + 1; j++) {
cout << "* ";
}
cout << endl;
}
}
void rectangle() {
int rows, cols;
cin >> rows;
cin >> cols;
cout << "Rectangle of dimensions "<<rows<<"x"<<cols<<endl;
// Main logic to print Rectangle.
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
cout << "* ";
}
cout << endl;
}
}
void hollowRectangle() {
int rows, cols;
cin >> rows;
cin >> cols;
cout << "Rectangle of dimensions "<<rows<<"x"<<cols<<endl;
// Main logic to print hollow rectangle.
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
// If the index is at the border, then print *.
if (i == 0 || i == rows - 1 || j == 0 || j == cols - 1)
cout << "* ";
else
cout << " ";
}
cout << endl;
}
}
void butterfly(){
int rows;
cin >> rows;
cout << "Butterfly Pattern of rows "<<rows<< endl;
// Main logic to print the Butterfly pattern.
// Printing upper part.
for( int i = 0; i <= rows; i++ ){
// Print left side stars.
for( int j = 0; j <= i; j++ ){
cout << "* ";
}
// Print spaces.
int spaces = 2 * (rows - i);
for( int j = 0; j < spaces; j++){
cout << " ";
}
// Print right side stars.
for( int j = 0; j <= i; j++ ){
cout << "* ";
}
cout << endl;
}
// Printing bottom part.
for( int i = rows - 1; i >= 0; i-- ){
// Print left side spaces.
for( int j = 0; j <= i; j++ ){
cout << "* ";
}
// Print spaces.
int spaces = 2 * (rows - i);
for( int j = 0; j < spaces; j++){
cout << " ";
}
// Print right side stars.
for( int j = 0; j <= i; j++ ){
cout << "* ";
}
cout << endl;
}
}