Saturday, 24 December 2016

How to play sound in C/C++ language using CodeBlock IDE

Playing  sound in C/C++ language is very interesting.

So, I am back with a code that plays a sound using C/C++ language in CodeBlocks IDE.This is a little code and here we go .........


#include<conio.h>
#include<windows.h>
int main()
{

    Beep(100,500);

    getche();

    return 0;

}

Now ,thats all we have to do to complete this task.And its time to explain the Code.

Explanation:-

Beep() is a function that is used to emit sounds of certain frequency .There are two parameters in this function.The first one is the frequency of the sound and the other one is the duration to play that sound .The most important thing about this function is that it belongs to the header file windows.h .
So to do these all you have to include windows.h header file.You can use this function in both the lnaguages C/C++.Now , we talk about the return value of this function .

Returns 0 if the function does not succeed.

Returns non-zero value if it succeed.

Beep(frequency as integer,duration in miliseconds)



 

Wednesday, 2 November 2016

C program to count days till the year given by user

This program illustrates a bit combination of logical and programming concepts of calender .And its easy to code and understand it you know the basics of C programming .In this program i have used some functions for just decorating the program output and might not work on turbo c++ compiler.And one more caution about this code when you compiler and run it in Turbo C++ compiler then it will give you logical error.It will calculate and give correct output in turbo till 170 years.So its better to use this program in other compiler like Dev C++,Codeblocks,Codelite etc.This is why because turbo C++ is very old and buggy.

Recommendation:use codeblocks or dev C++ IDE to make this program

Its coding time:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
int i, yy=0 ,l_days=0;
long int  t_days=0  ;
system("cls");
system("color 1e");                         //for changing background and text color
printf("\nCount total days till the given years");
printf("\nEnter the year::");
scanf("%d",&yy);
t_days=yy*365;                                           //counts the days of the simple years till yy years

for(i=1;  i<=yy;  i++)
{
if(i%100==0)                                        //condition for century
{
if(i%400==0)                         //condition for leap year in century
l_days++;
}
else
if(i%4==0)                                     //condition for leap year
l_days++;
}
printf("\nleap years extra days::%d",l_days);

printf("\ntotal years days::%u",t_days);

t_days=t_days+l_days;

printf("\ntotal days till%d is::%u",yy,t_days);

getche();

return 0;
}

output of the program
output of the program


Description :

In this program user will enter the year and this program will count the total day till that year and displays .system("cls") is used to clear screen like clrscr() function.

Logic:we have variable yy to take input from user and then we multiply yy to 365 so that we get the total days and store it in another variable t_days.But we have also leap years and their extra days to be added in the t_days to get net result.

Now the rest logic is on leapyear days .As we know the century that is divided by 400 will be the leapyear otherwise not.So in the for loop we check yy%100==0 ,if it is true then it is century and we then check whether divisible by 400 or not .I divisible by 400 then it is leap year and we increment the variable l_days by one.

The second part of the leap year,if it is not century and divided by 4 then it is leapyear and we increment the variable l_days by one.

At last we add all the days to get the net result like::total days=leap year extra days+total days by simple years.

I hope you understood the things.

we will come soon with another program so must visit again.



Thursday, 20 October 2016

PROGRAMMING AND COMPUTER MANIA: The instructions that a beginner programmer must f...

PROGRAMMING AND COMPUTER MANIA: The instructions that a beginner programmer must f...: Hello friends in this post i am going to share The instructions that a beginner programmer must follow while making a C program.If we are a...

The instructions that a beginner programmer must follow while making a C program

Hello friends in this post i am going to share The instructions that a beginner programmer must follow while making a C program.If we are able to drive these problems out then we can be a good programmer.These problems are very common and sometimes they frustrate the students.Consequently, students think that programming is very difficult.So if you are a beginner then you should think programming is very easy and you can do it .The most important thing in learning programming is the interest of domain.You are interested then you will learn easily.So generate your interest ....

Here are the key points....

1.ALWAYS START WITH ZERO LEVEL

If you  want to learn somethig and you dont know the abc of that thing then  you must start with the basics and gradually you will learn more and more concepts till the advanced topics.Now a days the students want to learn the advanced concepts before learning the basics.

2.READABILITY

Use tab in the program so the you will find it easy to counter errors in your program . Don't make the code complex.

3.ALWAYS FIND THE ALTERNATE SOLUTION

If you are making a program then you must find the alternative way to solve the problem.This will boost your logical skill.


4.SEARCH AND RESEARCH 

