Saturday, August 16, 2014

Data Types in PHP

uPHP supports eight primitive types.

uFour scalar types:

uboolean
uinteger
ufloating-point number (float)
ustring

uTwo compound types:

uarray
uobject

uAnd finally two special types:

uresource

uNULL

Comments in PHP


// C++ and Java-style comment


# Shell-style comments


/* C-style comments
     These can span multiple lines */

Web application lifecycle


PHP Features

uOpen source / Free software.
uCross Platform to develop, to deploy, and to use.
uPower,Robust, Scalable.
uWeb development specific.
uCan be Object Oriented.
uIt is faster to code and faster to execute.
uLarge, active developer community.
u20 million websites
uSupport for PHP is free.

uGreat documentation in many language www.php.net/docs.php

Brief History of PHP

u     PHP (PHP: Hypertext Preprocessor) was created by Rasmus Lerdorf in 1994. It was initially developed for HTTP usage logging and server-side form generation in Unix
u     PHP 2 (1995) transformed the language into a Server-side embedded scripting language. Added database support, file uploads, variables, arrays, recursive functions, conditionals, iteration, regular expressions, etc.
u     PHP 3 (1998) added support for ODBC data sources, multiple platform support, email protocols (SNMP,IMAP), and new parser written by Zeev Suraski and Andi Gutmans .
u     PHP 4 (2000) became an independent component of the web server for added efficiency. The parser was renamed the Zend Engine. Many security features were added.
u    PHP 5 (2004) adds Zend Engine II with object oriented programming, robust XML support using the libxml2 library, SOAP extension for interoperability with Web Services, SQLite has been bundled with PHP 

PHP Architecture

  uZend engine as parser (Andi Gutmans and  
      Zeev Suraski)
 uSAPI is a web server abstraction layer
 uPHP components now self contained 
      (ODBC, Java, LDAP, etc.)

 uThis structure is a good general design  
      for software (compare to OSI model,          and middleware applications).

What is PHP?

u"PHP Hypertext Preprocessor"
uScripting Server-Side language
uCreation of dynamic content – i.e. HTML and JSON
uInteraction with databases (CRUDs)
uServer side, or via command line (CLI)
uCan be embedded in HTML
uFirst introduced in 1995 as module for Apache
uOpen source, written in C
uSimilar to Perl and C
uPHP is "type-less" language.
uPHP originally stood for "PERSONAL HOME PAGE"
  uPHP runs on different platforms (Windows, Linux,                 Unix, etc.)‏    
  uPHP is compatible with almost all servers used today             (Apache, IIS, etc.)
  uPHP is easy to learn and runs efficiently on the server      side.
  uThe PHP code is enclosed in special start and end            processing instructions <?php and ?>  that allow you      to jump into and out of "PHP mode."

Friday, May 17, 2013

show current computer time program in C++



#include <iostream>
#include <ctime>
using namespace std;

int main( )
{
   // current date/time based on current system
   time_t now = time(0);
 
   // convert now to string form
   char* dt = ctime(&now);
   cout << "The local date and time is: " << dt;
   // convert now to tm struct for UTC
   tm *gmtm = gmtime(&now);
   dt = asctime(gmtm);
   cout << "\nThe UTC date and time is:"<< dt << endl;
}

Friday, May 03, 2013

binary search in C++


//binary search
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
   
    int n;
    cout<<"enter the array length: ";
    cin>>n;
   int bc[n];
      for(int i=0;i<=n;i++)
    {
            cout<<"the value of bc["<<i<<"] is: ";
    cin>>bc[i];
}
int m;
int c,f,mid;
c=1;
f=n+1;
mid=(c+f)/2;
    cout<<"enter a element you want to search :";
    cin>>m;
    while(c<=f && bc[mid]!=m)
 {   if (m<bc[mid])
   f=mid-1;
    else {
    c=mid+1;  }
    mid = (c+f)/2;
}
if(f>=c){

 cout<<"the element is located in mid";
}
else
{

    cout<<"the element is not located in mid";
}
    getch();
return 0;
}

TELL STAR OF USER in C++


