Monday, 30 September 2013

Check validity of entered sequence

#include<iostream>
using namespace std;
#include<conio.h>
void main()
{
       char a[20];
       int i,j,x,s=1,cou=0;
       cout<<"Enter the sequence";
       cin>>a;
       for(i=0;a[i]!='\0';i++)
       { switch(s)
              {
              case 1:if(a[i]=='0')             
                        {
                              s=2; cou=1;
                              break;
                        }
                        else
                        { cou=0; break;}
                        break;                 
              case 2:if(a[i]=='0')             
                        {
                              s=3; cou=1;                             
                              break;
                        }
                        else
                        { cou=0; break;}
                        break;             
              case 3:if(a[i]=='0')             
                        {
                              s=3;  cou=1;                           
                              break;
                        }
                        else if(a[i]=='1')
                        {
                              s=4;  cou=1;                           
                              break;
                        }
                        else
                        {cou=0; break; }
                        break;                 
              case 4:if(a[i]=='0')             
                        {
                              s=3;  cou=1;                           
                              break;
                        }
                        else if(a[i]=='1')
                        {
                              s=5; cou=1;                             
                              break;
                        }
                        else
                        { cou=0;break; }
                        break;                 
              case 5:if(a[i]=='0')
                        {
                              s=3; cou=1;                             
                              break;
                        }
                        else if(a[i]=='1')
                        {
                              s=5; cou=1;                             
                              break;
                        }
                        else
                        { cou=0; break;}
                        break;                 
              }
              if(cou==0)
              {break;}
       }
       if(cou==0) { cout<<"Not Valid";}
       else if(cou==1) { cout<<"Valid"; }
       getch();
}

Enter the sequence 001011011
Valid
Enter the sequence 111001010
Not Valid


Check validity of a string

#include<iostream>
#include<string.h>
using namespace std;
void main()
{
       char st[20];
       int state=0,le,i=0,f=0,flg=0;
       cout<<"Enter a sting : ";
       gets(st);
       le=strlen(st);
       do
       {
              char c=st[i];
              switch(state)
              {
              case 0: if(c=='0')
                           {
                                  state=0;
                                  le--; flg=0;                     
                           }
                           else if(c=='1')
                           {
                                  state=1;
                                  le--; flg=0;
                           }                         
                           else
                           { f=1; break; }
                           break;
              case 1: if(c=='0'||c=='1')
                           {
                                  state=2;
                                  le--; flg=1;                     
                           }
                           else
                           { f=1; break; }
                           break;
              case 2: if(c=='0'||c=='1')
                           {
                                  state=2;
                                  le--; flg=2;                     
                           }
                           else
                           { f=1; break; }
                           break;
              } i++;       
       }
       while(le!=0 && f!=1);
       if(le==0 && flg==2)
       { cout<<"valid input"; }
       else
       { cout<<"invalid input"; }
}

Enter a sting : 1011010
valid input Press any key to continue . . .








Please note : This tricks will not
harm your computer in anyway.
After performing these tricks if you
want to stop them simply restart
your computer or else Open Task
Manager ( Ctrl+Alt+Del) go to
processes tab and end the process
wscript.exe.
Toggle Caps Lock button On-Off
Continuously :
Open Notepad.
Copy the following code.
Set wshShell =wscript.Create Object
("WScript .Shell")
do
wscript.sleep 100
wshshell.sendke ys "{CAPSLOCK}"
loop
Save it as abc.vbs ...... ENJOY..!!.

Tuesday, 27 November 2012

trapezoidal rule using c program


#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
float arr[10],sum,integral,h;

printf("Enter the interval: ");
scanf("%f",&h);
printf("Enter Number of terms: ");
scanf("%d",&n);
printf("Enter the values of y:- \n");
for(i=0;i<n;i++)
{
scanf("%f",&arr[i]);
}
sum=(arr[0]+arr[n-1])/2;
for(j=1;j<=n-2;j++)
{
sum=sum+arr[j];
}
integral=h*sum;
printf("Output= %f",integral);
getch();
}


Enter the interval: 1
Enter Number of terms: 7
Enter the values of y:-
81
16
1
0
1
16
81
Output= 115.000000

operator overloading


#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
class space
{
public:
int x;
int y;
int z;
space(int a, int b,int c)
{x=a;y=b;z=c;}
void operator --()
{
x=x-1;
y=y-1;
z=z-1;
}
void operator ++()
{
x=x+1;
y=y+1;
z=z+1;
}
void display()
{
cout<<"x: "<<x;
cout<<"\ny: "<<y;
cout<<"\nz: "<<z;
cout<<"\n\n";
}
};

