download all and run all samples from here ......!!
Purpose of this blog is to make programming easy , weak programmers may get help from my blog i tried my best to post some of my codes in form of easiest approach, I think this blog is perfect c++ guide in form of online blog. please consult my all codes and suggest all of it with your class mates. Share experiences & knowledge with your juniors. Make yourself habitual to write different programs for 2 hours a day daily.
Saturday, 8 March 2014
C++ hollow diamond program
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int Pheigt;
cout<<"Enter the height of paradigm:";
cin>>Pheigt;
int const margin_view = 20; //no need for constant it
int count;
int spaces_print;
int *ptr;
//**********************ROWS PRINT***************************************//
for(int i=0;i<=Pheigt;i++)
{
int spaces_to_print = margin_view +Pheigt - i; //*****************************//SETTING HOW MUCH SPACES TO PRINT
//cout<<spaces_to_print;
for(count = 0 ; count <= spaces_to_print; count++)
{
cout<<" ";
}
for(count = 0; count<=i*2; count++ ) //**********************PRINT STARS**************************//
{
if(count==0 || count==i*2)
{
cout<<"*";}
else{cout<<" ";}
}
ptr = &spaces_to_print;
//cout<<*ptr;
// cout<<spaces_to_print;
cout<<endl;
}
// cout<<*ptr;
int margins_view = *ptr; //current spaces store to new variable
//*************************Row Loop***********************************************//
for(int i=Pheigt;i>=0;i--)
{
spaces_print = margins_view + Pheigt - i;
// cout<<spaces_print;
for(count = spaces_print ; count >=0; count --)
{
cout<<" ";
}
for(count=i*2;count>=0;count--)
{
if(count==0 || count==i*2)
{
cout<<"*";}
else{cout<<" ";}
//cout<<"*";
}
//spaces
cout<<endl;
}
_getch();
}
Enter the height of paradigm:7
*
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
*
C++ DIAMOND PROGRAM EASY APPROACH WITH FULL DESCRIPTION
QUESTIONS IN MIND
height is set because program does not know what to draw you have to pass the height of above and below pyramid that program can knew that height is etc height = 10; then it has to use logical height 10 times.
why nested loop ?
Always Remember C++ compiler only draw in form of rows and column a loop
nested means loop under a loop
ROW(PROGRAMMING){
_________COL(PROGRAMMING)
}
first loop is for rows (------------------------------)to print
2nd loop is for the column to print
(
|
|
|
)
now how to draw above and below pyramid??
Usually most of the time teachers and colleagues don't tell you what is logic to print it in easy way, i am experienced person so i will help you guys
1)ROWS
first of all you have to print pass the loop to compiler C++ which starts from 0 and ends to height you know
in which it now needs to know in a line single or line by line
you have to use \n or endl to print row by row a (loop prints row)
2) COLUMNS
As you see pyramid
*
***
*****
you notices their are spaces and margin in center and printing '*' in both sides
how
you have to define integer variable to set margin = for example 10
know
you have to store spaces for rows you see spaces are row by row reduced to help static print at left
int spaces = margin_you have given + height you have give - rows loop current value
your spaces for current loop row will be set
you have to print spaces for this row
until this row spaces value reached
_______________________________
you above see line it shows space of current row
Now you have to print *
use a loop goes to current row*2 value of loop and print *
initally 0 then one star will be print
now
you se
_______________________________*
loop continues
row incremented
colomn space decremented
stars in row incremented
___________________________*
__________________________***
_________________________*****
________________________*******
_______________________*********
______________________***********
How much height you want to draw diamond?
Want to draw in Center of screen to show beauty?
if you dont pass spaces loop what happens?
why Nested Loop is important in this program?
Many questions are produced in mind of new programmers I have solution
why nested loop ?
Always Remember C++ compiler only draw in form of rows and column a loop
nested means loop under a loop
ROW(PROGRAMMING){
_________COL(PROGRAMMING)
}
first loop is for rows (------------------------------)to print
2nd loop is for the column to print
(
|
|
|
)
now how to draw above and below pyramid??
Usually most of the time teachers and colleagues don't tell you what is logic to print it in easy way, i am experienced person so i will help you guys
1)ROWS
first of all you have to print pass the loop to compiler C++ which starts from 0 and ends to height you know
in which it now needs to know in a line single or line by line
you have to use \n or endl to print row by row a (loop prints row)
2) COLUMNS
As you see pyramid
*
***
*****
you notices their are spaces and margin in center and printing '*' in both sides
how
you have to define integer variable to set margin = for example 10
know
you have to store spaces for rows you see spaces are row by row reduced to help static print at left
int spaces = margin_you have given + height you have give - rows loop current value
your spaces for current loop row will be set
you have to print spaces for this row
until this row spaces value reached
_______________________________
you above see line it shows space of current row
Now you have to print *
use a loop goes to current row*2 value of loop and print *
initally 0 then one star will be print
now
you se
_______________________________*
loop continues
row incremented
colomn space decremented
stars in row incremented
___________________________*
__________________________***
_________________________*****
________________________*******
_______________________*********
______________________***********
till height is given
now reverse do process for print in reverse order how?
______________________***********
_______________________*********
________________________*******
_________________________*****
__________________________***
___________________________*
first of all samely you have to pass row for loop then space for loop in between row loop same as stars loop
how you pass the space margin to other row for loop you have to use pointer for which you can get the margin space total gone and last time used for upper paramid now you can by using pointer save in it last value of margin space of pointer and pass to lower margin space pointer so which from you for loop row starts and ends to 0 to print in reverse order
in upper row for loop pass this code
ptr = &spaces_to_print;
it can saves last pointer then
after end of loop declare another space margin variable and pass this pointer to it and start the loop from it and till ends to 0
int margins_view = *ptr;
for(int i=Pheigt;i>=0;i--)
{
// your code
}
same above procedure but in reverse
spaces_print = margins_view + Pheigt - i;
and you have got upper and lower paramid form diamond i hope you will understand my code
now reverse do process for print in reverse order how?
______________________***********
_______________________*********
________________________*******
_________________________*****
__________________________***
___________________________*
first of all samely you have to pass row for loop then space for loop in between row loop same as stars loop
how you pass the space margin to other row for loop you have to use pointer for which you can get the margin space total gone and last time used for upper paramid now you can by using pointer save in it last value of margin space of pointer and pass to lower margin space pointer so which from you for loop row starts and ends to 0 to print in reverse order
in upper row for loop pass this code
ptr = &spaces_to_print;
it can saves last pointer then
after end of loop declare another space margin variable and pass this pointer to it and start the loop from it and till ends to 0
int margins_view = *ptr;
for(int i=Pheigt;i>=0;i--)
{
// your code
}
same above procedure but in reverse
spaces_print = margins_view + Pheigt - i;
and you have got upper and lower paramid form diamond i hope you will understand my code
- #include<iostream>
- #include<conio.h>
- using namespace std;
- void main()
- {
- int Pheigt;
- cout<<"Enter the height of paradigm:";
- cin>>Pheigt;
- int const margin_view = 20; //no need for constant it
- int count;
- int spaces_print;
- int *ptr;
- //**********************ROWS PRINT***************************************//
- for(int i=0;i<=Pheigt;i++)
- {
- int spaces_to_print = margin_view +Pheigt - i; //*****************************//SETTING HOW MUCH SPACES TO PRINT
- //cout<<spaces_to_print;
- for(count = 0 ; count <= spaces_to_print; count++)
- {
- cout<<" ";
- }
- for(count = 0; count<=i*2; count++ ) //**********************PRINT STARS**************************//
- {
- cout<<"*";
- }
- ptr = &spaces_to_print;
- //cout<<*ptr;
- // cout<<spaces_to_print;
- cout<<endl;
- }
- // cout<<*ptr;
- int margins_view = *ptr;
- for(int i=Pheigt;i>=0;i--)
- {
- spaces_print = margins_view + Pheigt - i;
- // cout<<spaces_print;
- for(count = spaces_print ; count >=0; count --)
- {
- cout<<" ";
- }
- for(count=i*2;count>=0;count--)
- {
- cout<<"*";
- }
- //spaces
- cout<<endl;
- }
- _getch();
- }
Thursday, 6 March 2014
C++ FULL PARAMID PROGRAM EASIEST APPROACH
QUESTIONS IN MIND
height is set because program does not know what to draw you have to pass the height of pyramid that program can knew that height is etc height = 10; then it has to use logical height 10 times.
why nested loop ?
Always Remember C++ compiler only draw in form of rows and column a loop
nested means loop under a loop
ROW(PROGRAMMING){
_________COL(PROGRAMMING)
}
first loop is for rows (------------------------------)to print
2nd loop is for the column to print
(
|
|
|
)
now how to draw pyramid??
Usually most of the time teachers and colleagues don't tell you what is logic to print it in easy way, i am experienced person so i will help you guys
1)ROWS
first of all you have to print pass the loop to compiler C++ which starts from 0 and ends to height you know
in which it now needs to know in a line single or line by line
you have to use \n or endl to print row by row a (loop prints row)
2) COLUMNS
As you see pyramid
*
***
*****
you notices their are spaces and margin in center and printing '*' in both sides
how
you have to define integer variable to set margin = for example 10
know
you have to store spaces for rows you see spaces are row by row reduced to help static print at left
int spaces = margin_you have given + height you have give - rows loop current value
your spaces for current loop row will be set
you have to print spaces for this row
until this row spaces value reached
_______________________________
you above see line it shows space of current row
Now you have to print *
use a loop goes to current row*2 value of loop and print *
initally 0 then one star will be print
now
you se
_______________________________*
loop continues
row incremented
colomn space decremented
stars in row incremented
___________________________*
__________________________***
_________________________*****
________________________*******
_______________________*********
______________________***********
How much height you want to draw paramid?
Want to draw in Center of screen to show beauty?
if you dont pass spaces loop what happens?
why Nested Loop is important in this program?
Many questions are produced in mind of new programmers I have solution
why nested loop ?
Always Remember C++ compiler only draw in form of rows and column a loop
nested means loop under a loop
ROW(PROGRAMMING){
_________COL(PROGRAMMING)
}
first loop is for rows (------------------------------)to print
2nd loop is for the column to print
(
|
|
|
)
now how to draw pyramid??
Usually most of the time teachers and colleagues don't tell you what is logic to print it in easy way, i am experienced person so i will help you guys
1)ROWS
first of all you have to print pass the loop to compiler C++ which starts from 0 and ends to height you know
in which it now needs to know in a line single or line by line
you have to use \n or endl to print row by row a (loop prints row)
2) COLUMNS
As you see pyramid
*
***
*****
you notices their are spaces and margin in center and printing '*' in both sides
how
you have to define integer variable to set margin = for example 10
know
you have to store spaces for rows you see spaces are row by row reduced to help static print at left
int spaces = margin_you have given + height you have give - rows loop current value
your spaces for current loop row will be set
you have to print spaces for this row
until this row spaces value reached
_______________________________
you above see line it shows space of current row
Now you have to print *
use a loop goes to current row*2 value of loop and print *
initally 0 then one star will be print
now
you se
_______________________________*
loop continues
row incremented
colomn space decremented
stars in row incremented
___________________________*
__________________________***
_________________________*****
________________________*******
_______________________*********
______________________***********
till height is given
//CODE
//CODE
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int Pheigt;
cout<<"Enter the height of paradigm:";
cin>>Pheigt;
int margin_view = 20; //no need for constant it
int count;
//**********************ROWS PRINT***************************************//
for(int i=0;i<=Pheigt;i++)
{
int spaces_to_print = margin_view +Pheigt - i; //*****************************//SETTING HOW MUCH SPACES TO PRINT
for(count = 0 ; count <= spaces_to_print; count++)
{
cout<<" ";
}
for(count = 0; count<=i*2; count++ ) //**********************PRINT STARS**************************//
{
cout<<"*";
}
// cout<<spaces_to_print;
cout<<endl;
}
_getch();
}
Subscribe to:
Posts (Atom)