Search and research on internet so that you will aware of the new things .you will come across a lot of things that will help you in learning the typical things.

5.PRACTICE 

Do practise a lot to get experience in coding.You will learn key concepts and will be aware of errors .

6.CREATE INTEREST

Create interest in making program then you will learn fast and grab the things easily.
                     
                         Search the querry that you have on internet or ask your teachers without any hesitations.

Thank you for visiting us ......happy coding.......

we will come  with new facts and figure ,tips and tricks so visit again...

 

Monday, 17 October 2016

How to create a C program without main function

              C PROGRAM WITHOUT MAIN FUNCTION

Hello friends... 
we always create a program in C and C++ programming language and the most important thing is that we create a main function in every program.We are also taught by the teachers that we can not create a C program without main function .As we know main is a user defined function so can we make a C program without main function?
Yes we can....


So in this post i will show you how to achieve this task.
here is the code...

#include<stdio.h>
#include<conio.h>
#define begin main
int begin()
{
              clrscr();
              printf("This program is without main function");
              getch();
              return 0;
}

This program will  compile and run successfully .

So this was all for this post we will come with new and interesting typical programmming in C that make a lot of fun.








Tuesday, 4 October 2016

How to make a folder with no name

Hello friends ,

Today we are going to create a folder which has no name in window operating system.In window operating system there is a facility or feature which is Unicode Control Character .They are invisible and represented as non printable characters.

Unicode Control Characters(by computerhope.com)-non-printing character, also called a control character, is a number that represents a non-written or non-printable character (letter, number, or symbol). Some control characters represent audible or silent signals to be sent or received. Other control characters (ASCII code) include the backspace, line feed, form feed, carriage return, escape, and delete.






 Here are the steps to make a folder with no name:

step 1-Create a new folder          

step 2-delete the default name which is 'New Folder' then right click 

step 3-select insert unicode control characters

step 4-now you can select any of the options except the last two options.


And now we have successfully created the folder with no name.


We will come with new tips or new coding of typical C programs, So visit again ...........





Monday, 3 October 2016

how to create a 3d animation in C language

HOW TO CREATE A 3D ANIMATION IN C LANGUAGE

Hello friends we always want to do something new so that we can improve ourselves in every field of our lives.
Here i have created a program of 3d animation in C language .I have used turbo C++ compiler for this and also recommend you to use if you are running this program.Its ouput is pretty much cool and you can customize it your own so enjoy it....
Here is the code.....
ALSO SEE:TYPING GAME PROJECT IN C


#include<conio.h>
#include<stdio.h>
#include<graphics.h>
void happy();
int main()
   {
happy();
return 0;
}
void happy()
{
int x,y, gd = DETECT, gm;
     char arr[]="HAPPY TEACHER'S DAY 2016",arr1[]="They say that...'Experience is the best teacher'";
     int i;
     initgraph(&gd,&gm,"c:\\tc\\bgi");//used to initialised the graphics
     settextstyle(SCRIPT_FONT,HORIZ_DIR,3);//used to change the text style and size
    setcolor(4); // used to set the color of the output text
     outtextxy(50,170,arr1);  //used to print msg at the given position cursor
     outtextxy(50,190,"But for us...");
     outtextxy(50,210,"Having you as our teacher is the best experience!");
     settextstyle(TRIPLEX_FONT,HORIZ_DIR,1);
     setcolor(GREEN);
outtextxy(300,350,"Created By :: Shashi Kumar");
settextstyle(TRIPLEX_FONT,HORIZ_DIR,5);
     while(!kbhit())
{
     for(i=100;i<110;i++)
     {
outtextxy(50,i,arr);
setcolor(i);
delay(200); // pause the program
     }
}       getch();
     
system("cls");  // substitution for CLRSCR();
closegraph();
}
ALSO SEE::HOW TO CHANGE THE BACKGROUND COLOR OF TURBO C++ EDITOR'S BACKGROUND

Saturday, 10 September 2016

typing game project in c language

Typing game project in C language

I have used a header file shashi.h which is created by me because this project is created in codeblocks compiler.so if you are trying to create it in turbo c++ then there is no need to include shashi.h header file and you have to use textcolor() insted of setcolor().
The code is here.
#include<time.h>
#include<conio.h>
#include<stdio.h>
#include<dos.h>
#include<stdlib.h>
#include<shashi.h>//contains the definition of gotoxy,setcolor etc.
static int x=1;//used for x cursor co-ordinate
#define pos gotoxy(33,x++) /*for cursor movement*/
#define ln  printf(".......................");
//.......................................................................................................................................................................

//.................................................................................................................................................................................
void sett();//sets time limit for playing game
int t=30;
int c=0;

int size =5;
int limit=5;
char name[15];
void rstring();
void getscore(int score,int speed,int level);
void startgame();  //to start the game
void scorecard();  //to update high score
void About_me();
void help();
//...............................................................................................................................................................................

void rectangle(int x,int y,int l,int b)//to create a rectangle
{
    int i,m;
    gotoxy(x,y); printf("%c",201);
    for(i=x+1;i<l-1;i++)
    {
        gotoxy(i,y);
        printf("%c",205);
    }
    gotoxy(i,y); printf("%c",187);

    for (m=y+1;m<b;m++)
    {
        gotoxy(x,m);
        for(i=x;i<l;i++)
        {
            if(i==x||i==l-1)
            {
                gotoxy(i,m); printf("%c",186);
            }

        }

    }

    gotoxy(x,m); printf("%c",200);
    for(i=x+1;i<l-1;i++)
    {
        gotoxy(i,m);
        printf("%c",205);
    }
    gotoxy(i,m); printf("%c",188);
}

//................................................................................................................................................................................
// main function
int main()
{       int ch;

time_t t;
time(&t);
// rectangle(0,0,70,15);
x=1;
system("cls");
pos;
setcolor(12) ;
printf("welcome to typing game ");
setcolor(10) ;
pos;
printf("%s",ctime(&t));
pos;
    ln pos;
if(c==0)
  { printf("Enter player's name::");
gets(name);
  }
  c++;
pos;ln pos;
printf("#..MAIN MENU..#");pos;
ln
pos;
printf("1.startgame");
pos;
printf("2.scorecard");
pos;
printf("3.Set the time limit::");
pos;
printf("4.Help");
pos;
printf("5.About me");
pos;
printf("0.exit");
pos;
printf("Enter your choice::");
scanf("%d",&ch);
pos;
switch(ch)
{       case 1:startgame();break;
case 2:scorecard();break;
case 3:sett();main();
case 4:help();break;
case 5:About_me();break;
case 0:system("cls");gotoxy(17,10);printf("#This Game is created by Shashi Kumar#");delay(1000);exit(1);
default:main();
}

getch();
}
//.....................end of main function.................................

  //startgame
//..........................................................................
void startgame()
{       int score=0,level=1,mode=100,count=0;
clock_t begin;int time_spent,speed;

int r,letter,ch;
rectangle(0,0,70,15);
delay(500);

system("cls");
srand(time(NULL)) ; //initilizes random function and seed with time
x=2;
pos;
setcolor(12);
printf("#select the Mode#");pos;
ln
pos;
printf("1.Easy mode(upper case alphabet)#");
pos;
printf("2.Normal mode(lower case alphabet)#");
pos;
printf("3.hard mood(words)#");
pos;
printf("4.Back to main menu#");
pos;
scanf("%d",&level);
if(level==4)
main();

else

{     if(level==1)    //boundary addition for lowercase alphabet
      mode=65;
    if(level==2)    //boundary addition for uppercase
mode=97;
    if(level==3)    //condition for mixed case
rstring();
            else
            {
                    begin=clock();
                    while(1)
                    {           system("cls");
                                time_spent=(int)(clock()-begin)/CLOCKS_PER_SEC;

                                if(time_spent>=t)
                                        break;
                                r=rand()%1000;
                                r=r%26+mode;
                                gotoxy(20,8);
                                printf("....Type the following character....");
                                gotoxy(36,11) ;
                                printf(" %c",r); //prints random character

                                letter=getch();

                                if(letter!=r)
                                    break;
                                else
                                    {       count++;
                                            score=score+10;
                                            gotoxy(28,9);
                                            printf("score=%d",score);//prints score
                                            gotoxy(37,9);
                                            printf("time_spent=%d sec",time_spent);//prints time spent during game

                                            if(level==1)
                                            delay(400);
                                            if(level==2)
                                            delay(200);
                                            if(level==3)
                                            delay(100);

                                    } //end of else
                        }//end of while

                                    gotoxy(26,x);

                                    delay(400);

                                    setcolor(5); //blue text color
                                    ++x;
                                    pos;
                                    speed=(count*60)/time_spent ;

                                    if(time_spent<t-1)
                                    printf("You  are looser!loser!loser!Game Over!");
                                    else
                                    {       setcolor(11);
                                            printf("Times up !Game over!");
                                            pos;
                                            setcolor(5);
                                            if((speed>=40)&&(speed<=50))
                                            { printf("Good Work !Keep it up!");pos;

                                                printf("You got silver medal");
                                            }
                                            else
                                            if(speed>50)
                                            {
                                            printf("Nice work! You got Gold medal");
                                            }
                                            else
                                            printf("Sorry no medal !you need practise..");
                                    }
                                                pos;
                                                printf("Total score is ::%d",score);
                                                pos;

                                                printf("Your net speed=%d letter per minute",speed);

                                                getscore(score,speed,level);//saves data to file
                                                ++x;
                                                pos;
                                                printf("1.# play again #");
                                                pos;

                                                printf("2.# main menu #");pos;
                                                printf("3.exit"); pos;
                                                printf("Enter your choice::");
                                                scanf("%d",&ch);
                                                switch(ch)
                                                {
                                                        case 1:startgame();break;//recursive call
                                                        case 2:main();break;
                                                        case 3:system("cls");gotoxy(17,10);printf("#This Game is created by Shashi Kumar#");delay(1000);exit(1);
                                                        default:pos;printf("wrong choice!");pos;
                                                                main();
                                                }
            }

        }

}
//......................end of start game function..........................


//...........................sett function starts..........................
void sett()  //set time limit
{
int ch;
system("cls");
//rectangle(0,0,70,15);
setcolor(11);
x=5;
pos;
printf("Set the time limit for game in minute::");
pos;
ln
pos;
printf("press 0 for half minute") ;pos;
printf("press 1 for 1 minute"); pos;
printf("press 2 for 2 minute");pos;
scanf("%d",&ch);
switch(ch)
{
case 0:t=30;break;
case 1:t=60;break;
case 2:t=120;break;
default:main();
}
}
//....................sett function ends....................................

//........................................................................
void help()
{
system("cls");
//rectangle(0,0,70,15);
gotoxy(7,5);
setcolor(6);

printf("#......Rules of the Game......#");gotoxy(7,6);
printf("=>Enter your name as player name");gotoxy(7,7);
printf("=>Set the time limit under option 3 in main menu(default limit is 30 sec)");gotoxy(7,8);
printf("=>select the level and get started :");gotoxy(7,9);
printf("=>Characters are displayed and you have to type them as fast as you can..");gotoxy(7,10);
printf("=>Avoid incorrect typing otherwise game will be over..");gotoxy(7,11);
printf("=>Hit Enter in hard mode after typing the word:");

getch();main();
}
void About_me()
{       system("cls");
gotoxy(7,7);
printf("Hello everyone i am shashi ,BCA 1st year student in DBGI ,Dehradun.");
       printf(".I think it would be better....thanks...");
       getch();
       main();
}
//.........................................................................
void getscore(int score,int speed,int level)
{
FILE *fp;
fp=fopen("file.txt","a");
pos;
if(fp==NULL)
printf("error in opening file");
fprintf(fp,"\nname=%s   score=%d    speed=%d    level=%d",name,score,speed,level);
fclose(fp);
pos;
//printf("scorecard updated");
}
void scorecard()
{       int ch;
FILE *fp;
system("cls");
//rectangle(0,0,70,15);
x=3;

printf("\t\t\t....The scores are...\n");

fp=fopen("file.txt","r");
while((ch=fgetc(fp))!=EOF)
{ printf("%c",ch);
}
getch();
main();
}
//.....................................................................................................................
//function for third level hard mode (to generate the strings randomly)
void rstring()
{       int time_spent,score=0,level=3,speed=0;
        pos;
        setcolor(13);
        printf("Enter the no of letters of the word::");
        scanf("%d",&limit);
        pos;

        srand(time(NULL));
        clock_t begin;
        begin=clock();

        while(1)
        {   // printf("Enter the following word");
            system("cls");

            x=8;
             pos;
             printf("Enter the following word");
time_spent=(int)(clock()-begin)/CLOCKS_PER_SEC;
if(time_spent>=t)
            {
               pos;
                     printf("\t......Times Up.....");
                     pos;
                     speed=(score*60)/(time_spent*20);
                     printf("Total score=%d    speed=%d word per minute",score,speed);pos;
                     getscore(score,speed,level);
                      printf("Enter any key to go to  back menu..");
                     getch();
                     startgame();
            }

            pos;
            printf("time_spent=%d     score=%d",time_spent,score);
            size=limit;
            char src1[size];
            char src[size];
        //size = rand() % size; // this randomises the size (optional)

        src[size] = '\0'; // start with the end of the string...

      // ...and work your way backwards
        while(--size > -1)
          src[size] = (rand() % 26) + 97;
            pos;
            puts(src);
            pos;
            scanf("%s",&src1);
          if(strcmp(src,src1))
                 {  pos;
                     printf("\t......wrong.....");
                     pos;
                     speed=(score*60)/(time_spent*20);
                     printf("Total score=%d    speed=%d word per minute",score,speed);pos;
                     getscore(score,speed,level);
                     printf("Enter any key to go to  back menu..");
                     getch();
                      startgame();
                 }
            else
              {    score=score+20;
                  continue;
              }
}

}






program to create an animated heart in C++ language




Today i am sharing the code for animated heart in c++

#include<conio.h>
#include<iostream>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<shashi.h> // header file is created by me which contains the definitions of delay,setcolot,gotoxy,and some others functions
using namespace std;
void heart()

{       int i,j,n=3;
    while(1)//for infinately use for the heart to be created.
    {            n=3;
                delay(500);
        setcolor(10);
        cout<<"\n\n\t";
        for(i=1;i<=n;i++)//loop for upper part
        {   setcolor(i+5);//IN Turbo C++ use "textcolor" instead of setcolor
                delay(500);  //Delay is used to delay the program execution

            for(int j=1;j<=(n-i);j++)//loop for space for upper part
                cout<<" ";

            for(j=1;j<=i+2;j++)//upper part  1st tomb pattern
               {cout<<"* ";
                setcolor(i+j);
               }

            for(j=1;j<=2*(n-i);j++)//upper part  2nd tomb pattern
                cout<<" ";
            for(j=1;j<=i+2;j++)
                {cout<<"* ";
                 setcolor(i+5);
                }
                cout<<"\n\t";
        }

        n=11;
        for(i=1;i<=n;i++)//loop for rest triangle
        {    delay(500);
            for(j=1;j<=2*i-j;j++)
               {    if(i==1)
                   cout<<" ";
                   if(i>1)
                    cout<<"  ";
               }

            for(j=1;j<=(n-i*2);j++)
               {cout<<"* ";
                setcolor(i);
               }

            cout<<"\n\t";
        }
                gotoxy(20,20);cout<<"::Created by shashi::";//gotoxy is used to set cursor position rowwise and columnwise
                delay(500);
                system("cls");//In Turbo C++ use clrscr() in place of system("cls")
    }//End of while loop

}
int main()
{
    heart();
    return 0;
}

Monday, 18 July 2016

C program to find time spent by a function

            C program to find time spent by a function         

We write a lot of programs and functions and became happy after finishing it but 
we must care for their complexity in terms of space as well as time.The program or algorithm which takes less time and less memory is the best .So ,if we want to find the time spent by a function then must use the piece of code given below..........
//C program to find time spent by a function
#include<conio.h>
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<dos.h>
int main()
{
    int i=0,time_spent;
    clock_t begin;
    begin=clock();
    for(;i<10;i++)
    {   time_spent=(int)(clock()-begin)/CLOCKS_PER_SEC;
        printf("shashi  ");
        delay(1000);//delays the execution for 1 sec
    }
    printf("time spent by the function =%d second",time_spent);
    getch();
    return 0;
}
output:-

Tuesday, 28 June 2016

How to change Turbo C++ compiler editors background color

Hello friends in this post i will give you an idea about how to change Turbo C++ compiler's editors background which is blue  by default .Most of the students do not know that it can be changed and we can customise it our own .The turbo C++ gives the freedom to change the color of every part of the compiler.This is very funny and you will really enjoy  doing it .This is the picture after changing the color of the compiler.


Now for doing this go to option menu then select environment then select color  from dropdown menu.
Then you have to select edit window and on the half right side you have to change the background color for each and every  part .But you must care for that the foreground and background for one part must not be same otherwise it will be invisible.

You can also watch my video on youtube  How to change the  editor's blue  background of the Turbo C++ Compier .It will give you full guide to customise the background of Turbo C++ compiler's editor. 
I hope you enjoyed it ........





Welcome

Hello!!!!
This is Shashi doing graduation in computer application and like to play with computers and programming.I have created lots of different pattern programming and other programs in C language .So i just want to share whatever i will create because it will give a lot of confidence as well as motivation to carry on my path.  
                                                                                                             Thanks.........