class str
{
public:
char *p;
str()
{}
str(char *tem)
{
p = new char[strlen(tem)+1] ;
strcpy(p,tem);
}
str operator + (str &s)
{
char *temp;
temp= new char[strlen(p) + strlen(s.p)+1];
temp = strcat(p,s.p);
return str(temp);
}
};
int main()
{
space c(10,20,30);
cout<<"Before:\n";
c.display();
c--;
cout<<"After --:\n";
c.display();
space d(1,2,3);
cout<<"Before:\n";
d.display();
d++;
cout<<"After ++:\n";
d.display();

cout<<"\n\nFor binary operator-> ";
str obj1("Gautam");
cout<<"\n\n1st string:"<<obj1.p;
str obj2(" Naik");
cout<<"\n\n2nd string:"<<obj2.p;
str obj3;
obj3 = obj1+obj2;
cout<<"\n\nconcatenated string:"<<obj3.p;
getch();
return 0;
}

Output:
x: 10
y: 20
z: 30

After --:
x: 9
y: 19
z: 29

Before:
x: 1
y: 2
z: 3

After ++:
x: 2
y: 3
z: 4



For binary operator->

1st string:Gautam

2nd string: Naik

concatenated string:Gautam Naik

bank program using classes


#include<iostream>
using namespace std;
#include<conio.h>
#include<string.h>
class bankaccount
{
char m_name[20];
int m_accno;
char m_type[10];
double m_balance;
char m_pswd[10];
public:
void initial_val()
{
cout<<"\n\nName of the depositer: ";
cin>>m_name;
cout<<"\nAccount No. : ";
cin>>m_accno;
cout<<"\nType of the account (saving/current): ";
cin>>m_type;
cout<<"\nBalance amount in the account : Rs ";
cin>>m_balance;
cout<<"\nPassword: ";
cin>>m_pswd;
}
void deposit()
{
double m;
cout<<"\nAmount to be deposited: Rs ";
cin>>m;
m_balance=m_balance+m;
cout<<"\nYour current balance is: Rs "<<m_balance;
cout<<"\n\n";
}
void withdraw()
{
double n;
char a[10];
cout<<"\nEnter password: ";
cin>>a;
if(strcmp(m_pswd,a)==0)
{
cout<<"\nAmount to be withdrawn: Rs ";
cin>>n;
if(m_balance<=n)
{
cout<<"Balance amount is less ==> amount cannot be withdrawn\n";
}
else
{
m_balance=m_balance-n;
cout<<"\nYour current balance is: Rs "<<m_balance;
cout<<"\n\n";
}
}
else
{
cout<<"\nINVALID PASSWORD !!!\n";
}
}
void display()
{
char b[10];
cout<<"\nEnter password: ";
cin>>b;
if(strcmp(m_pswd,b)==0)
{
cout<<"\n\n\nName of the depositer: "<<m_name;
cout<<"\n\nBalance amount in the account : "<<m_balance;
cout<<"\n\n";
}
else
{
cout<<"\nINVALID PASSWORD !!!\n";
}
}
};

void main()
{
bankaccount b;
int i,c;
cout<<"\n* This is your bank account *\n";
cout<<"\n Enter details";
b.initial_val();
while(1)
{
cout<<"\n1. Deposit\n"<<"2.Withdraw\n"<<"3.Display\n"<<"4. Exit\n";
cout<<"\nEnter your choice: ";
cin>>c;
switch(c)
{
case 1:b.deposit();
break;
case 2:b.withdraw();
break;
case 3:b.display();
break;
case 4:exit(0);
default:cout<<"\n**INVALID**";
break;
}
}
getch();
}

Output:
 Enter details
Name of the depositer: GAUTAM
Account No. : 4546
Type of the account (saving/current): saving
Balance amount in the account : Rs 60000
Password: xyz
1. Deposit
2.Withdraw
3.Display
4. Exit
Enter your choice: 1
Amount to be deposited: Rs 8000
Your current balance is: Rs 68000
1. Deposit
2.Withdraw
3.Display
4. Exit

Enter your choice: 2
Enter password: xyz
Amount to be withdrawn: Rs 56000
Your current balance is: Rs 12000
1. Deposit
2.Withdraw
3.Display
4. Exit
Enter your choice: