TE_SEM1_PL_01(Programming Laboratory I)
DBMS Practicals
Assignments Group A (Mandatory)
1 DBMS using connections(Client-Data sever, two tier) Oracle/MySQL (ODBC/JDBC), SQL
prompt to create data base tables insert, update data values, delete table, use table, select
queries with/without where clause. ,demonstrate use of stored procedure / function (create
procedure at the data side and make use of it on the client side)
2 DBMS using connections(Client-application server-Data sever, three tier) Oracle/MySQL
(ODBC/JDBC), SQL Joints, prompt.
3 Design and Develop SQL DDL statements which demonstrate the use of SQL objects
such as Table, View , Index using Client-Data sever(two tier)
4 Write a program in Python/C++ to read display the i-node information for a given text file,
image file.
5 Write an IPC program using pipe. Process A accepts a character string and Process B
inverses the string. Pipe is used to establish communication between A and B processes
using Python or C++.
6 Use Python for Socket Programming to connect two or more PCs to share a text file.
Assignments Group B (Any Six Assignments, All assignments to be covered in a Batch)
1 Design at least 10 SQL queries for suitable database application using SQL DML statements:
Insert, Select, Update, Delete Clauses using distinct, count, aggregation on Client-Data
sever(three tier)
2 Implement database with suitable example using MongoDB and implement all basic
operations and administration commands using two tier architecture.
3 Use MongoDB to process semi structured and unstructured data collections such as Rfid,
images, blogs use python/Java MongoDB interface.
4 Write an python/Java application using MongoDB to maintain the blog for composing the
blog consists of text columns, images and videos also calculate the hit or users visited by
drawing 2D graphs.
5 Write a program in Python/C++ to test that computer is booted with Legacy Boot ROM-
BIOS or UEFI.
6 Write a program in C++ to create a RAMDRIVE and associate an acyclic directory structure
to it. Use this RAMDRIVE to store input, out files to run a calculator program.
7 Write a program in C++ to develop a tool using GRUB2 or GRUBx64.rfi select and display
a boot partition. (use appropriate overloading)
8 Write a Python/Java/C+ program to verify the operating system name and version of Mobile
devices.
9 Write a program using MongoDB to compose a web news-letter consisting of videos,
images, text use python MongoDB interface.
10 Create a iso boot image using open source tools.
11 Write a python program for creating virtual file system on Linux environment.
12 Write a program in C++ to make USB Device Bootable by installing required system files
13 Write a program in python for USB Device File Management. Check usefulness of
command e2fsck for different file systems mounted on computer.
14 Aggregation and indexing with suitable example using Cassendra and RdfID based
employees attendance system.
15 Aggregation and indexing with suitable example using MongoDB.
16 Map reduce operation with suitable example using MongoDB.
17 Indexing and querying with MongoDB using suitable example.
18 Connectivity with MongoDB using any Java application.
19 Using MongoDB create a database of employee performance, employee attendance on the
workstation. Perform statistical analysis for the results of the products produced by
employees rated as passed ok, damaged products ( 5 samples per batch size 1000) and the
portion covered in the training and absentee of the employees during training. Use
programming language R. (or R-Python/R-Java) or equivalent assignment using R
Programming Language for BiGDATA computing.
Assignment Group C: Advance Technology Assignments (Any One, all three to be
covered in a Batch)
1 BIG DATA applications using Hadoop
2 BIG DATA applications using Blogs
3 Big Data Predictive Machine Learning
4 Create and test functioning of Windows-8 ReFS (Resilient File System)
GroupA
//============================================================================
// Author: Aman Bohra
// ( bohraaman.blogspot.in)
// ROLL NO : 007
// CLASS : TE(COMPUTER)
// BATCH : S1
// ASSIGNMENT NO.: 01
/* TITLE : 1 DBMS using connections(Client-Data sever, two tier) Oracle/MySQL (ODBC/JDBC), SQL
prompt to create data base tables insert, update data values, delete table, use table, select
queries with/without where clause. ,demonstrate use of stored procedure / function (create
procedure at the data side and make use of it on the client side)
//============================================================================*/
//Server-side
aman@Aman-pc:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 48
Server version: 5.5.37-0ubuntu0.12.10.1 (Ubuntu)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
mysql> create database TE;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| TE |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)
mysql> use TE;
Database changed
mysql> create table Student (Rollno int,Name varchar(20),Branch varchar(20),Percent float,primary key(Rollno));
Query OK, 0 rows affected (0.10 sec)
mysql> desc Student;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| Rollno | int(11) | NO | PRI | 0 | |
| Name | varchar(20) | YES | | NULL | |
| Branch | varchar(20) | YES | | NULL | |
| Percent | float | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> show tables;
+--------------+
| Tables_in_TE |
+--------------+
| Student |
+--------------+
1 row in set (0.00 sec)
mysql> select * from Student;
Empty set (0.00 sec)
mysql> select * from Student;
+--------+------+----------+---------+
| Rollno | Name | Branch | Percent |
+--------+------+----------+---------+
| 7 | Aman | Computer | 61 |
+--------+------+----------+---------+
1 row in set (0.00 sec)
mysql> select * from Student;
+--------+-------+----------+---------+
| Rollno | Name | Branch | Percent |
+--------+-------+----------+---------+
| 0 | &Name | &Branch | 0 |
| 7 | Aman | Computer | 75 |
+--------+-------+----------+---------+
2 rows in set (0.00 sec)
mysql> select * from Student;
+--------+-------+----------+---------+
| Rollno | Name | Branch | Percent |
+--------+-------+----------+---------+
| 0 | &Name | IT | 0 |
| 7 | Aman | Computer | 75 |
+--------+-------+----------+---------+
2 rows in set (0.00 sec)
mysql> select * from Student;
+--------+-------+----------+---------+
| Rollno | Name | Branch | Percent |
+--------+-------+----------+---------+
| 0 | &Name | IT | 0 |
| 7 | Aman | Computer | 75 |
+--------+-------+----------+---------+
2 rows in set (0.00 sec)
mysql> select * from Student;
+--------+------+----------+---------+
| Rollno | Name | Branch | Percent |
+--------+------+----------+---------+
| 7 | Aman | Computer | 75 |
+--------+------+----------+---------+
1 row in set (0.01 sec)
mysql> DROP DATABASE TE;
Query OK, 1 row affected (0.04 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
//Client-side
aman@Aman-pc:~$ mysql -u root -h 20.0.0.1 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 49
Server version: 5.5.37-0ubuntu0.12.10.1 (Ubuntu)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| TE |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)
mysql> use TE;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> insert into Student (Rollno,Name,Branch,Percent) values (07,'Aman','Computer',61);
Query OK, 1 row affected (0.05 sec)
mysql> insert into Student values (Rollno,'&Name','&Branch','&Percent')
-> ;
Query OK, 1 row affected, 1 warning (0.04 sec)
mysql> update Student set Percent=75 where Rollno=7
-> ;
Query OK, 1 row affected (0.06 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update Student set Branch='IT' where Rollno=0;
Query OK, 1 row affected (0.18 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> delete from Student where Rollno=3;
Query OK, 0 rows affected (0.00 sec)
mysql> delete from Student where Rollno=0;
Query OK, 1 row affected (0.04 sec)
//============================================================================
// Author: Aman Bohra
// ( bohraaman.blogspot.in)
// ROLL NO : 007
// CLASS : TE(COMPUTER)
// BATCH : S1
// ASSIGNMENT NO.: 02
/* TITLE : 2 DBMS using connections(Client-application server-Data sever, three tier) Oracle/MySQL
(ODBC/JDBC), SQL Joints, prompt.
//============================================================================*/
import java.lang.*;
import java.sql.*;
import java.io.*;
public class Javasql1
{
public static void main(String[] args)
{
int ch;
String q;
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String url = "jdbc:mysql://localhost/";
String driver = "com.mysql.jdbc.Driver";
String dbname = "blog";
String username = "root";
String password="root";
try{
Connection conn = DriverManager.getConnection(url+dbname,username,password);
Statement st = conn.createStatement();
ResultSet res;
do
{
System.out.println("\n---------MENU---------");
System.out.println("\n1.Create Tables");
System.out.println("\n2.Insert Records");
System.out.println("\n3.Joins");
System.out.println("\n4.Exit");
System.out.println("\n\nEnter your choice:");
ch=Integer.parseInt(input.readLine());
switch(ch)
{
case 1:
System.out.println("\nCreating two table:blog and rates");
q="CREATE TABLE blog(Blog_id int,Name VARCHAR(500),blog_type varchar(100),blog_link varchar(1000));";
st.executeUpdate(q);
q="CREATE TABLE rates(Blog_id int,Name varchar(500),Total_pageviews int,Total_advertisement int);";
st.executeUpdate(q);
System.out.println("\n'blog' and 'rates'table Successfully created\n");
break;
case 2:
q = "INSERT INTO blog VALUES(101,'CSE','Computer','bohraaman.blogspot.in');";
st.executeUpdate(q);
q = "INSERT INTO blog VALUES(102,'Entc','ENTC','entc.blogspot.in');";
st.executeUpdate(q);
q = "INSERT INTO blog VALUES(103,'itech','ITech','it.blogspot.in');";
st.executeUpdate(q);
q = "INSERT INTO rates VALUES(101,'Computer Engineering',48,50);";
st.executeUpdate(q);
q = "INSERT INTO rates VALUES(102,'Entc',35,39);";
st.executeUpdate(q);
q = "INSERT INTO rates VALUES(103,'itech',43,45);";
st.executeUpdate(q);
q = "INSERT INTO rates VALUES(104,'Mechanical',40,41);";
st.executeUpdate(q);
System.out.println("\nInserted records into the tables 'blog' and 'rates' successfully...\n");
break;
case 3:
do{
System.out.println("\n\n-------Joins-------\n");
System.out.println("\n1.INNER JOIN");
System.out.println("\n2.LEFT OUTER JOIN");
System.out.println("\n3.RIGHT OUTER JOIN");
System.out.println("\n4.FULL OUTER JOIN");
System.out.println("\n5.Exit");
System.out.println("\n\nEnter your choice:");
ch=Integer.parseInt(input.readLine());
switch(ch)
{
case 1: q="SELECT blog.Blog_id,blog.Name, blog.blog_type, blog.blog_link FROM blog INNER JOIN rates ON blog.Blog_id=rates.Blog_id;";
res=st.executeQuery(q);
System.out.println("\n\t----------------------------------------------------------------------");
System.out.println("\n\t\t\t\tRECORDS");
System.out.println("\n\t-------------------------------------------------------------------\n");
while (res.next())
{
int blogid = res.getInt("Blog_id");
String Name = res.getString("Name");
String blog_type = res.getString("blog_type");
String blog_link = res.getString("blog_link");
System.out.println("\n\tBlog_id:"+blogid+"\t\t Name:"+Name+"\tblog_type:"+blog_type+"\n");
}
System.out.println("\n\t---------------------------------------------------------------\n");
break;
case 2:
q="SELECT blog.Blog_id,blog.Name, blog.blog_link,rates.Total_pageviews FROM blog LEFT OUTER JOIN rates ON blog.Blog_id=rates.Blog_id;";
res=st.executeQuery(q);
System.out.println("\n\t-------------------------------------------------------------------");
System.out.println("\n\t\t\t\tRECORDS");
System.out.println("\n\t-------------------------------------------------------------------\n");
while (res.next())
{
int blogid = res.getInt("Blog_id");
String Name = res.getString("Name");
String blog_link = res.getString("blog_link");
int Prates = res.getInt("Total_pageviews");
System.out.println("\n\t\tBlog_id:"+blogid+"\t \tName:"+Name+"\tblog_link:"+blog_link+"\t\tTotal_pageviews:"+Prates+"\n");
}
System.out.println("\n\t-------------------------------------------------------------------\n");
break;
case 3:
q="SELECT blog.blog_type, blog.blog_link,rates.Blog_id,rates.Total_advertisement FROM blog RIGHT OUTER JOIN rates ON blog.Name=rates.Name;";
res=st.executeQuery(q);
System.out.println("\n\t-------------------------------------------------------------------");
System.out.println("\n\t\t\t\tRECORDS");
System.out.println("\n\t-------------------------------------------------------------------\n");
while (res.next())
{
String blog_type = res.getString("blog_type");
String blog_link = res.getString("blog_link");
int blogid = res.getInt("Blog_id");
int Arates = res.getInt("Total_advertisement");
System.out.println("\n\t\tblog_type:"+
blog_type +"\tBlog_id:"+blogid+
"\t\tAdvertisement_rates:"+Arates+
"\t\tblog_link:"+blog_link+"\n");
}
System.out.println("\n\t-------------------------------------------------------------------\n");
break;
case 4:
q="SELECT * FROM blog LEFT OUTER JOIN rates ON blog.Blog_id=rates.Blog_id UNION SELECT * FROM blog RIGHT OUTER JOIN rates ON blog.Blog_id=rates.Blog_id;";
res=st.executeQuery(q);
System.out.println("\n\t-------------------------------------------------------------------");
System.out.println("\n\t\t\t\tRECORDS"); System.out.println("\n\t-------------------------------------------------------------------\n");
while (res.next())
{
int blogid = res.getInt("Blog_id");
String Name = res.getString("Name");
int Prates = res.getInt("Total_pageviews");
int Arates = res.getInt("Total_advertisement");
System.out.println("\n\tBlog_id:"+blogid+ "\tName:"+Name+"\t\t\tPv_rates:"
+Prates+"\t\t\tAdv_rates:"+Arates+"\n");
}
System.out.println("\n\t-------------------------------------------------------------------\n");
break;
case 5: break;
}
}while(ch!=5);
break;
case 4: System.exit(0);
}
}while(ch!=4);
}
catch(SQLException se)
{
System.out.print("\nCreated error is:\n"+se+"\n");
}
catch (Exception e)
{
System.out.print("\nCreated error is:\n"+e+"\n");
}
}
}
/******************OUTPUT****************
---------MENU---------
1.Create Tables
2.Insert Records
3.Joins
4.Exit
Enter your choice:
1
Creating two table:blog and rates
'blog' and 'rates'table Successfully created
---------MENU---------
1.Create Tables
2.Insert Records
3.Joins
4.Exit
Enter your choice:
2
Inserted records into the tables 'blog' and 'rates' successfully...
---------MENU---------
1.Create Tables
2.Insert Records
3.Joins
4.Exit
Enter your choice:
3
-------Joins-------
1.INNER JOIN
2.LEFT OUTER JOIN
3.RIGHT OUTER JOIN
4.FULL OUTER JOIN
5.Exit
Enter your choice:
1
----------------------------------------------------------------------
RECORDS
-------------------------------------------------------------------
Blog_id:101 Name:CSE blog_type:Computer
Blog_id:102 Name:Entc blog_type:ENTC
Blog_id:103 Name:itech blog_type:ITech
---------------------------------------------------------------
-------Joins-------
1.INNER JOIN
2.LEFT OUTER JOIN
3.RIGHT OUTER JOIN
4.FULL OUTER JOIN
5.Exit
Enter your choice:
2
-------------------------------------------------------------------
RECORDS
-------------------------------------------------------------------
Blog_id:101 Name:CSE blog_link:bohraaman.blogspot.in Total_pageviews:48
Blog_id:102 Name:Entc blog_link:entc.blogspot.in Total_pageviews:35
Blog_id:103 Name:itech blog_link:it.blogspot.in Total_pageviews:43
-------------------------------------------------------------------
-------Joins-------
1.INNER JOIN
2.LEFT OUTER JOIN
3.RIGHT OUTER JOIN
4.FULL OUTER JOIN
5.Exit
Enter your choice:
3
-------------------------------------------------------------------
RECORDS
-------------------------------------------------------------------
blog_type:null Blog_id:101 Advertisement_rates:50 blog_link:null
blog_type:ENTC Blog_id:102 Advertisement_rates:39 blog_link:entc.blogspot.in
blog_type:ITech Blog_id:103 Advertisement_rates:45 blog_link:it.blogspot.in
blog_type:null Blog_id:104 Advertisement_rates:41 blog_link:null
-------------------------------------------------------------------
-------Joins-------
1.INNER JOIN
2.LEFT OUTER JOIN
3.RIGHT OUTER JOIN
4.FULL OUTER JOIN
5.Exit
Enter your choice:
4
-------------------------------------------------------------------
RECORDS
-------------------------------------------------------------------
Blog_id:101 Name:CSE Pv_rates:48 Adv_rates:50
Blog_id:102 Name:Entc Pv_rates:35 Adv_rates:39
Blog_id:103 Name:itech Pv_rates:43 Adv_rates:45
Blog_id:0 Name:null Pv_rates:40 Adv_rates:41
-------------------------------------------------------------------
-------Joins-------
1.INNER JOIN
2.LEFT OUTER JOIN
3.RIGHT OUTER JOIN
4.FULL OUTER JOIN
5.Exit
Enter your choice:
5
---------MENU---------
1.Create Tables
2.Insert Records
3.Joins
4.Exit
Enter your choice:
4
*/
//============================================================================
// Author: Aman Bohra
// ( bohraaman.blogspot.in)
// ROLL NO : 007
// CLASS : TE(COMPUTER)
// BATCH : S1
// ASSIGNMENT NO.: 04
/* TITLE :4 Write a program in Python/C++ to read display the i-node information for a given text file,
image file.
//============================================================================*/
//C++ Program
#include"iostream"
#include"stdio.h"
#include"stdlib.h"
#include"sys/types.h"
#include"sys/stat.h"
#include"time.h"
using namespace std;
int main()
{
int m;
struct stat var;
char fname[50];
cout<<"\nEnter file name: ";
cin>>fname;
stat(fname, &var);
cout<<"\nFile name you entered is: "<<fname<<endl;
cout<<"\n*****************************************************\n";
cout<<" INODE STRUCTURE FOR GIVEN FILE\n";
cout<<"*******************************************************\n";
cout<<"\n1. Size of file is: "<<var.st_size;
cout<<"\n2. inode no. is: "<<var.st_ino;
cout<<"\n3. Device id of file is: "<<var.st_dev;
cout<<"\n4. Time of last access: "<<ctime(&var.st_atime);
cout<<"\n5. Time of last modification: "<<ctime(&var.st_mtime);
cout<<"\n6. Time of last status change: "<<ctime(&var.st_ctime);
cout<<"\n7. No. of links to file: : "<<var.st_nlink;
cout<<"\n8. User ID of owner of file: "<<var.st_uid;
cout<<"\n9. No. of IO blocks allocated to file: "<<var.st_blksize;
m=var.st_mode;
cout<<"\n10. type of file: ";
if(S_ISREG(m))
cout<<"regular file\n";
else if(S_ISDIR(m))
cout<<"directory\n";
cout<<"\n11. Access permissions of file: ";
if(S_ISDIR(m))
cout<<"d";
else
cout<<"-";
if(S_IRUSR & m)
cout<<"r";
else
cout<<"-";
if(S_IWUSR & m)
cout<<"w";
else
cout<<"-";
if(S_IXUSR & m||S_IXGRP & m||S_IXOTH & m)
cout<<"x";
else
cout<<"-";
if(S_IRGRP & m)
cout<<"r";
else
cout<<"-";
if(S_IWGRP & m)
cout<<"w";
else
cout<<"-";
if(S_IROTH & m)
cout<<"r";
else
cout<<"-";
if(S_IWOTH & m)
cout<<"w";
else
cout<<"-";
return 0;
}
/***************************** OUTPUT*****************************************
aman@Aman-pc:~$ cd Desktop
aman@Aman-pc:~/Desktop$ g++ pl1_a04.cpp
aman@Aman-pc:~/Desktop$ ./a.out
Enter file name: pl1_a04.cpp
File name you entered is: pl1_a04.cpp
*****************************************************
INODE STRUCTURE FOR GIVEN FILE
*******************************************************
1. Size of file is: 1976
2. inode no. is: 6887
3. Device id of file is: 2053
4. Time of last access: Tue Aug 25 04:10:40 2015
5. Time of last modification: Tue Aug 25 04:10:39 2015
6. Time of last status change: Tue Aug 25 04:10:39 2015
7. No. of links to file: : 1
8. User ID of owner of file: 1000
9. No. of IO blocks allocated to file: 4096
10. type of file: regular file
11. Access permissions of file: -rw-rwr-
aman@Aman-pc:~/Desktop$ ./a.out
Enter file name: cllg life.jpg
File name you entered is: cllg
*****************************************************
INODE STRUCTURE FOR GIVEN FILE
*******************************************************
1. Size of file is: 134516337
2. inode no. is: 3075133989
3. Device id of file is: 13207599299392700416
4. Time of last access: Sun Apr 7 05:33:36 1974
5. Time of last modification: Wed Jun 3 22:46:08 1931
6. Time of last status change: Sat Dec 21 06:42:00 1935
7. No. of links to file: : 134525328
8. User ID of owner of file: 134525016
9. No. of IO blocks allocated to file: 134514672
10. type of file: regular file
11. Access permissions of file: -rwxrw--
aman@Aman-pc:~/Desktop$ ^C
*/
// C program
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char *argv[])
{
struct stat sb;
if (argc != 2) {
fprintf(stderr, "Usage: %s <pathname>\n", argv[0]);
exit(EXIT_FAILURE);
}
if (stat(argv[1], &sb) == -1) {
perror("stat");
exit(EXIT_FAILURE);
}
printf("File type: ");
switch (sb.st_mode & S_IFMT) {
case S_IFBLK: printf("block device\n"); break;
case S_IFCHR: printf("character device\n"); break;
case S_IFDIR: printf("directory\n"); break;
case S_IFIFO: printf("FIFO/pipe\n"); break;
case S_IFLNK: printf("symlink\n"); break;
case S_IFREG: printf("regular file\n"); break;
case S_IFSOCK: printf("socket\n"); break;
default: printf("unknown?\n"); break;
}
printf("I-node number: %ld\n", (long) sb.st_ino);
printf("Mode: %lo (octal)\n",
(unsigned long) sb.st_mode);
printf("Link count: %ld\n", (long) sb.st_nlink);
printf("Ownership: UID=%ld GID=%ld\n",
(long) sb.st_uid, (long) sb.st_gid);
printf("Preferred I/O block size: %ld bytes\n",
(long) sb.st_blksize);
printf("File size: %lld bytes\n",
(long long) sb.st_size);
printf("Blocks allocated: %lld\n",
(long long) sb.st_blocks);
printf("Last status change: %s", ctime(&sb.st_ctime));
printf("Last file access: %s", ctime(&sb.st_atime));
printf("Last file modification: %s", ctime(&sb.st_mtime));
exit(EXIT_SUCCESS);
}
/*********************OUTPUT******************************
guest-bDtrYn@ccpvg-HP-dx2480-MT-VP562PA:~$ cd Desktop
guest-bDtrYn@ccpvg-HP-dx2480-MT-VP562PA:~/Desktop$ gcc pl1_a04.c
guest-bDtrYn@ccpvg-HP-dx2480-MT-VP562PA:~/Desktop$ ./a.out
Usage: ./a.out <pathname>
guest-bDtrYn@ccpvg-HP-dx2480-MT-VP562PA:~/Desktop$ ./a.out om.txt
File type: regular file
I-node number: 18755
Mode: 100664 (octal)
Link count: 1
Ownership: UID=155 GID=163
Preferred I/O block size: 4096 bytes
File size: 7 bytes
Blocks allocated: 8
Last status change: Mon Jun 22 00:17:02 2015
Last file access: Mon Jun 22 00:17:03 2015
Last file modification: Mon Jun 22 00:17:02 2015
*/
//============================================================================
// Author: Aman Bohra
// ( bohraaman.blogspot.in)
// ROLL NO : 007
// CLASS : TE(COMPUTER)
// BATCH : S1
// ASSIGNMENT NO.: 05
/* TITLE : 5 Write an IPC program using pipe. Process A accepts a character string and Process B
inverses the string. Pipe is used to establish communication between A and B processes
using Python or C++.
//============================================================================*/
//Named pipe
#include<stdio.h>
#include<unistd.h>
#include<sys/stat.h>
#include<sys/wait.h>
#include<fcntl.h>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{
int len,status,mypipe;
char str[29];
mknod("test.txt",S_IFIFO | S_IRUSR | S_IWUSR,0);
pid_t pid=fork();
if (pid==0)
{
mypipe=open("test.txt",O_WRONLY);
cout<<"\n Enter the string: ";
cin>>str;
len=strlen(str);
write(mypipe,str,len);
close(mypipe);
}
else
{
mypipe=open("test.txt",O_RDONLY);
char buffer[21];
int pid_child;
pid_child=wait(&status);
int length=read(mypipe,buffer,20);
buffer[length]='\0';
cout<<"\n Enter string is: "<<buffer;
int i=0;
for(length=length-1;length>=0;length--)
str[i++]=buffer[length];
str[i]='\0';
printf("\n Reversed string is: %s ",str);
close(mypipe);
}}
/*---------------------------------------------
OUTPUT:-
aman@Aman-pc:~$ cd Desktop
aman@Aman-pc:~/Desktop$ g++ pl1_a05named.cpp
aman@Aman-pc:~/Desktop$ ./a.out
Enter the string: Aman
Enter string is: Aman
Reversed string is: namA
aman@Aman-pc:~/Desktop$
*/
//Unnamed pipe
#include<iostream>
using namespace std;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
int main(void)
{
int fd[2], nbytes,len;
pid_t childpid;
char string[80] ;
char readbuffer[80];
char revbuffer[80];
cout<<"/n Enter the string: ";
cin>>string;
len=strlen(string);
pipe(fd);
if((childpid = fork()) == -1)
{
perror("fork");
exit(1);
}
if(childpid == 0)
{
/* Child process closes up input side of pipe */
close(fd[0]);
/* Send "string" through the output side of pipe */
write(fd[1], string, (strlen(string)+1));
exit(0);
}
else
{
/* Parent process closes up output side of pipe */
close(fd[1]);
/* Read in a string from the pipe */
nbytes = read(fd[0], readbuffer, sizeof(readbuffer));
int i=0;
for(i=len-1;i>=0; )
{
for(int j=0;j<len;i--,j++)
{
revbuffer[j]=readbuffer[i];
}
}
printf("Received string: %s", readbuffer);
printf("\n Reversed string: %s", revbuffer);
}
return(0);
}
/*---------------------------------------------
OUTPUT:-
aman@Aman-pc:~$ cd Desktop
aman@Aman-pc:~/Desktop$ g++ pl1_a05unnamed.cpp
aman@Aman-pc:~/Desktop$ ./a.out
Enter the string: Aman
Received string: Aman
Reversed string is: nama
*/
//============================================================================
// Author: Aman Bohra
// ( bohraaman.blogspot.in)
// ROLL NO : 007
// CLASS : TE(COMPUTER)
// BATCH : S1
// ASSIGNMENT NO.: 06
/* TITLE : 6 Use Python for Socket Programming to connect two or more PCs to share a text file
//============================================================================*/
#Server side
#!/user/bin/python
import socket
import os
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host=socket.gethostname()
port= 12345
s.bind(('127.0.0.1',port))
s.listen(10)
while True:
c,addr=s.accept()
print 'Got connection from',addr
name=c.recv(100)
print name,'File req by client'
file=open(name,"r")
while True:
contents=file.read(65536)
if not contents:
break
c.sendall(contents)
c.send('Thank you for connecting')
c.close()
/*output
aman@Aman-pc:~$ cd Desktop
aman@Aman-pc:~/Desktop$ python pl1_06.py
Got connection from ('20.0.0.80', 45202)
pl1_06.py File req by client
*/
#Client side
#!/user/bin/pythonimport socket
import socket
import os
s=socket.socket()
host=socket.gethostname()
port= 12345
s.connect(('127.0.0.1',port))
print 'Entre the file name'
name=raw_input()
s.send(name)
print s.recv(65536)
s.close()
/*output
aman@Aman-pc:~$ cd Desktop
aman@Aman-pc:~/Desktop$ python pl1_06cli.py
Entre the file name
pl1_06.py
#!/user/bin/python
import socket
import os
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host=socket.gethostname()
port= 12345
s.bind(('20.0.0.80',port))
s.listen(10)
while True:
c,addr=s.accept()
print 'Got connection from',addr
name=c.recv(100)
print name,'File req by client'
file=open(name,"r")
while True:
contents=file.read(65536)
if not contents:
break
c.sendall(contents)
c.send('Thank you for connecting')
c.close()
Thank you for connecting
aman@Aman-pc:~/Desktop$
*/
Group B
//============================================================================
// Author: Aman Bohra
// ( bohraaman.blogspot.in)
// ROLL NO : 007
// CLASS : TE(COMPUTER)
// BATCH : S1
// ASSIGNMENT NO.: 06
/* TITLE : 6 Write a program in C++ to create a RAMDRIVE and associate an acyclic directory structure
to it. Use this RAMDRIVE to store input, out files to run a calculator program.
//============================================================================*/
//pl1_b06.cpp
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
system("sudo mkdir -p /media/rdcal123");
system("sudo mount -t tmpfs -o size=512M tmpfs /media/rdcal123");
system("sudo cp /home/administrator/Desktop/pl1_cal.cpp /media/rdcal123/");
system("sudo g++ pl1_cal.cpp");
system("./a.out");
return 0;
}
//pl1_cal.cpp
#include<iostream>
using namespace std;
int main()
{
float no1,no2,res;
int ch;
cout<<"\n-----------------------------------------------------------";
cout<<"\n\n\t\t ***** CALCULATOR *****";
cout<<"\n-----------------------------------------------------------";
cout<<"\n\n\t Enter first number : ";
cin>>no1;
cout<<"\n\n\t Enter second number : ";
cin>>no2;
do
{
cout<<"\n\n\t\t ***** MENU *****";
cout<<"\n\n\t 1]. Addition";
cout<<"\n\t 2]. Subtraction";
cout<<"\n\t 3]. Multilication";
cout<<"\n\t 4]. Division";
cout<<"\n\t 5]. Exit";
cout<<"\n\n\t\t Enter your choice : ";
cin>>ch;
switch(ch)
{
case 1: res=no1+no2;
cout<<"\n\t Addition of two numbers is : "<<res;
break;
case 2: res=no1-no2;
cout<<"\n\t Subtraction of two numbers is : "<<res;
break;
case 3: res=no1*no2;
cout<<"\n\t Multiplication of two numbers is : "<<res;
break;
case 4: res=no1/no2;
cout<<"\n\t Division of two numbers is : "<<res;
break;
case 5:return 1;
break;
}
}while(ch!=5);
return 0;
}
/* Output
aman@Aman-pc:~$ cd Desktop
aman@Aman-pc:~/Desktop$ g++ pl1_cal.cpp
aman@Aman-pc:~/Desktop$ g++ pl1_b06.cpp
aman@Aman-pc:~/Desktop$ ./a.out
[sudo] password for aman:
-----------------------------------------------------------
***** CALCULATOR *****
-----------------------------------------------------------
Enter first number : 20
Enter second number : 5
***** MENU *****
1]. Addition
2]. Subtraction
3]. Multilication
4]. Division
5]. Exit
Enter your choice : 1
Addition of two numbers is : 25
***** MENU *****
1]. Addition
2]. Subtraction
3]. Multilication
4]. Division
5]. Exit
Enter your choice : 2
Subtraction of two numbers is : 15
***** MENU *****
1]. Addition
2]. Subtraction
3]. Multilication
4]. Division
5]. Exit
Enter your choice : 3
Multiplication of two numbers is : 100
***** MENU *****
1]. Addition
2]. Subtraction
3]. Multilication
4]. Division
5]. Exit
Enter your choice : 4
Division of two numbers is : 4
***** MENU *****
1]. Addition
2]. Subtraction
3]. Multilication
4]. Division
5]. Exit
Enter your choice : 5
aman@Aman-pc:~/Desktop$ ./a.out
-----------------------------------------------------------
***** CALCULATOR *****
-----------------------------------------------------------
Enter first number : 20.5
Enter second number : 5.555
***** MENU *****
1]. Addition
2]. Subtraction
3]. Multilication
4]. Division
5]. Exit
Enter your choice : 1
Addition of two numbers is : 26.055
***** MENU *****
1]. Addition
2]. Subtraction
3]. Multilication
4]. Division
5]. Exit
Enter your choice : 2
Subtraction of two numbers is : 14.945
***** MENU *****
1]. Addition
2]. Subtraction
3]. Multilication
4]. Division
5]. Exit
Enter your choice : 3
Multiplication of two numbers is : 113.877
***** MENU *****
1]. Addition
2]. Subtraction
3]. Multilication
4]. Division
5]. Exit
Enter your choice : 4
Division of two numbers is : 3.69037
***** MENU *****
1]. Addition
2]. Subtraction
3]. Multilication
4]. Division
5]. Exit
Enter your choice : 5
aman@Aman-pc:~/Desktop$
*/
//============================================================================
// Author: Aman Bohra
// ( bohraaman.blogspot.in)
// ROLL NO : 007
// CLASS : TE(COMPUTER)
// BATCH : S1
// ASSIGNMENT NO.: 11
/* TITLE : 11 Write a python program for creating virtual file system on Linux environment.
//============================================================================*/
import shelve
import sys
fs = shelve.open('filesystem.fs', writeback=True)
current_dir = []
def install(fs):
# create root and others
username = raw_input('What do you want your username to be? ')
fs[""] = {"System": {}, "Users": {username: {}}}
def current_dictionary():
"""Return a dictionary representing the files in the current directory"""
d = fs[""]
for key in current_dir:
d = d[key]
return d
def ls(args):
print 'Contents of directory', "/" + "/".join(current_dir) + ':'
for i in current_dictionary():
print i
def cd(args):
if len(args) != 1:
print "Usage: cd "
return
if args[0] == "..":
if len(current_dir) == 0:
print "Cannot go above root"
else:
current_dir.pop()
elif args[0] not in current_dictionary():
print "Directory " + args[0] + " not found"
else:
current_dir.append(args[0])
def mkdir(args):
if len(args) != 1:
print "Usage: mkdir "
return
#To create an empty directory there and sync back to shelve dictionary!
d = current_dictionary()[args[0]] = {}
fs.sync()
def pwd(args):
d=current_dir
print d[-1]
def quit(args):
sys.exit(0)
COMMANDS = {'ls' : ls, 'cd': cd, 'mkdir': mkdir,'pwd':pwd,'quit':quit}
install(fs)
while True:
raw = raw_input('> ')
cmd = raw.split()[0]
if cmd in COMMANDS:
COMMANDS[cmd](raw.split()[1:])
#Use break instead of exit, so you will get to this point.
raw_input('Press the Enter key to shutdown...')
#................................OUTPUT......................................
aman@Aman-pc:~$ cd Desktop
aman@Aman-pc:~/Desktop$ python pl1_b11.py
What do you want your username to be? Aman
> ls
> ^X^Z
[1]+ Stopped python pl1_b11.py
aman@Aman-pc:~/Desktop$ python pl1_b11.py
What do you want your username to be? Aman
> ls
Contents of directory /:
System
Users
> cd System
> ls
Contents of directory /System:
> mkdir CSE007
> ls
Contents of directory /System:
CSE007
> pwd
System
> cd ..
> ls
Contents of directory /:
System
Users
> cd ..
Cannot go above root
> cd Users
> mkdir CSE07
> ls
Contents of directory /Users:
CSE07
Aman
> pwd
Users
> ls
Contents of directory /Users:
CSE07
Aman
> cd ..
> ls
Contents of directory /:
System
Users
> cd ..
Cannot go above root
> ls
Contents of directory /:
System
Users
> quit
*/
I will try to post all this enlisted program....
ReplyDeleteu just stay in touch with our blog.........
and if any-one know better then me and want some changes in the program........... for them i am ready to edit my program and make it better.........
.................................Thank you.............................................