Friday, July 30, 2010

Java Assignment Solution

Here goes the solution for the Programming Paradigm assignment,


Download the Solution(2007 MS office or higher)

Download the Solution ( 2003 MS office or below)

Java Program for Matrix Multiplication

Here goes the Java Program to multiply Two matrices, written by me....Requires Scanner package to run this( available with new versions of Java JDK).

(Pls download the source code in case if it is not clear below)

import java.util.Scanner;
public class matrix_main
{
public static void main(String[] args)
{
Scanner cin=new Scanner(System.in);
int A_row,A_col,B_row,B_col;
System.out.println("Enter the number of rows in matrix A : ");
A_row=cin.nextInt();
System.out.println("Enter the number of columns in matrix A : ");
A_col=cin.nextInt();
System.out.println("Enter the number of rows in matrix B : ");
B_row= cin.nextInt();
System.out.println("Enter the number of columns in matrix B : ");
B_col=cin.nextInt();

if(A_col==B_row)
{
int matrix_A[][] =new int[A_row][A_col];
int matrix_B[][] =new int[B_row][B_col];
int mult_ans[][] =new int[A_row][B_col];
System.out.println("Enter the elements of matrix A : ");
for(int i=0;i for(int j=0;j {
matrix_A[i][j]=cin.nextInt();
}
System.out.println("Enter the elements of matrix B : ");
for(int i=0;i for(int j=0;j {
matrix_B[i][j]=cin.nextInt();
}
for(int i=0;i for(int j=0;j for(int k=0;k mult_ans[i][j] += matrix_A[i][k] * matrix_B[k][j];

System.out.println("\n\n The output is:");
for(int i=0;i {
for(int j=0;j {
System.out.print(mult_ans[i][j]+" ");
}
System.out.println();
}

}
else
{

System.out.print("!!! Can't multiply this matrixes !!! ");
}
}

}



Download The Source Code

Sunday, July 25, 2010

A New Google Group For Us

Hi fellas, i have created a new Google group for our 2008-12 batch...The address of the group is http://groups.google.co.in/group/veccse . The group is a restricted one and only its members can view the contents. I have invited around 25 members whose contact Id I knew, just in case i have missed someone, u can inform me so that I add you in that group.

Some of the features of Google Groups are,

  • Join in on what others are talking about.
  • Start a discussion in your own group.
  • Discuss online or over email.
  • Create web pages right inside your group
  • Build a knowledge base
  • Upload files
  • Learn more about each other

So guys just join it and make it an useful and a successful one. Hope that it is useful for you all....

Wednesday, July 14, 2010

UDP Echo Server Client Program

UDP - User Datagram Protocol

(To know more Click the below link)

http://en.wikipedia.org/wiki/User_Datagram_Protocol

TCP Vs UDP

TCP -
Reliable, Ordered, Heavyweight, Streaming.

UDP - Unreliable, Not Ordered, Lightweight, Datagrams.

Screenshot of the Output




Program


Server.c

#include "stdio.h"
#include "sys/types.h"
#include "sys/socket.h"
#include "netinet/in.h"
#include "string.h"
#include "stdlib.h"
int main()
{
int len,sfd,connfd,i=0,r,b,l,port;
char buff[1024],str[1024],c;
struct sockaddr_in servaddr,cliaddr;
socklen_t clilen;
sfd=socket(AF_INET,SOCK_DGRAM,0);
if(sfd==-1)
{
perror("Socket");
exit(-1);
}
memset(servaddr.sin_zero,'\0',sizeof(servaddr.sin_zero));
printf("\n Enter the port no:");
scanf("%d",&port);
printf("\n Port No is %d",port);
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=INADDR_ANY;
servaddr.sin_port=htons(port);
b=bind(sfd,(struct sockaddr*)&servaddr, sizeof(servaddr));
if(b==-1)
{
perror("bind");
exit(-1);
}
clilen=sizeof(cliaddr);
r=recvfrom(sfd,buff,sizeof(buff),0,(struct sockaddr*)&cliaddr, &clilen);
buff[r]=0;
printf("\n Client:%s",buff);
printf("\n Server:%s",buff);
sendto(sfd,buff,sizeof(buff),0,(struct sockaddr*)&cliaddr,sizeof(cliaddr));
exit(0);
return 0;
}


Client.c

#include "stdio.h"
#include "sys/types.h"
#include "sys/socket.h"
#include "netinet/in.h"
#include "string.h"
#include "stdlib.h"
int main()
{
int len,listenfd,connfd,i=0,r,co,port;
char buff[1024],c;
struct sockaddr_in servaddr,cliaddr;
socklen_t servlen;
listenfd=socket(AF_INET,SOCK_DGRAM,0);
if(listenfd==-1)
{
perror("socket");
exit(-1);
}
memset(servaddr.sin_zero,'\0',sizeof(servaddr.sin_zero));
printf("\n Enter the port no:");
scanf("%d",&port);
printf("\n Port No is : %d",port);
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=INADDR_ANY;
servaddr.sin_port=htons(port);
printf("\n Client:");
scanf("%s",buff);
sendto(listenfd,buff,sizeof(buff),0,(struct sockaddr*)&servaddr,sizeof(servaddr));
r=recvfrom(listenfd,buff,sizeof(buff),0,(struct sockaddr*)&servaddr, &servlen);
buff[r]=0;
printf("\n Server:%s\n",buff);
exit(0);
return 0;
}


Download The Source Code

UDP_Server.c

UDP_Client.c

Monday, July 12, 2010

Madrasapattinam(2010) Movie

Madrasapattinam is a 2010 Indian Tamil film that stars Arya and Amy Jackson in the lead roles, whilst, actors Nasser and Cochin Hanifa play other prominent roles.




What I liked

A period film in Tamil???
Oh!!, that is something new to us who are tired of seeing some filthy fighting scenes, Punch Dialogues and a typical hero-Villain fight sequence in the climax. After seeing this movie what I thought first was that 'our Tamil Cinema is improving a lot' , and is in par to some international movies when it comes to Editing, Camera, and Background Music.

Superb Plot

The film has a very strong foundation with the Story written by Director Vijay.

The movie begins more like Titanic as an old English woman Amy Wilkinson(Amy Jackson) almost at her death bed in London, wants to come down to Chennai in search of a young man Parithi(Arya) whom she last saw on 15 August, 1947.

Almost 60 years from then, she is clueless as she has just a picture of Parithi, which was taken then. The search begins. There are scenes where she recalls her past. It is revealed that Parithi was a valorous dhobi in Madarasapattinam. He revolts against the British officials for they plan to construct a golf course in their dhobikhana.

Comes Amy, daughter of Madras Presidency Governor, and she develops an affinity towards Parithi. She is friendly and helpful. Sequence of events leaves romance blossoming between them. Parithi calls her affectionately as Duraiamma.

Even as they face trouble from the angry White officials, comes 15 August 1947 which brings freedom to India. Duraiamma is now forced to go back to England. Parithi runs from pillar to post and fights to hold his sweetheart’s hands. But he couldn’t achieve his mission. Cut to present, Duraiamma is back in search of Parithi.

Did she realise her mission??? forms the climax


The story is Unique and it is not like regular tamil movies.

We gotta give credits for that.

Good Picturesque of Madraspatnam

The first scene of Madraspatnam in the movie begins with Amy Wilikinson(daughter of Governor general of Madrasapatnam) being received in the Airport, then on the way she sees Mount Road, Spencer Plaza, Chennai Central. It looked as realistic that we could hardly feel the 'Sets' or Graphics in the movie.

So kudos to the Art director on these.

Other pros of this movie include,

  • Racy Action Sequences
  • The Romance between Parithi and Emy.
  • Arya's Acting.
  • Beautiful Emy Jackson...sema machi...lol...
  • Cochin Haneefa's humorous role.
  • All the Artists in the Movie did justice to their Roles, Be it the Indians or Foreigners in the movie (Lead Role Emy Jackson for that matter). The Miss teen world 2008 did perfect justice to her role. The way she adapted to the role was really good.
  • The way they showed how Madras was that time and how Chennai now is.
  • Music by GV Prakash Kumar.
Cons

The only thing i found was that the Tamil Accent used was similar to the one we use now a days. Those days I guess the Accent was a little different.


Overall Rating that I can give - 4.0/5.0

Perfect weekend movie for you. You can have a ride of Madraspatnam, and can see some good romance, song and action sequences.

One of the good movies of the Year after Angaadhi Theru....




Friday, July 9, 2010

TCP Echo Sever program

Purpose - Server must receive messages from client and echo it back to client...

Program Status: Tested, Difficulty level: Easy

Program written by Vivek Venkatesh G

Screen-shot of output:



Program
server.c

#include "stdio.h"
#include "sys/types.h"
#include "netinet/in.h"
#include "string.h"
#include "sys/socket.h"
#include "stdlib.h"
#include "unistd.h"
main()
{
int sd,i,len,bi,nsd,port;
char content[30],buff[30],last_received[30];
struct sockaddr_in ser,cli;
if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1)
{
printf("\n Socket problem");
return 0;
}
printf("\n Socket created\n");
bzero((char*)&cli,sizeof(ser));
printf("ENTER PORT NO:\n");
scanf("%d",&port);
printf("\n Port Address is %d\n:",port);
ser.sin_family=AF_INET;
ser.sin_port=htons(port);
ser.sin_addr.s_addr=htonl(INADDR_ANY);

bi=bind(sd,(struct sockaddr *)&ser,sizeof(ser));
if(bi==-1)
{
printf("\n bind error, port busy, plz change port in client and server");
return 0;
}
i=sizeof(cli);
listen(sd,5);
nsd = accept(sd,((struct sockaddr *)&cli),&i);
if(nsd==-1)
{
printf("\ncheck the description parameter\n");
return 0;
}
printf("\nConnection accepted");
i = recv(nsd,content,30,0);
send(nsd,content,30,0);
while(strcmp(content,"exit")!=0)
{
printf("\nReceived from client and echoeing it....");
i=recv(nsd,content,30,0);
send(nsd,content,30,0);
}
printf("\n Bye");
send(nsd,"EOF",4,0);
close(sd);
close(nsd);
return 0;
}


client.c

#include "stdio.h"
#include "sys/types.h"
#include "netinet/in.h"
#include "string.h"
#include "sys/socket.h"
#include "stdlib.h"
#include "unistd.h"
int main()
{
int sd,con,port,i;
char content[30];
struct sockaddr_in cli;
if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1)
{
printf("\n Socket problem");
return 0;
}
bzero((char*)&cli,sizeof(cli));
cli.sin_family = AF_INET;
printf("ENTER PORT NO");
scanf("%d",&port);
cli.sin_port=htons(port);
cli.sin_addr.s_addr=htonl(INADDR_ANY);
con=connect(sd,(struct sockaddr*)&cli,sizeof(cli));
if(con==-1)
{
printf("\n connection error");
return 0;
}
if(fork())
{
printf("\nEnter the data to be send:");
scanf("%s",content);
while(strcmp(content,"exit")!=0)
{
send(sd,content,30,0);
scanf("%s",content);
}
send(sd,"exit",5,0);
}
else
{
i=recv(sd,content,30,0);
while(strcmp(content,"exit")!=0)
{
printf("Data Echoed from Server: %s\n",content);
i=recv(sd,content,30,0);
}
send(sd,"exit",5,0);
}
close(sd);
return 0;
}


Download Source Code


eserver.c

eclient.c

TCP Time Server Program

Purpose - Server to send time to the client(TCP)

Program Status: Tested, Program Difficulty: Very Easy

Program written by G.Vivek Venkatesh

Screen-shot of output:



Program

server.c

#include "stdio.h"
#include "sys/types.h"
#include "netinet/in.h"
#include "string.h"
#include "sys/socket.h"
#include "stdlib.h"
#include "unistd.h"
#include "time.h"
main()
{
int sd,i,len,bi,nsd,port;
char content[30],buff[30],last_received[30];
struct sockaddr_in ser,cli;
if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1)
{
printf("\n Socket problem");
return 0;
}
printf("\n Socket created\n");
bzero((char*)&cli,sizeof(ser));
printf("ENTER PORT NO:\n");
scanf("%d",&port);
printf("\n Port Address is %d\n:",port);
ser.sin_family=AF_INET;
ser.sin_port=htons(port);
ser.sin_addr.s_addr=htonl(INADDR_ANY);

bi=bind(sd,(struct sockaddr *)&ser,sizeof(ser));
if(bi==-1)
{
printf("\n bind error, port busy, plz change port in client and server");
return 0;
}
i=sizeof(cli);
listen(sd,5);
nsd = accept(sd,((struct sockaddr *)&cli),&i);

if(nsd==-1)
{
printf("\ncheck the description parameter\n");
return 0;
}
printf("\nConnection accepted");

time_t ticks;
ticks=time(NULL);
snprintf(buff,sizeof(buff),"%24s\r\n",ctime(&ticks));

send(nsd,buff,30,0);
printf("\n Bye..");
send(nsd,"EOF",4,0);
close(sd);
close(nsd);
return 0;
}


client.c

#include "stdio.h"
#include "sys/types.h"
#include "netinet/in.h"
#include "string.h"
#include "sys/socket.h"
#include "stdlib.h"
#include "unistd.h"
int main()
{
int sd,con,port,i;
char content[30];
struct sockaddr_in cli;
if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1)
{
printf("\n Socket problem");
return 0;
}
bzero((char*)&cli,sizeof(cli));
cli.sin_family = AF_INET;
printf("ENTER PORT NO");
scanf("%d",&port);
cli.sin_port=htons(port);
cli.sin_addr.s_addr=htonl(INADDR_ANY);
con=connect(sd,(struct sockaddr*)&cli,sizeof(cli));
if(con==-1)
{
printf("\n connection error");
return 0;
}
i=recv(sd,content,30,0);
printf("Received from server %s\n",content);
close(sd);
return 0;
}

Download Source code


tserver.c


tclient.c

TCP Client-Server Chat Program

Program Status : Tested, Program Difficulty: Easy

Screen-shot of output




Program


server.c

#include "stdio.h"
#include "sys/types.h"
#include "netinet/in.h"
#include "string.h"
#include "sys/socket.h"
#include "stdlib.h"
#include "unistd.h"
main()
{
int sd,i,len,bi,nsd,port;
char content[30];
struct sockaddr_in ser,cli;
if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1)
{
printf("\n Socket problem");
return 0;
}
printf("\n Socket created\n");
bzero((char*)&cli,sizeof(ser));
printf("ENTER PORT NO:\n");
scanf("%d",&port);


printf("\n Port Address is %d\n:",port);
ser.sin_family=AF_INET;
ser.sin_port=htons(port);
ser.sin_addr.s_addr=htonl(INADDR_ANY);


bi=bind(sd,(struct sockaddr *)&ser,sizeof(ser));
if(bi==-1)
{
printf("\n bind error, port busy, plz change port in client and server");
return 0;
}
i=sizeof(cli);
listen(sd,5);
nsd = accept(sd,((struct sockaddr *)&cli),&i);
if(nsd==-1)
{
printf("\ncheck the description parameter\n");
return 0;
}
printf("\nConnection accepted");
if(fork())
{
printf("\n Enter the data to be send type exit for stop:\n");
scanf("%s",content);
while(strcmp(content,"exit")!=0)
{
send(nsd,content,30,0);
scanf("%s",content);
}
send(nsd,"exit",5,0);
}
else
i = recv(nsd,content,30,0);
while(strcmp(content,"exit")!=0)
{
printf("\nReceived from client %s\n",content);
i=recv(nsd,content,30,0);
}
while(strcmp(content,"exit")!=0)
{
printf("\n Received from client %s\n",content);
i=recv(nsd,content,30,0);
}
printf("\n Bye");
send(nsd,"EOF",4,0);
close(sd);
close(nsd);
return 0;
}

client.c

#include "stdio.h"
#include "sys/types.h"
#include "netinet/in.h"
#include "string.h"
#include "sys/socket.h"
#include "stdlib.h"
#include "unistd.h"
int main()
{
int sd,con,port,i;
char content[30];
struct sockaddr_in cli;
if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1)
{
printf("\n Socket problem");
return 0;
}
bzero((char*)&cli,sizeof(cli));
cli.sin_family = AF_INET;
printf("ENTER PORT NO");
scanf("%d",&port);
cli.sin_port=htons(port);
cli.sin_addr.s_addr=htonl(INADDR_ANY);
con=connect(sd,(struct sockaddr*)&cli,sizeof(cli));
if(con==-1)
{
printf("\n connection error");
return 0;
}
if(fork())
{
printf("\nEnter the data to be send type exit for stop");
scanf("%s",content);
while(strcmp(content,"exit")!=0)
{
send(sd,content,30,0);
scanf("%s",content);
}
send(sd,"exit",5,0);
}
else
{
i=recv(sd,content,30,0);
while(strcmp(content,"exit")!=0)
{
printf("Received from server %s\n",content);
i=recv(sd,content,30,0);
}
send(sd,"exit",5,0);
}
close(sd);
return 0;
}




Download the Source Code


server.c

client.c

Java Lab - Program 1

Difficulty Level - Very Easy

Rational Number Class in Java

Question:

Develop Rational number class in Java. Use JavaDoc comments for documentation.
Your implementation should use efficient representation for a rational number, i.e. (500 / 1000) should be represented as (½).

My Solution

(any further improvements welcomed).

Two classes "rational_main.java" and "rational.java" has been used to implement this.

rational_main.java

import java.util.Scanner;
class rational_main
{
/** Class that contains the main function
* @author Vivek Venkatesh (Your name)
*/

public static void main(String args[])
{
/** Create an instance of "rational" class
* to call the function in it.
*/

rational x = new rational();

//To get input from user

Scanner s = new Scanner(System.in);
int a,b;
System.out.println("\n Enter the Numerator and Denominator:");
a = s.nextInt();
b = s.nextInt();

x.efficient_rep(a,b);
}
}

rational.java

public class rational
{

/** Rational number class
* To give an efficient representation of user's input rational number
* For ex: 500/1000 to be displayed as 1/2
*/

public void efficient_rep(int a, int b)
{

int x=b;
if(a=2;i--)
{
if(a%i==0 && b%i==0)
{
a=a/i;
b=b/i;
}
}
System.out.println(a + "/" + b);
}
}

(This is only one of the solution, and there is a gr8 possibility of even more efficient solution. If u know pls post it.)


Download Source Code


Click the following links,

rational_main.java

rational.java

Sunday, July 4, 2010

Check out my Blog

Friends just check out the new look of my blog,


http://vivekvenkatesh.blogspot.com/


Do post your Comments and Suggestions.

Wishing you all Success in 3rd year of your college life..


Your Friend
Vivek Venkatesh G

Thursday, July 1, 2010


Heyy..ppl :) :)

We have successfully completed 2 years of our coll ...life... :)

Hope the remaining 2 years will move on successfully.. :)

I welcome you all to 3rd year...wish us all success......... :)