#include<iostream>
using namespace std;
 int main()
 {
 int date,month;

 cout<<"\nEnter Date: ";
 cin>>date;
 cout<<"\nEnter Month: ";
 cin>>month;
 cout<<"\n\n";

if(month<=1 && date>=20)
 cout<<"Aquarius";
 else
if(month<=2 && date<=18)
 cout<<"Aquarius";
 else
 if(month<=2 && date>=19)
 cout<<"Pices";
 else
 if(month<=3 && date<=20)
 cout<<"Pices";
 else
 if(month<=3 && date>=21)
 cout<<"Aries";
 else
 if(month<=4 && date<=19)
 cout<<"Aries";
 else
 if(month<=4 && date>=20)
 cout<<"Taurus";
 else
 if(month<=5 && date<=20)
 cout<<"Taurus";
 else
 if(month<=5 && date>=21)
 cout<<"Gemini";
 else
 if(month<=6 && date<=20)
 cout<<"Gemini";
 else
 if(month<=6 && date>=21)
 cout<<"Cancer";
 else
 if(month<=7 && date<=22)
 cout<<"Cancer";
 else
 if(month<=7 && date>=23)
cout<<"Leo";
 else
 if(month<=8 && date<=22)
 cout<<"Leo";
 else
 if(month<=8 && date>=23)
 cout<<"Virgo";
 else
 if(month<=9 && date<=22)
 cout<<"Virgo";
 else
 if(month<=9 && date>=23)
 cout<<"Libra";
 else
 if(month<=10 && date<=22)
 cout<<"Libra";
 else
 if(month<=10 && date>=23)
 cout<<"Scorpio";
 else
 if(month<=11 && date<=21)
 cout<<"Scorpio";
 else
 if(month<=11 && date>=22)
 cout<<"Sagittarius";
 else
 if(month<=12 && date<=21)
 cout<<"Sagittarius";
 else
 if(month<=12 && date>=22)
 cout<<"Capricon";
 else
 if(month<=1 && date<=19)
 cout<<"Capricon";
 else
 cout<<"Invalid Month:";

 }

bubble sort in C++


#include<iostream>
using namespace std;
int main()
{
   
    int n,p;
    cout<<"enter the array length: ";
    cin>>n;
    int bc[n];
      for(int i=0;i<=n;i++)
    {
            cout<<"the value of bc["<<i<<"] is: ";
    cin>>bc[i];
}
for(int k=1;k<=n-1;k++)
{
       
        for(int p=1;p<=n-k;p++)
        {if(bc[p]>bc[p+1])
        bc[p]=bc[p+1];
}
}
for(int i=0;i<=n;i++)
    {
            cout<<"the value of bc["<<i<<"] is:"<<bc[i]<<endl;
            }
}

program to get ip address in C++


#include<stdlib.h>
main()
{
   system("C:\\Windows\\System32\\ipconfig");
   system("pause");
   return 0;
}

searching in linked list in C++


#include <iostream>
using namespace std;
struct node{
int data;
node *link;
};
int main(){
node *start,*temp,*prev;
int lim,item;
cout<<"enter the linked list limited :";
cin>>lim;
cout<<"ente item to find :";
cin>>item;
start=new node;
prev=start;
cout<<"enter char for location 1 :";
cin>>start->data;
start->link=NULL;
for(int i=2;i<=lim;i++){
temp=new node;
cout<<"enter char for location"<<i<<" : ";
cin>>temp->data;
temp->link=NULL;
prev->link=temp;
prev=temp;                    
}
node* ptr;
ptr=start;
while(ptr!=NULL)
{  if (item=ptr->data) {
cout<<"Item is found location of the item is "<<ptr->link;
return 0;
}
ptr=ptr->link;
}
}

General Linked list integer program in C++


#include <iostream>
using namespace std;
struct node{
int data;
node *link;
};
int main(){
node *start,*temp,*prev;
int lim;
cout<<"enter the linked list limited :";
cin>>lim;
start=new node;
prev=start;
cout<<"enter char for location 1 :";
cin>>start->data;
start->link=NULL;
for(int i=2;i<=lim;i++){
temp=new node;
cout<<"enter char for location"<<i<<" : ";
cin>>temp->data;
temp->link=NULL;
prev->link=temp;
prev=temp;                    
}
node* ptr;
ptr=start;
while(ptr!=NULL)
{  cout<<ptr->data<<endl;
      ptr=ptr->link;
}
}

