Single inheritance C++ program to display the pattern like a pyramid using the alphabet using single inheritance
Write a C++ Program to display the pattern like a pyramid using the alphabet using single inheritance.
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 43 | #include<iostream> using namespace std; class pyramid { protected: int i,k,j,bl,n,ct; char alp; }; class child:public pyramid { public: int pyr() { ct=1; alp='A'; cout<<"Input the number of letters(less than 26) in the pyramid: "; cin>>n; { for(i=1;i<=n;i++) { for(bl=1;bl<=n-1;bl++) cout<<" "; for(j=0;j<=(ct/2);j++) { cout<<alp++; } alp=alp-2; for(j=0;j<(ct/2);j++) { cout<<alp--; } ct=ct+2; alp='A'; cout<<endl; } } } }; int main() { child c; c.pyr(); } |