Tuesday, August 29, 2017

3. Write a program to demonstrate Operator overloading.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace program
{
 class OpOver
{
int x, y, z; // 3-D coordinates
public OpOver() { x = y = z = 0; }
public OpOver(int i, int j, int k) { x = i; y = j; z = k; }
// Overload binary + for object + object.
public static OpOver operator +(OpOver op1, OpOver op2)
{
OpOver result = new OpOver();
 /* This adds together the coordinates of the two points  and returns the result. */
result.x = op1.x + op2.x;
result.y = op1.y + op2.y;
result.z = op1.z + op2.z;
return result;
}
// Overload binary + for object + int.
public static OpOver operator +(OpOver op1, int op2)
{
OpOver result = new OpOver();
result.x = op1.x + op2;
result.y = op1.y + op2;
result.z = op1.z + op2;
return result;
}
// Show X, Y, Z coordinates.
public void show()
{
Console.WriteLine(x + ", " + y + ", " + z);
}
}
public class Prog3
{
public static void Main()
{
OpOver a = new OpOver(1, 2, 3);
OpOver b = new OpOver(10, 10, 10);
OpOver c = new OpOver();
Console.Write("Here is a: ");
a.show();
Console.WriteLine();
Console.Write("Here is b: ");
b.show();
Console.WriteLine();
c = a + b; // object + object
Console.Write("Result of a + b: ");
c.show();
Console.WriteLine();
c = b + 10; // object + int
Console.Write("Result of b + 10: ");
c.show();
Console.Read();
}
}
}

2. Write a Program in C# to demonstrate boxing and Unboxing.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace boxing
{
class Program
{
static void Main(string[] args)
{
int m = 10;
object a = m;
try
{
Console.WriteLine("Value of m is :" + a);
object n = 20;
int b = (int)n;
Console.WriteLine("Value of n is :" + b);
System.Console.WriteLine("Boxing and unboxing is done");
Console.ReadLine();
}
catch (System.InvalidCastException e)
{
System.Console.WriteLine("Error Incorrect unboxing" + e.Message);
}
}
}
}
//converting from value type to reference type is known as BOXING
//converting from reference type to value type is known as UNBOXING

1. Write a Program in C# to demonstrate Command line arguments processing.

 namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
 {
  System.Console.WriteLine("\nNumber of command line arguments : " + args.Length);
  System.Console.WriteLine("Command line arguments are : \t");
  for (int i = 0; i < args.Length; i++)
  {
  System.Console.WriteLine(args[i]+"\t");
 }
 System.Console.ReadKey(); //system is built in package
  }      
  }
}
 //writeline -- curson will move on to nextline || write -- execte in  current line
//readline --  || readkey --
// try to do without any argument in string and in Main M must be capital

Sunday, July 9, 2017

4. Build a Rails application to accept book information viz. accession number, title, authors, edition and publisher from a web page and store the information in a database and to search for a book with the title specified by the user and to display the search results with proper headings.

After Installing rails application, you have to start the servers both Apache and MySql when you open exe file of rails application, the servers are automatically started

Open a ruby console window

C :\Rails\rails_apps>

Type the following command
Creating Books Database
> mysql -u root

This will now show you mysql> prompt

At mysql prompt type the following

>create database book_development;

>use book_development;

>create table books(id int not null auto_increment,accno varchar(40) not null,title varchar(60) not null,author varchar(60) not null,edition varchar(60) not null,publisher varchar(5) not null,primary key(id));

Creating book Project

Now open another console window type the following command

>rails -d mysql book
>cd book

Creating controller, model and view from database

>ruby script/generate scaffold Book accno:string title:string author:string
edition:string publisher:string

Starting rails server
>ruby script/server

Executing in the web browser
http://localhost:3000/books

Creating main (new) controller for searching book
>ruby script/generate controller main

a controller with a name main will be created..
Opening main controller program
>edit app\controllers\main_controller.rb

Create two views welcome and result