General Linked list character program in C++


#include <iostream>
using namespace std;
struct node{
char data;
node *link;
};
int main(){
node *start,*temp,*prev;
int lim;
cout<<"enter the linked list limited :";
cin>>lim;
start=new node;
prev=start;
cout<<"enter char for location 1 :";
cin>>start->data;
start->link=NULL;
for(int i=2;i<=lim;i++){
temp=new node;
cout<<"enter char for location "<<i<<" : ";
cin>>temp->data;
temp->link=NULL;
prev->link=temp;
prev=temp;                    
}
node* ptr;
ptr=start;
while(ptr!=NULL)
{  cout<<ptr->data<<endl;
      ptr=ptr->link;
}
}


Friday, April 26, 2013

number in pyramid before space in C++


#include <iostream>
using namespace std;
int main(){

int a;
int b;
cout<<"enter the number pyramid limit:";
cin>>b;
int nPyramid = 1;

int k=b;
for(a=1;a<=k;a++)
{


for(int i=0;i<b;i++)
{                   //for the spaces
cout<<nPyramid<<"\t";

nPyramid++;         //Increase the pyramid value by 1
}

nPyramid--; //Remove this line and see the effect
cout<<endl; //Next line
for(int i=1;i<=a;i++)
{ cout<<"\t";
}
b--;
}
}
output:-

number in pyramid space after in C++


#include <iostream>
using namespace std;
int main(){
int a;
int b;
cout<<"enter the number pyramid limit:";
cin>>b;
int nPyramid = 1;
int k=b;
for(a=1;a<=k;a++)
{
for(int i=0;i<b;i++)
{                   //for the spaces
cout<<"\t"<<nPyramid;

nPyramid++;         //Increase the pyramid value by 1
}

nPyramid--;                 //Remove this line and see the effect
cout<<endl;               //Next line
b--;
}
}

Wednesday, March 20, 2013

displayind odd numbers upto 100 in C++

#include <iostream.h>
#include <conio.h>
int main()
{
int i;
for(int i=1;i <= 100 ;i++)
{

 if(i%2==1)
cout<<i<<endl;
}
getch();
return 0;

}

Saturday, December 08, 2012

Calender


#include <iostream>
#include <stdlib.h>
#include <iomanip>
using namespace std;
typedef int Bool;

// converts 0 to 'S', 1 to 'M', 2 for 'T',3 for 'W',4 for 'T',5 for 'F' ,6 for 'S'
char whatDay (int);

// not very good check for leap years
Bool isLeapYear (int);

// takes the number of the month, a flag saying whether year is leap
int numOfDaysInMonth (int,Bool);

void printHeader (int);

// takes the number of the month, and the first day, prints, and updates
// the first day of the next month
void printMonth (int, int&);

// prints the specified amount of spaces
void skip (int);

// prints leading spaces in monthly calendar
void skipToDay (int);

// terminates program in case of unrecoverable errors
void disaster ();

int main () {

  int year, firstDayInCurrentMonth;
  Bool leap;
  int currentMonth = 1; // start at Jan
  int numDays;

  cout << "What year do you want a calendar for? ";
  cin >> year;
  cout << "What day of the week does January 1 fall on?" << endl;
  cout << "Enter 0 for Sunday, 1 for Monday,2 for Tuesday,3 for Wednesday,4 for Thursday,5 for Friday ,6 for Saturday ";
  cin >> firstDayInCurrentMonth;

  leap = isLeapYear(year);
  skip(9); cout << year << endl;

  while (currentMonth <= 12) {
    numDays = numOfDaysInMonth(currentMonth,leap);
    printHeader(currentMonth);
    printMonth(numDays, firstDayInCurrentMonth);
    cout << endl << endl << endl;
    currentMonth = currentMonth + 1;
  }
  cout << endl;
}

