Write a C++ program to display the diamond-like pattern using the Constructor Overloading.
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
#include<iostream> using namespace std; class T4Tutorials_Constructor { protected : int i,j,s,rows; public : T4Tutorials_Constructor(int T4Tutorials_One) { for(i=1 ; i<T4Tutorials_One ; i++) { for(s=i ; s<T4Tutorials_One ; s++) { cout<<" "; } for(j=1 ; j<=2*i-1 ; j++) { cout<<"*"; } cout<<"\n"; } } T4Tutorials_Constructor (int T4Tutorials2, int T4Tutorials3) { cout<<"\nYour First Payramid For "<<T4Tutorials2<<" No of rows is given below\n"; for(i=1 ; i<T4Tutorials2 ; i++) { for(s=i ; s<T4Tutorials2 ; s++) { cout<<" "; } for(j=1 ; j<=2*i-1 ; j++) { cout<<"*"; } cout<<"\n"; } cout<<"\nYour Second Payramid For "<<T4Tutorials3<<" No of rows is given below\n"; for(i=1 ; i<T4Tutorials3 ; i++) { for(s=i ; s<T4Tutorials3 ; s++) { cout<<" "; } for(j=1 ; j<=2*i-1 ; j++) { cout<<"*"; } cout<<"\n"; } } }; int main() { cout<<"This Program Demonstrate The Single and"; cout<<"multiple paramter Constructor\n"; int option; cout<<"Enter 1 of Single parameter Constructor \n"; cout<<"\nEnter 2 For Multiple Paramter constucor \n"; cout<<"\nEnter 1 or 2 : "; cin>>option; system("cls"); //this function is to clear the screen if(option ==1) { cout<<"You Have Slected Single Paramater"; cout<<" Constructor\n\n"; int T4Tutorials_One; cout<<"Enter No of rows : "; cin>>T4Tutorials_One; T4Tutorials_Constructor a(T4Tutorials_One); } else if(option==2) { cout<<"You Have slected Multiple Paramater "; cout<<" Constructor"; int T4Tutorials2,T4Tutorials3; cout<<"Enter First No of Rows for 1st Payramid : "; cin>>T4Tutorials2; cout<<"\nEnter Second No of rows for 2nd Payramid : "; cin>>T4Tutorials3; T4Tutorials_Constructor a(T4Tutorials2, T4Tutorials3); } else { cout<<"Your Input in Wrong try Agin \n\n\n"; } } |