Projects Inventory

C++ OOP program  to print pyramid of a number

C++ OOP program  to print pyramid of a number.

#include<iostream>  // header file
using namespace std;  //name space

class projectsinventory_DotCom  // class  is created with name of "projectsinventory_DotCom"
{
	protected:
 	int i,j,k,l,n;  
	 
	//"i,j,k,l,n" are variable names which are created by int data type
	// it is protected which accessiable by only this and childs class(If any)
	
 	public:
	int show()      
	// show is function and it is public.That means this function is accesiable anywhere outside the class
	{
		// starting the show function
		cout<<"num of rows :";   // user have to enter number of rows
 		cin>>n;    // input in "n" name variable
 
 		for(i=1;i<=n;i++)   
		// loop is started with no 1 ,and in which i is lessthan equal to n,an increment in loop
        // until the condition is true
 		{
 			for(l=1;l<=n-i;l++)  
			// for loop having another loop which started with num 1,1 is lessthan equal to n-i
            // loop having increment if the condition is true
 			{
 				cout<<" ";      // adding spacing
 			}
 
 			for(j=1;j<=i;j++)    
			// loop is starting in which j variable equal to 1,in loop j is lessthan equal to i
            // loop having increment if condition is true
 			{
 				cout<<j;   	           // display the value of which is stored in the variable  j
 			}
 
 			for(k=i-1;k>=1;k--)    
			// loop is started in which variable k stored i-1,k is greaterthan equal to 1
            // if condtion is true loop having decrement
 			{
 				cout<<k;               // display the value which is stored in variable k
 			}
 			
			cout<<endl;       // going to next line
 		}
 	}
};

int main()      // main function is performing
{
 projectsinventory_DotCom obj;   //projectsinventory_DotCom is the class  and obj is the object of the class projectsinventory_DotCom.
                    //we can access the show funtion of class projectsinventory_DotCom with the help of this object.
                    
 obj.show(); //show function is a property of object obj and obj is a object of class projectsinventory_DotCom
}

 

Exit mobile version