Thursday, 28 March 2013

C++ Casino Game Project

About The Project : 


Casino Game is very simple text based game designed in C++ Programming. In this game also we have not used any graphics. So this is simple project for beginners like 11th or 12th class student can learn basic project concept by my this article. In Casino Game player can deposit fund to play. From this amount he can bet on number between 1 to 12.  By winning game player will get 10 times of his fund or else will loss all fund.



Source Code : 


<pre class="brush: cpp">
#include&lt;iostream.h&gt;
#include&lt;conio.h&gt;
#include&lt;stdlib.h&gt;
#include&lt;stdio.h&gt;
#include&lt;time.h&gt;
void draw_line(int n,char ch);
void rules();
void main()
{
int balanceamt,amt,no,dice;
char playername[80],ch;
clrscr();
draw_line(60,'=');
cout&lt;&lt;"nnnnttCASINO GAMEnnnn";
draw_line(60,'=');
cout&lt;&lt;"nnnEnter Your Name :";
gets(playername);
cout&lt;&lt;"nnEnter Deposit amount to play game :";
cin&gt;&gt;balanceamt;
do
{
clrscr();
rules();
cout&lt;&lt;"nnYour current balance is Rs."&lt;&lt;balanceamt;
do
{
cout&lt;&lt;"nn"&lt;&lt;playername&lt;&lt;" enter money to bet";
cin&gt;&gt;amt;
if(amt&gt;balanceamt)
cout&lt;&lt;"Your betting amount is more than your current balancennRe-enter datan ";
else
break;
}while(1);
do
{
cout&lt;&lt;"Enter your lucky number to bet between 1 to 12 :";
cin&gt;&gt;no;
if(no&lt;=0||no&gt;12)
cout&lt;&lt;"Please check the number!! should be between 1 to 12nnRe-enter datan ";
else
break;
}while(1);
randomize();
dice=random(12)+1;
if(dice==no)
{
cout&lt;&lt;"nnGood Luck!! You won Rs."&lt;&lt;amt*10;
balanceamt=balanceamt+amt*10;
}
else
{
cout&lt;&lt;"Bad Luck this time !! You lose Rs."&lt;&lt;amt;
balanceamt=balanceamt-amt;
}
cout&lt;&lt;"nnThe winning number was : "&lt;&lt;dice;
cout&lt;&lt;"nnt"&lt;&lt;playername&lt;&lt;" You have Rs. "&lt;&lt;balanceamt&lt;&lt;endl;
cout&lt;&lt;"nn--&gt;Do you want to play (y/n)? ";
cin&gt;&gt;ch;
}while(ch=='Y'|| ch=='y');
clrscr();
cout&lt;&lt;"nnn";
draw_line(70,'+');
cout&lt;&lt;"nntTHANKS FOR COME TO CASINO YOUR BALANCE AMOUNT IS RS."&lt;&lt;balanceamt&lt;&lt;"nn";
draw_line(70,'+');
cout&lt;&lt;"nnGame developed by ANIKET RAJPUTn";
draw_line(70,'+');
getch();
}
void draw_line(int n,char ch)
{
for(int i=0;i&lt;n;i++)
cout&lt;&lt;ch;
}
void rules()
{
clrscr();
cout&lt;&lt;"nn";
draw_line(60,'-');
cout&lt;&lt;"nttRULES OF THE GAMEn";
draw_line(60,'-');
cout&lt;&lt;"nt1. Choose any number between 1 to 12nt2. If you win you will get 10 times of money you betnt3. If you bet on wrong number you will lose your betting amountnn";
draw_line(60,'-');
cout&lt;&lt;endl;
}
</pre>

Monday, 25 March 2013

Round Robin Scheduling in C Programming

Round Robin Technique is one of the scheduling algorithm for processes in an operating system. This algorithm give the CPU access to a process for a particular time period which time know as Quantum Time. After execution once all the process again repeated and allotted for CPU execution that’s why it’s Round term us in this algorithm. I made following Program which manage all the process and calculate average turn around time and waiting time.

