PropellerAds
Posted by : Unknown Saturday, 4 October 2014

Creating a hollow square or rectangle in C++














// a rectangle boundry by asteriks
//including header files
#include<iostream>
#include<conio.h>

//including directives of iostream
using std::cout; //see out. for output same function as printf
using std::cin;  //see in. for output same function as scanf
using std::endl; //end line same as \n

//main function starting
void main() {
//initializing vars
int length, width, row, column;
//length input
cout << "Enter length less then 39: ";
cin >> length;
while (length>38){
cout << "plz Enter length less then 39: ";
cin >> length;
}

//initializing column of the rectangle
column = length;
//Taking width input
cout << endl << "Enter the Width: ";
cin >> width;
row = width;

//new line
cout << endl;

//printing length of the rectangle in first line
for(column; column >(length/2+1); column--){
cout << "  ";
}
cout << length;

//new line
cout << endl;
column = length;

//marking length of rectangle
for(column; column >0; column--){
cout << "--";
}
cout << endl;
column = length;

//begining of formation of rectangle
for(row ; row >0; row--) {
//top and bottom of rectangle
if (row == width || row == 1) {
for(column; column >0; column--){
cout << "* ";
}
cout << "|";
cout << endl;
column = length;
//middle portion of rectangle
else {
cout << "* ";
for(column; column >2; column--){
cout << "  ";
}
cout << "*";
cout << " |";
if (row == (width/2+1)) {
cout << width;
}
cout << endl;
column = length;
}

}
_getch();
}//end main

Leave a Reply

Subscribe to Posts | Subscribe to Comments

PropellerAds
PropellerAds

Popular Post

Powered by Blogger.

- Copyright © BSCS -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -