Skip to main content

Posts

Showing posts from June, 2015

Object Oriented Programming - C++

Basic Console program using Visual Studio A program to input Student numbers and Student names and to display them at the end. "student.h" Header file class student { private: int stdNo; char stdName[20]; public: void setStdNo(int pNo); void setStdName(char pName[]); void printDetails(); }; "student.cpp" file (where methods are defined) #include "student.h" #include <cstring> #include <iostream> using namespace std; void student::setStdNo(int pNo) { stdNo=pNo; } void student::setStdName(char pName[]) { strcpy(stdName,pName); } void student::printDetails() { cout<<"Student ID is "<< stdNo<<endl; cout<<"Student Name is "<<stdName<<endl; } The main program #include "stdafx.h" #include "student.h" #include <iostream> using namespace std; int _tmain...

Transferring data from a web form to a database

STEP 1: HTML FORM <body> <h2>Data Form</h2> <form action="info.php" method="post" > //Data entered is redirected to 'info.php' page Name:<input type="text" name="name" size="60" /> <br /> <br /> E-mail:<input type="text" name="email" size="60" /> <br /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </body> STEP 2: PHP <body> <?php  //Connecting to a database $servername="localhost"; $username="root"; $password=""; $dbname="info"; $connect=mysqli_connect("$servername","$username","$password","$dbname"); if (mysqli_connect_error()) { die("Database connection failed: ". mysqli_connect_error()); } else  { echo "Created connection successful...

Creating a new table in the mySQL database

SOURCE CODE: <?php $servername="localhost"; $username="root"; $password=""; $dbname="newDB; //Create a connection($connect) $connect=new mysqli("$servername"," $username "," $password "," $dbname "); //Check the connection new_tbl="CREATE TABLE info( //columns name VARCHAR(30) NOT NULL, email VARCHAR(30)NOT NULL ); $connect->close; ?>

Creating a database using mySQL

SOURCE CODE: <?php $servername="localhost"; $username="root"; $password=""; //Create a connection($connect) //Check the connection $new_db="CREATE DATABASE newDB"; if($connect->query($new_db)==TRUE){    echo "Database created successfully"; } else{    echo "Error: ".$conn->error; } $conn->close(); ?>

Opening a mySQL database connection

SOURCE CODE: <?php $servername="localhost"; $username="root"; $password=""; //Create a connection     $connect=mysqli_connect("$servername","$username","$password"); //Check the connection if (mysqli_connect_error()){    die("Database connection failed:ERROR: ".mysqli_connect_error(); } else{   echo "Database connected successfully!"; ?>

A C++ program to input an integer 'n' and get the 'n'th prime number

#include <iostream> using namespace std; int main() {         int n;         cout<<"Input integer for n: ";         cin>>n;         int prime=0;         int count,count1=0;                 for(int x=1;;x++){                         count1=0;                         for(int y=1;y<=x;y++)                         {                                 if(x%y==0)                                 {                           ...