Source Code :

<pre class="brush : cpp">
#include<stdio.h>
#include<conio.h>
int main()
{
int st[10], bt[10], wt[10], tat[10], n, tq;
int i, count=0, swt=0, stat=0, temp, sq=0;
float awt=0.0, atat=0.0;
printf("enter number of processes : ");
scanf("%d", &n);
printf("nenter burst time for processes ");
for(i=0; i<n;i++)
{
printf("nFor process p%d : ",i+1); 
scanf("%d", &bt[i]);
st[i]=bt[i];
}
printf("nenter time quantum : ");
scanf("%d", &tq);
while(1)
{
for(i=0, count=0;i<n;i++)
{
temp=tq;
if(st[i]==0)
{
count++;
continue;
}
if(st[i]>tq)
{
st[i]=st[i]-tq;
}
else
if (st[i]>=0)
{
temp=st[i];
st[i]=0;
}
sq=sq+temp;
tat[i]=sq;
}
if(n==count)
break;
}
for(i=0;i<n;i++)
{
wt[i]=tat[i]-bt[i];
swt=swt+wt[i];
stat=stat+tat[i];
}
awt=(float)swt/n;
atat=(float)stat/n;
printf(" n process_not burst_timet wait_timet turn_around_time");
for(i=0; i<n; i++)
{
printf("n%dtt %dtt %dtt %d", i+1, bt[i], wt[i], tat[i]);
}
printf("naverage wait time is %fnaverage turn_around_time is %fn", awt, atat);
getch();
return 0;}
</pre>


Output :




Wednesday, 20 March 2013

Quick Sort program in C++

Quick Sort is a Divide-and-conquer  Sorting algorithm Because this algorithm first divides a large list into two smaller sub-lists ( low elements and high elements ). Quick Sort can then recursively sort by the sub-lists. Check my Following Link and comment me back if you can do it in other better way.


Source Code :

<pre class="brush: cpp">
#include<iostream.h>
#include<conio.h>
int main()
{
int a[10],size,m;
int qsort(int a[],int p,int r);
cout<<"enter array size : ";
cin>>size;

for(m=0;m<size;m++)
{
cout<<"nenter " <<m<<"th element : "; 
cin>>a[m];                    
}
qsort(a,0,size-1);
cout<<endl<<"sorted array is : ";
for(m=0;m<size;m++)
{

cout<<a[m]<<"t";                    
}
getch();
return 0;
}
int qsort(int a[],int p,int r)

    int partition(int a[],int x,int y);
  int q;
  if(p<r)  
  {
      q=partition(a,p,r);     

    qsort(a,p,q-1);
   qsort(a,q+1,r);
}
}
int partition(int a[],int p,int r)
{
    int i,x,temp,temp1;
    i=p-1;
    x=a[r];
    int j;
    for(j=p;j<=r-1;j++)
    {
    if(a[j]<=x)
    {
    i=i+1;  
    temp=a[i];
    a[i]=a[j];
    a[j]=temp;     
    }                   
    }
    temp1=a[r];
    a[r]=a[i+1];
    a[i+1]=temp1;
    return i+1;
}

</pre>

Output :




Wednesday, 6 March 2013

C Program to Reverse the String


Here I’m sharing a code to print any inputted sting as reverse method. For Example if we input APPS then output should be SSPA.
Strrev() function in C do the same thing. By using this function easily can print a String in reverse but here we perform Reverse opertion without using Strrev(). 

Let See our Code :

<pre class="brush: cpp">
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
   char *str;
   int i,len;
   clrscr();
   printf("Enter Any String for Reverse Print : ");
   scanf("%s",str);
   len=strlen(str)-1;
   for(i=0;i<strlen(str)/2;i++)
   {
     str[i]+=str[len];
     str[len]=str[i]-str[len];
     str[i]=str[i]-str[len--];
   }
   printf("nnReverse String is : %s",str);
   getch();
}
</pre>

Output :