class MainController < ApplicationController
def welcome
@num_books = Book.count
end
def result
@titlename = params[:title]
@bookz = Book.find(:all, :conditions => "title = #{@titlename}")
end
end

Create Result view file
>notepad app\views\main\result.rhtml
<html>
<title> Welcome template for books </title>
<body>
<p> Entered book title is <%= @titlename %> </p>
<table border=1>
<tr><th>Book Id</th> <th>Accesion Number</th><th>Book
Title</th><th>Author</th> <th>Edition </th> <th>Publisher</th></tr>
<% @names.each do |bk|
@id = bk.id
@accno = bk.accno
@title = bk.title
@author = bk.author
@edition = bk.edition
@publisher = bk.publisher%>
<tr>
<td> <%= @id %></td>
<td><%= @accno %> </td>
<td><%= @title %></td>
<td> <%= @author %></td>
<td><%= @edition %></td>
<td> <%= @publisher %></td>
</tr>
<% end %>
</table>
</form></body></html>

Create Welcome view file

>notepad app\views\main\welcome.rhtml
<html>
<title> Welcome template for books </title>
<body>
<p> Total number of books = <%= @num_books %> </p>
<form action = "result" >
Enter Searching Element: <input type="text" name="title" />
<input type=submit value="Search" />
</form></body></html>

Starting Rails Server
ruby script/server

Executing in the web browser
http://localhost:3000/main/welcome

3.Write a PHP program to read student data from an XML file and store into the MySQL database. Retrieve and display using SEARCH function.

lab3.xml

<?xml version="1.0" ?>
<student>
<stud>
<name>BBBB</name>
<usn>1234</usn>
</stud>
<stud>
<name>CCCC</name>
<usn>4567</usn>
</stud>
</student>

lab3.html

<html>
<body>
<center>
<table width="50%" border="2"><tr>
<form action="http://localhost/lab3.php">
<tr><th> ENTER NAME TO SEARCH </th></tr><br/>
<td align="center"><br/>Name: <input type="text" name="name"><br /><br/>
submit: <input type="submit"><br/><br/></td>
</form></tr>
</body>
</html>

lab3.php

