Projects Inventory

C++ OOP program  to print stars in a Rhombus pattern using classes

C++ OOP program  to print stars in a Rhombus pattern using classes.

#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
}

Advertisement

 

Exit mobile version