Write a C++ program to display the diamond-like pattern using the Inline function.
The inline function inline int T4Tutorials::in()
and inline int T4Tutorials:: T4Tutorials_Function()
helps to increase the execution time of a program. The programmer can make a request to the compiler to make the inline function as inline int T4Tutorials::in()
and inline int T4Tutorials:: T4Tutorials_Function()
.
Making inline means that compiler can replace the function definitions of inline int T4Tutorials::in()
with the place where this function is called obj. in();
and obj. T4Tutorials_Function();
.
The compiler replaces the definition of inline functions at compile time instead of referring function definition at runtime.
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 |
# include<iostream> using namespace std; class T4Tutorials { protected: int i,j,s,rows; public: int in(); int T4Tutorials_Function(); }; inline int T4Tutorials:: in() { cout<<"enter no of rows:"; cin>>rows; }; inline int T4Tutorials:: T4Tutorials_Function() { for(i=1; i<=rows; i++) { for(s=i; s<rows; s++) { cout<<" "; } for(j=1; j<=2*i-1; j++) { cout<<"*"; } cout<<"\n"; } } int main() { T4Tutorials obj; obj. in(); obj. T4Tutorials_Function(); } |