C++ OOP program to print stars in a Rhombus pattern using classes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
#include<iostream> // start using namespace std; //libraries class projectsinventory_DotCom_Rhombus // creating class { private: //private variables int r,sp; //declare int type variables public: //use for showing data anywhere in this program void disp() //create function { for(r=1;r<=4;r++) //loop for displaying the number of rows { for(sp=r;sp<4;sp++) //loop for printing the spaces in first row { cout<<" "; // cout for printing space } if(r==1||r==4) //condition for first or last row { for(sp=1;sp<=4;sp++) //loop for printing stars in first and last row if above condition is true { cout<<"*"; // for printing star } } else //print firstly 1 star then 2 spaces and then one star if "if condition" is false { cout<<"*"; // print star for(sp=1;sp<=2;sp++) // loop for print space in stars { cout<<" "; // for space } cout<<"*";// for star } cout<<endl;// when loop completed then computer come out side the loop } } }; int main() // main function { projectsinventory_DotCom_Rhombus obj; //create the object of class obj.disp(); // call function by object } |