void disaster () {
  cout << "Disaster! Exiting ..." << endl;
  exit (-1);
}

void skip (int i) {
  while (i > 0) {
    cout << " ";
    i = i - 1;
  }
}

char whatDay (int d) {
  if (d == 0) return('S');
  else if (d == 1) return('M');
  else if (d == 2) return('T');
  else if (d == 3) return('W');
  else if (d == 4) return('T');
  else if (d == 5) return('F');
  else if (d == 6) return('S');
  else disaster();
}

Bool isLeapYear (int y) {
  return ((y % 4) == 0); // simplified
}

void printHeader (int m) {

  if (m == 1) { skip(7); cout << "January" << endl; }
  else if (m == 2) { skip(7); cout << "February" << endl; }
  else if (m == 3) { skip(7); cout << "March" << endl; }
  else if (m == 4) { skip(7); cout << "April" << endl; }
  else if (m == 5) { skip(7); cout << "May" << endl; }
  else if (m == 6) { skip(7); cout << "June" << endl; }
  else if (m == 7) { skip(7); cout << "July" << endl; }
  else if (m == 8) { skip(7); cout << "August" << endl; }
  else if (m == 9) { skip(7); cout << "September" << endl; }
  else if (m == 10) { skip(7); cout << "October" << endl; }
  else if (m == 11) { skip(7); cout << "November" << endl; }
  else if (m == 12) { skip(7); cout << "December" << endl; }
  else disaster();

  cout << " S  M  T  W  T  F  S" << endl;
  cout << "____________________" << endl;
}

int numOfDaysInMonth (int m, Bool leap) {
  if (m == 1) return(31);
  else if (m == 2) if (leap) return(29); else return(28);
  else if (m == 3) return(31);
  else if (m == 4) return(30);
  else if (m == 5) return(31);
  else if (m == 6) return(30);
  else if (m == 7) return(31);
  else if (m == 8) return(31);
  else if (m == 9) return(30);
  else if (m == 10) return(31);
  else if (m == 11) return(30);
  else if (m == 12) return(31);
  else disaster();
}

void skipToDay (int d) {
  skip(3*d);
}

void printMonth (int numDays, int& weekDay) {
  int day = 1;

  skipToDay(weekDay);
  while (day <= numDays) {
    cout << setw(2) << day << " ";
    if (weekDay == 6) {
      cout << endl;
      weekDay = 0;
    }
    else weekDay = weekDay + 1;
    day = day + 1;
  }
}

Tuesday, December 04, 2012

GPA calculate in C++


// it is use in kust i calculate my gpa that is correct
#include <iostream>
using namespace std;

int main(){
    float nmbr, grade, credits, GPA = 0, totalCredits = 0;

    cout << "Enter The Number of Courses: ";
    cin >> nmbr;

    for(int i = 0; i < nmbr; i++){
        cout << "Enter the credit number for course No. " << i+1 << " : ";
        cin >> credits;
        totalCredits =totalCredits + credits;

        cout << "Enter the grade for course No. " << i+1 << " : ";
        cin >> grade;
         GPA =GPA+grade*credits;
    }

    GPA /= totalCredits;

    cout << "The GPA Is: " << GPA << " / ";
    if(GPA >=.7 && GPA <= 1)
        cout << "F oh no";
    else if(GPA >= 1 && GPA <= 1.33)
        cout << "D";
    else if(GPA >= 1.33 && GPA <= 1.7)
        cout << "D+";
    else if(GPA >=1.7 && GPA <= 2)
        cout << "C-";
    else if(GPA >= 2 && GPA <= 2.33)
        cout << "C";
    else if(GPA >= 2.33 && GPA <= 2.63)
        cout << "C+";
    else if(GPA >= 2.63  && GPA <= 3)
        cout << "B-";
    else if(GPA >= 3 && GPA <= 3.33)
        cout << "B";
    else if(GPA >=3.33 && GPA <= 3.63)
        cout << "B+";
    else if(GPA >=3.63 && GPA <= 4)
        cout << "A-";
    else if(GPA == 4)
        cout << "A oh....................\n";
 

    return 0;
}