<?php
$link=mysqli_connect("localhost","root","","test");
if(!$link)
{
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
$name=$_GET['name'];
$studs=simplexml_load_file("http://localhost/lab3.xml");
foreach($studs as $stud)
{
$name = $stud->name;
$usn = $stud->usn;
mysqli_query($link,"insert into stud3 values('$name','$usn')");
}
$name=$_GET['name'];
$res=mysqli_query($link,"select * from stud3 where name='$name'");
if(mysqli_num_rows($res)==0)
{
echo "$name doesn't exist in the table";
}
else
{
echo "<table border='1' align=center width=60%>";
echo "<tr><td width=15% align=center>NAME</td><td width=15%
align=center>USN</td></tr>";
while($arr=mysqli_fetch_row($res))
echo "<tr><td>$arr[0]</td><td>$arr[1]</td></tr>";
echo "</table>";
}
?>

2. Create a XHTML form with Name, Address Line 1, Address Line 2, and Email text fields. On submitting, store the values in MySQL table. Retrieve and display the data based on Name.

>create database stud;
>use stud;
>create table info(name varchar(40), add1 varchar(40), add2 varchar(40),
email varchar(50));
>desc info;

lab2.html

<html>
<body>
<center>
<table width="50%" border="2"><tr>
<form action="http://localhost/insert.php">
<tr><th> ENTER AGE INFORMATION </th></tr><br/>
<td align="center"><br/>Name: <input type="text" name="name"><br
/><br/>
add1: <input type="text" name="add1"><br /><br/>
add2: <input type="text" name="add2"><br /><br/>
email: <input type="text" name="email"><br /><br/>
submit: <input type="submit"><br/><br/></td>
</form></tr>
<tr><form action="http://localhost/search.php">
<tr><th> ENTER NAME TO BE SEARCHED AND DISPLAY ITS DETAILS</th></tr><br/>
<td align="center"><br/>Name: <input type="text" name="name"><br
/><br/>
submit: <input type="submit"><br/><br/></td>
</form></tr>
</body>
</html>

insert.php


<?php
$link=mysqli_connect("localhost","root","","stud");
if(!$link)
{
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
$name=$_GET['name'];
$add1=$_GET['add1'];
$add2=$_GET['add2'];
$email=$_GET['email'];
echo "hello " .$name;
echo " INSERTED SUCCESSFULLY<br/><br/>";
$query="insert into info values('$name','$add1','$add2','$email')";
mysqli_query($link,$query) or die(mysql_error());
$res=mysqli_query($link,"select * from info");
echo "<table border='1' align=center width=60%>";
echo "<tr><td width=15% align=center>NAME</td><td width=15%
align=center>ADDRESS1</td><td width=15% align=center>ADDRESS2</td><td
width=15% align=center>EMAIL ID</td></tr>";
while($arr=mysqli_fetch_row($res))
echo
"<tr><td>$arr[0]</td><td>$arr[1]</td><td>$arr[2]</td><td>$arr[3]</td></tr>"
;
echo "</table>";
?>



search.php

<?php
$link=mysqli_connect("localhost","root","","stud");
if(!$link)
{
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
$name=$_GET['name'];
$res=mysqli_query($link,"select * from info where name='$name'");
if(mysqli_num_rows($res)==0)
{
echo "$name doesn't exist";
}
else
{
echo "<table border='1' align=center width=60%>";
echo "<tr><td width=15% align=center>NAME</td><td width=15%
align=center>ADDRESS1</td><td width=15% align=center>ADDRESS2</td><td
width=15% align=center>EMAIL ID</td></tr>";
while($arr=mysqli_fetch_row($res))
echo
"<tr><td>$arr[0]</td><td>$arr[1]</td><td>$arr[2]</td><td>$arr[3]</td><
/tr>";
echo "</table>";
}
?>

1.Write a Perl program to insert name and age information entered by the user into a table created using MySQL and to display the current contents of this table.

Open the terminal window, you will get terminal prompt. Enter into the
super user with the following username and password. You will get root
prompt.
Username: su
Password:root123
 Change into mysql with the following command
>mysql
>create database web;
>show databases;
>use web;
>create table age_info(nam varchar(40), age int(11));
>desc age_info;
 Open another terminal window
>chmod 777 /var/www/cgi-bin
>chmod 777 /var/www/html

lab1.html

<html>
<body>
<center><br/><br/>
<table width="50%" border="2"><tr>
<form action="http://localhost/cgi-bin/p1.pl" method="post">
<tr><th> ENTER AGE INFORMATION </th></tr>
<h3>
<td align="center"><br/>Enter your name :<input type="text"
name="nam"><br><br/>
Enter your age :<input type="text" name="age"><br><br/><br/>
click here to send :<input type="submit" value="Send"><br><br/></td>
</h3>
</form></tr>
</table>
</center>
</body>
</html>

l1.pl

#!/usr/bin/perl
use strict;
use CGI':standard';
use DBI;
print header();
print start_html(-title=>"database",-bgcolor=>"#F0F8FF",-text=>"green");
my $nam=param('nam');
my $age=param('age');
my $db=DBI->connect('DBI:mysql:web','root',"") or die "cannot
connect:".DBI->errstr();
my $query=$db->prepare("insert into age_info values('$nam','$age')");
$query->execute();
my $query=$db->prepare("select * from age_info");
$query->execute();
print "<center>";
print "<table width=20% border=2>";
print "<tr><b>STUDENT AGE INFORMATION</b></tr><br/>";
print "<tr><td align=center width=15%><b>NAME</b></td> <td align=center
width=5%><b>AGE</b></td></tr><BR/>";
while(($nam,$age)=$query->fetchrow())
{
print "<tr><td>$nam</td><td>$age</td></tr>";
}
print "</center>";
$query->finish();
$db->disconnect();
print end_html;
exit(0);