Monday, January 26, 2015

Scientific Calculator in C++

Read Also:  



Scientific Calculator in C++ Programming SeekerzZ




#include<iostream.h>
#include<math.h>
#include<conio.h>
int main ()
{
clrscr();
float a,b,PI;
int c;
cout<<endl;
cout<<"******************************* Calculator *************************************\n";
cout<<"================================================================================\n";
cout<<"Operations\t"<<"\tTrigonometric Functions"<<"\t\tLogarithmic Functions\n";
cout<<"================================================================================\n";
cout<<"1: Division\t\t"<<"7: Sin\t\t"<<"\t\t13: Log"<<endl;
cout<<endl;
cout<<"2: Multiplication\t"<<"8: Cos\t\t"<<"\t\t14: Log with base 10"<<endl;
cout<<endl;
cout<<"3: Subtraction\t\t"<<"9: Tan\t\t"<<endl;
cout<<endl;
cout<<"4: Addition\t\t"<<"10: Inverse of Sin"<<endl;
cout<<endl;
cout<<"5: Exponent\t\t"<<"11: Inverse of Cos"<<endl;
cout<<endl;
cout<<"6: Square root\t\t"<<"12: Inverse of Tan"<<endl;
cout<<endl;
cout<<"Enter the function that you want to perform : ";
cin>>c;
cout<<endl;
PI=3.14159265;
switch(c)
{
case 1:
cout<<"Enter 1st number : ";
cin>>a;
cout<<endl;
cout<<"Enter 2nd number : ";
cin>>b;
cout<<endl;
cout<<"Division = "<<a/b<<endl;
break;
case 2:
cout<<"Enter 1st number : ";
cin>>a;
cout<<endl;
cout<<"Enter 2nd number : ";
cin>>b;
cout<<endl;
cout<<"Multiplication = "<<a*b<<endl;
break;
case 3:
cout<<"Enter 1st number : ";
cin>>a;
cout<<endl;
cout<<"Enter 2nd number : ";
cin>>b;
cout<<endl;
cout<<"Subtraction = "<<a-b<<endl;
break;
case 4:
cout<<"Enter 1st number : ";
cin>>a;
cout<<endl;
cout<<"Enter 2nd number : ";
cin>>b;
cout<<endl;
cout<<"Addition = "<<a+b<<endl;
break;
case 5:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Enter the exponent : ";
cin>>b;
cout<<endl;
cout<<"Exponent = "<<pow(a,b)<<endl;
break;
case 6:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Square Root = "<<sqrt(a)<<endl;
break;
case 7:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Sin = "<<sin(a)<<endl;
break;
case 8:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Cos = "<<cos(a)<<endl;
break;
case 9:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Tan = "<<tan(a)<<endl;
break;
case 10:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Inverse of Sin = "<<asin(a)*180.0/PI<<endl;
break;

case 11:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Inverse of Cos = "<<acos(a)*180.0/PI<<endl;
break;
case 12:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Inverse of tan = "<<atan(a)*180.0/PI<<endl;
break;
case 13:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Log = "<<log(a)<<endl;
break;
case 14:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Log with base 10 = "<<log10(a)<<endl;
break;
default:
cout<<"Wrong Input"<<endl;
}
 getch();
 return 0;

}

Thursday, January 22, 2015

Program to evaluate an expression entered in post-fix form in C++

#include <iostream.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <conio.h>
const int MAX = 50 ;
class postfix
{
int stack[MAX] ;
int top, nn ;
char *s ;
public :
postfix( ) ;
void setexpr ( char *str ) ;
void push ( int item ) ;
int pop( ) ;
void calculate( ) ;
void show( ) ;
} ;
postfix :: postfix( )
{
top = -1 ;
}
void postfix :: setexpr ( char *str )
{
s = str ;
}
void postfix :: push ( int item )
{
if ( top == MAX - 1 )
cout << endl << "Stack is full" ;
else
{
top++ ;
stack[top] = item ;
}
}
int postfix :: pop( )
{
if ( top == -1 )
{
cout << endl << "Stack is empty" ;
return NULL ;
}
int data = stack[top] ;
top-- ;
return data ;
}
void postfix :: calculate( )
{
int n1, n2, n3 ;
while ( *s )
{
if ( *s == ' ' || *s == '\t' )
{
s++ ;
continue ;
}
if ( isdigit ( *s ) )
{
nn = *s - '0' ;
push ( nn ) ;
}
else
{
n1 = pop( ) ;
n2 = pop( ) ;
switch ( *s )
{
case '+' :
n3 = n2 + n1 ;
break ;
case '-' :
n3 = n2 - n1 ;
break ;
case '/' :
n3 = n2 / n1 ;
break ;
case '*' :
n3 = n2 * n1 ;
break ;
case '%' :
n3 = n2 % n1 ;
break ;
case '$' :
n3 = pow ( n2 , n1 ) ;
break ;
default :
cout << "Unknown operator" ;
exit ( 1 ) ;
}

push ( n3 ) ;
}
s++ ;
}
}
void postfix :: show( )
{
nn = pop ( ) ;
cout << "Result is: " << nn ;
}

