Posted by : Waqas Javed 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

Contact Us

Stay updated for more codes if we u want any code write us by commenting below or email us.
If you want to hire us for your semester project email us at above given email or call or message
Email: 14bscswjaved@seecs.edu.pk
Phone no: 0308-8109708

Popular Post

Powered by Blogger.

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