void main( )
{
clrscr();
char expr[MAX] ;
cout << "\nEnter postfix expression to be evaluated : " ;
cin.getline ( expr, MAX ) ;
postfix q ;
q.setexpr ( expr ) ;
q.calculate( ) ;
q.show( ) ;
getch();
}


HUNT Code in C++ :: Create Hunt using C++

 #include<stdio.h>
#include<conio.h>


int main()
{
int i,j,k,l,m=10,n=4;
int o,x,y,z=1,w=0;
int ln=0;
for(i=0;i<10;i++)
{
for(j=0;j<m;j++)

printf(" ");
}
for(k=0;k<12;k++)
{
printf("*");
printf(" ");


for(o=0;o<z;o++)
{
printf(" ");
}
z=z+2;
for(l=0;l<2;l++)
{
printf("*");
printf(" ");
}
n=n++;
m=m--;
printf("\n"); 
}

for(i=0;i<10;i++)

for(k=0;k<2;k++)
{
printf(" ");
}
printf("*");
if(ln<3)
{
for(l=0,x=0;l<17;l++,x++)
printf(" ");
}
else
for(l=0,x=0;l<12;l++,x++)
{
if(x==6)
while(x!=9)
{
printf(" ");
printf("*");
x++;
}
else
printf(" "); 
}
ln=ln++;
printf(" ");
printf("*");
if(w<3)
{ for(x=0;x<8;x++)
printf(" ");
for(x=0;x<3;x++)
{
printf("*");
printf(" ");
}
}
else
if(w<6)
{
for(x=0;x<7;x++)
printf(" ");
for(x=0;x<3;x++)
{
printf(" ");
printf("*");
}
printf(" ");
}
else
{
for(x=0;x<14;x++)
printf(" ");
// printf("*");
}
w=w++;

for(y=0;y<6;y++)
printf(" ");
printf("*");

printf("\n");
}
for(x=0;x<24;x++)
{
printf(" ");
printf("*");
}
printf("\n created by usman siddique");
getch();
return 0;

}


Monday, January 12, 2015

Basic Syntax of PHP

PHP stands for PHP: Hypertext Preprocessor.


A PHP script can be placed anywhere in the document.

A PHP script starts with <?php and ends with ?>:

<?php
// PHP code goes here
?>

The default file extension for PHP files is ".php".

A PHP file normally contains HTML tags, and some PHP scripting code.


Sunday, January 4, 2015

Sound Function in C or C++

In Both C and C++:
--------------------------------------
#include<dos.h>
#include<iostream.h>
 void main()
{
   int a;
   for ( a = 200 ; a <= 1000 ; a = a + 20 )
   {
      sound(a);
      delay(25);
   }
   nosound();
}

------------------------------------------
You can also do like that in C++ :

#include<iostream.h>
#include<conio.h>
void main()
{
cout<<"\a --------- \a -------- \a";
getch();
}

--------------------------------------
You can also do like that in C Language :

#include<stdio.h>
#include<conio.h>
void main()
{
printf("\a --------- \a -------- \a");
getch();
}










First Hello World Android Program

Please follow below give steps for create First Hello World Android Program in eclipse :-
Step 1:Install  new version of android supported Eclipse
Step 2:After install the eclipse go in File Section
First Hello World Android Program-1
Step 3:File->new->Android Application Project

 First Hello World Android Program-1

Step 4:After click on Android Application project
Step 5:Type Application Name,First letter Must be in uppercase
First Hello World Android Program-3
Step 6:Click on Next->Next->Next->Next
step 7:choose the Activity Name
First Hello World Android Program-7
Step 8:Click on Finish button

Your Android project is ready to work.Your project have following sections and these section have following file and what is use of these files and folders
1.src folder:-this folder contain package of your project
this package have classes where you want to coding and implement functional activity in your project.
2.gen folder:-it have supported package that used to run your project
3.Android 4.4.2(Android version 19):-contain android .jar file
4.Android Dependencies:-have the other outer supported .jar files
5.Referenced Libraries:-it have reference libraries like Android-support-v4 .jar file
6.bin folder:in bin folder .class and .apk file are create after “run” the project
7.lib folder:-it have current running libraries,you also add external .jar file in bin folder
8.res folder:-in drawable folder you add the images that is used in your project.
9.layout folder:-create .xml file in layout folder.it is a very important part in project,by this you design your project.
values folder:-you add your style,color .xml file
10.Android Manifest.xml file:-it is very important file in android project.it having following information
a)android version information
b)package name
c)SDK version information
d)when .xml file open first when project is run.
Source Code :-
Helloworld.java
package com.example.helloworld;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

Saturday, January 3, 2015

Get the current local time with ctime [C++]

#include <iostream>
#include <ctime>

int main()
{
  time_t currentTime;
  struct tm *localTime;

  time( &currentTime );                   // Get the current time
  localTime = localtime( &currentTime );  // Convert the current time to the local time

  int Day    = localTime->tm_mday;
  int Month  = localTime->tm_mon + 1;
  int Year   = localTime->tm_year + 1900;
  int Hour   = localTime->tm_hour;
  int Min    = localTime->tm_min;
  int Sec    = localTime->tm_sec;

  cout << "This program was exectued at: " << Hour << ":" << Min << ":" << Sec<<endl ;
  cout << "And the current date is: " << Day << "/" << Month << "/" << Year <<endl;
  return 0;
}