Wednesday, October 29, 2014

Write a program in C++ /Python to analyze email header.

Problem Statement:
Write a program in C++ /Python to analyze email header.


PROGRAM

Mainwindow.h
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QCoreApplication>

QImage img(600,600,QImage::Format_ARGB32);

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    img.fill(Qt::white);

    for(int l=150;l<450;l++)        //vertical line
    {
        img.setPixel(30,l,qRgb(0,0,0));
    }
    for(int n=5;n<650;n++)          //horizontal line
    {
        img.setPixel(n,300,qRgb(0,0,0));
    }
    ui->label->setPixmap(QPixmap::fromImage(img));

    connect(ui->sampling,SIGNAL(clicked()),this,SLOT(sampling()));
    connect(ui->Quantization,SIGNAL(clicked()),this,SLOT(quantization()));
    connect(ui->Encoding,SIGNAL(clicked()),this,SLOT(encoding()));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::input()
{
    Fm=ui->lineEdit_freq->text().toInt();
    A=ui->lineEdit_amp->text().toInt();
    Fs=ui->lineEdit_sfreq->text().toInt();
    r=Fs/Fm;
    if (Fs<=Fm)
    {
        QMessageBox::warning(this,"Error","Sampling frequency should be at least twice of Frequency");
    }
}

void MainWindow::analog()
{

}

void MainWindow::sampling()
{
    input();
    r=(2*Fs)/Fm;

    for(int i=0;i<480;i++)
    {
        int x=A*sin(2*PI*Fm*i);
        Y[i]=300-x;
        X[i]=30+i;
        img.setPixel(X[i],Y[i],qRgb(255,0,0));
        ui->label->setPixmap(QPixmap::fromImage(img));
    }
    //--------------------

}

void MainWindow::quantization()
{
    for(int i=0;i<480;i+=r)
    {
        img.setPixel(X[i],Y[i],qRgb(0,0,0));
        for (int j=200;j<=400;j++)
        {
           img.setPixel(X[i],j,qRgb(0,0,0));
        }
        ui->label->setPixmap(QPixmap::fromImage(img));
    }
    delta=A/4;
    ui->label->setPixmap(QPixmap::fromImage(img));

    //--------------------------

}

void MainWindow::encoding()
{
    QImage img2(300,300,QImage::Format_ARGB32);
    QRgb f;
    f=qRgb(0,0,0);
    int d=Fm/Fs;
    int e=(2*A)/3;
    for(int i=d;i<300;i++)
    {

       y=A*sin((2*3.14*Fm*i)/Fs);

       //+ cycle
       if(y+A<e)
       {
           for(int k=0;k<A;k++)
           {
            img2.setPixel(i,k,f);
           }
           i+=d;
           s=s.append("11");
       }
       else if(y+A<A)
       {
           for(int k=2*e;k<A;k++)
           {
            img2.setPixel(i,k,f);
           }
           i+=d;
           s=s.append("10");
       }

       else if(y+A<2*e)
       {
           for(int k=A;k<2*e;k++)
           {
            img2.setPixel(i,k,f);
           }
           i+=d;
           s=s.append("01");
       }
       else
       {
           for(int k=2*e;k<2*A;k++)
           {
            img2.setPixel(i,k,f);
           }
           i+=d;
           s=s.append("00");
       }
    }
     ui->label2->setText(s);
     QString filename ="F:\\QT\\myPCM\\encodeddata.txt";
     QFile file(filename);
     if ( file.open(QIODevice::WriteOnly | QIODevice::Text))
             {
                 QTextStream stream( &file );
                 stream << s << endl;
                 file.close();
             }
         file.close();
}

Mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
 
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(emailheader()));
}
 
 
MainWindow::~MainWindow()
{
    delete ui;
}
 
void MainWindow::emailheader()
{
    QString path=ui->lineEdit->text();
    string p=path.toStdString().c_str();
    ifstream in(p.c_str(),ios::in);
       string sender,receiver,mesId,sub,recdate,mime_ver,from,to;
       string temp1[2];
       int i=0;
       while(in>>temp1[i])
       {
          if(temp1[i].compare("Delivered-To:")==0)
              getline(in,receiver);
          else if(temp1[i].compare("Return-Path:")==0)
              getline(in,sender);
          else if(temp1[i].compare("Date:")==0)
              getline(in,recdate);
          else if(temp1[i].compare("Message-ID:")==0)
              getline(in,mesId);
          else if(temp1[i].compare("Subject:")==0)
              getline(in,sub);
          else if(temp1[i].compare("MIME-Version:")==0)
              getline(in,mime_ver);
          else if(temp1[i].compare("From:")==0)
              getline(in,from);
          else if(temp1[i].compare("To:")==0)
              getline(in,to);
       }
      QString r = receiver.c_str();
      QString s = sender.c_str();
      QString m = mesId.c_str();
      QString su = sub.c_str();
      QString re = recdate.c_str();
      QString mi = mime_ver.c_str();
      QString fr = from.c_str();
      QString t = to.c_str();
 
      ui->deliver->setText(r);
      ui->return_2->setText(s);
      ui->messid->setText(m);
      ui->subject->setText(su);
      ui->dat->setText(re);
      ui->mime->setText(mi);
      ui->from->setText(fr);
      ui->to->setText(t);
}


OUTPUT

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.

Problem Statement:
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.

PROGRAM

database 

Last login: Tue Oct 14 13:58:41 on ttys000
Amols-MacBook-Air:~ Darwin$ mongo
MongoDB shell version: 2.6.4
connecting to: test
Server has startup warnings: 
2014-10-14T13:59:01.288+0530 [initandlisten] 
2014-10-14T13:59:01.288+0530 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
> use employee
switched to db employee
> db.createCollection("employee");
{ "ok" : 1 }
> db.employee.insert({"name":"brr1","presenty":90,"pass_rating":"pass","portion":80,"damaged_products":2});
WriteResult({ "nInserted" : 1 })
> db.employee.insert({"name":"brr2","presenty":95,"pass_rating":"pass","portion":70,"damaged_products":1});
WriteResult({ "nInserted" : 1 })
> db.employee.insert({"name":"brr3","presenty":85,"pass_rating":"fail","portion":75,"damaged_products":5});
WriteResult({ "nInserted" : 1 })
> db.employee.insert({"name":"brr4","presenty":75,"pass_rating":"fail","portion":85,"damaged_products":6});
WriteResult({ "nInserted" : 1 })
> db.employee.insert({"name":"brr5","presenty":71,"pass_rating":"pass","portion":78,"damaged_products":3});
WriteResult({ "nInserted" : 1 })
> db.employee.insert({"name":"brr6","presenty":79,"pass_rating":"fail","portion":87,"damaged_products":4});
WriteResult({ "nInserted" : 1 })

query1.r

#!/usr/bin/env Rscript
library(rJava)
library(RMongo)
mongo <- mongoDbConnect("employee","127.0.0.1","27017")
username = ""
password = ""
authenticated <- dbAuthenticate(mongo, username, password)
result<-dbGetQuery(mongo,"employee","{}",0,100) #here employee is my collection name
name<-result$name
pass_rating<- result$pass_rating
x<-factor(name)
y<-factor(pass_rating)
#X11() #calling the X11 windows graphics device!
plot(x=as.integer(x),y=as.integer(y),type = "l",xlab = "Employee", ylab = "Pass rating", axes = FALSE)
axis(side = 1, at = c(1:length(x)), labels = x)
axis(side = 2, at = c(1:length(levels(y))),labels = c("FAIL","PASS"))
dbDisconnect(mongo)
#message("Press enter to exit") #to print msg
#invisible(readLines("stdin",n=1))

#invisible(dev.off())

query2.r

#!/usr/bin/env Rscript
library(rJava)
library(RMongo)
mongo <- mongoDbConnect("employee","127.0.0.1","27017")
username = ""
password = ""
authenticated <- dbAuthenticate(mongo, username, password)
result<-dbGetQuery(mongo,"employee","{}",0,100)
names <- result$name
portion <- result$portion
iname <- as.integer(factor(names))
iportion <- c(0:100)
iportion <- seq(0,100,10)
fnames <- factor(names)
fportion <- factor(portion)
iportion <- as.integer(fportion)
#pdf(file="query2.pdf")  #calling the pdf graphics device!
plot(x = iname,y = iportion,xlab = "Employee",ylab = "Portion covered in training", axes = FALSE,type = "b")
axis(side = 2,at = iportion, labels = factor(fportion))
axis(side = 1,at = iname,labels = factor(fnames))
dbDisconnect(mongo)
#invisible(dev.off())

query3.r

#!/usr/bin/env Rscript
library(rJava)
library(RMongo)
mongo <- mongoDbConnect("employee","127.0.0.1","27017")
username = ""
password = ""
authenticated <- dbAuthenticate(mongo, username, password)
result<-dbGetQuery(mongo,"employee","{}",0,100)
presenty <- result$presenty
presenty <- 100-presenty
fpresenty <- factor(presenty)
ipresenty <- as.integer(fpresenty)
#X11()
plot(x = iname,y = ipresenty,ylab = "Absenty",xlab = "Employee",type = "b",axes = FALSE)
axis(side = 1,at = iname,labels = factor(fnames))
axis(side = 2,at = ipresenty,labels = factor(fpresenty))
dbDisconnect(mongo)
#message("Press enter to exit")      
#invisible(readLines("stdin",n=1))
#invisible(dev.off())

query4.r

#!/usr/bin/env Rscript
library(rJava)
library(RMongo)
mongo <- mongoDbConnect("employee","127.0.0.1","27017")
username = ""
password = ""
authenticated <- dbAuthenticate(mongo, username, password)
result <- dbGetQuery(mongo,"employee","{}",0,100)
name <- result$name
damage <- result$damaged_products
fname <- factor(name)
fdamage <- factor(damage)
iname <- as.integer(fname)
idamage <- as.integer(fdamage)
pdamage <- (idamage)/10
#png(file="brr.png",width=500,height=500)  #calling the image graphics driver
plot(x = iname ,y = pdamage,xlab = "Employee", ylab = "Damage products 5 samples per batch size 1000 ",type = "b",axes = FALSE)
axis(side = 1,at = iname,labels = levels(fname),)
axis(side = 2,at = pdamage,labels = levels(pdamage),)
dbDisconnect(mongo)
#invisible(dev.off())
#message("Press enter to exit")
#invisible(readLines("stdin",n=1))


Indexing and querying with MongoDB using suitable example.

Problem Statement:
Indexing and querying with MongoDB using suitable example.

TERMINAL:

[db@localhost ~]$ cd /home/pict/mongodb-linux-x86_64-2.6.3/bin
[db@localhost bin]$ ./mongo 192.168.5.122/db -u root -p root
MongoDB shell version: 2.6.3
connecting to: 192.168.5.122/db
> db.createCollection("Student");
{ "ok" : 1 }
> db.Student.insert({"_id":1,"roll_no":3205,"Name":'Amol Modi',"dmsa marks":"90","array":["name","Amol Modi","dmsa marks"]});
WriteResult({ "nInserted" : 1 })
> db.Student.insert({"_id":2,"roll_no":3206,"Name":'Anjana Pradeep',"dmsa marks":"75","array":["name","Anjana Pradeep","dmsa marks"]});
WriteResult({ "nInserted" : 1 })
> db.Student.insert({"_id":3,"roll_no":3228,"Name":'Rohan Jain',"dmsa marks":"85","array":["name","Rohan Jain","dmsa marks"]});
WriteResult({ "nInserted" : 1 })
> db.Student.insert({"_id":4,"roll_no":3254,"Name":'Payal Rathod',"dmsa marks":"70","array":["name","Payal Rathod","dmsa marks"]});
WriteResult({ "nInserted" : 1 })
> db.Student.find().pretty();
{
"_id" : 1,
"roll_no" : 3205,
"Name" : "Amol Modi",
"dmsa marks" : "90",
"array" : [
"name",
"Amol Modi",
"dmsa marks"
]
}
{
"_id" : 2,
"roll_no" : 3206,
"Name" : "Anjana Pradeep",
"dmsa marks" : "75",
"array" : [
"name",
"Anjana Pradeep",
"dmsa marks"
]
}
{
"_id" : 3,
"roll_no" : 3228,
"Name" : "Rohan Jain",
"dmsa marks" : "85",
"array" : [
"name",
"Rohan Jain",
"dmsa marks"
]
}
{
"_id" : 4,
"roll_no" : 3254,
"Name" : "Payal Rathod",
"dmsa marks" : "70",
"array" : [
"name",
"Payal Rathod",
"dmsa marks"
]
}
> db.Student.ensureIndex({"name":1}); //simple index
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
> db.Student.ensureIndex({"array":1});
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 2,
"numIndexesAfter" : 3,
"ok" : 1
}
> db.Student.ensureIndex({"_id":-1,"name":1}); //compound index
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 3,
"numIndexesAfter" : 4,
"ok" : 1
}
> db.Student.ensureIndex({"roll_no":1},{unique:true}); //unique index
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 4,
"numIndexesAfter" : 5,
"ok" : 1
}
> db.Student.find({"array":"name"}).pretty(); //querying
{
"_id" : 1,
"roll_no" : 3205,
"Name" : "Amol Modi",
"dmsa marks" : "90",
"array" : [
"name",
"Amol Modi",
"dmsa marks"
]
}
{
"_id" : 2,
"roll_no" : 3206,
"Name" : "Anjana Pradeep",
"dmsa marks" : "75",
"array" : [
"name",
"Anjana Pradeep",
"dmsa marks"
]
}
{
"_id" : 3,
"roll_no" : 3228,
"Name" : "Rohan Jain",
"dmsa marks" : "85",
"array" : [
"name",
"Rohan Jain",
"dmsa marks"
]
}
{
"_id" : 4,
"roll_no" : 3254,
"Name" : "Payal Rathod",
"dmsa marks" : "70",
"array" : [
"name",
"Payal Rathod",
"dmsa marks"
]
}
> db.Student.find({},{roll_no:1}).pretty();
{ "_id" : 1, "roll_no" : 3205 }
{ "_id" : 2, "roll_no" : 3206 }
{ "_id" : 3, "roll_no" : 3228 }
{ "_id" : 4, "roll_no" : 3254 }
> db.Student.find({roll_no:{$gt:3206}}).pretty();
{
"_id" : 3,
"roll_no" : 3228,
"Name" : "Rohan Jain",
"dmsa marks" : "85",
"array" : [
"name",
"Rohan Jain",
"dmsa marks"
]
}
{
"_id" : 4,
"roll_no" : 3254,
"Name" : "Payal Rathod",
"dmsa marks" : "70",
"array" : [
"name",
"Payal Rathod",
"dmsa marks"
]
}

Write a program in C++ to make USB Device Bootable by installing required system files.

Problem Statement:
Write a program in C++ to make USB Device Bootable by installing required system files.


PROGRAM

/* Enter in root before executing the program in terminal*/

#include<iostream>
#include<stdlib.h>

using namespace std;

class bootableusb
{
public:
void formatusb();
void isocopy();
};

void bootableusb::formatusb()
{
char ch;
cout<<"\nPl take backup!\n";
cout<<"\nDo you want still to continue(y/n)=";
cin>>ch;
if(ch=='y')
{
cout<<"\n";
string path,umount,ntfs,eject;
system("blkid");
cout<<"\nEnter path of USB=";
cin>>path;
cout<<"\n";
umount="umount "+path;
eject="eject "+path;
ntfs="mkfs.vfat "+path;
system(umount.c_str());
system(ntfs.c_str());
system(eject.c_str());
cout<<"\nPl re-insert the USB in the port as it has been ejected by program!\n";
}
else
return;
}

void bootableusb::isocopy()
{  
char ch;
cout<<"\nPl take backup!\n";
cout<<"\nDo you still want to continue(y/n)=";
cin>>ch;
if(ch=='y')
{
string copyiso,path,eject;
cout<<"\n";
system("blkid");
system("isohybrid ubuntu.iso");
cout<<"\nEnter path of USB=";
cin>>path;
cout<<"\n";
copyiso="dd if=/home/ubuntu.iso of="+path;
eject="eject "+path;
system(copyiso.c_str());
system(eject.c_str());
cout<<"\nYour USB is now bootable and ejected py program!\n";
}
else
return;
}

int main()
{
int ch;
bootableusb busb;
do{
cout<<"\n\t\tCREATE BOOTABLE USB";
cout<<"\n\t1.Format USB in FAT format."<<"\n\t2.Copy system files(making usb bootable)."<<"\n\t3.Exit.";
cout<<"\nEnter your choice: ";
cin>>ch;
switch(ch)
{
case 1: busb.formatusb();
break;
case 2: busb.isocopy();
break;
case 3: cout<<"\nExiting...\n";
break;
default: cout<<"\nInvalid Choice!";

}
}while(ch!=3);
return 0;

}

Create a iso boot image using open source tools.

Problem Statement:
Create a iso boot image using open source tools.

Required Softwares:
1. Linux x64
2. Brasero

OUTPUT:





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.

Problem Statement:

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.

PROGRAM

ramdisk.cpp

#include<iostream>
#include <stdlib.h>
using namespace std;
int main(){
cout<<"Creating Ramdisk...\n\n";
system("mkdir /mnt/ramdisk");
system("mount -t tmpfs -o size=256M tmpfs /mnt/ramdisk");
cout<<"Ramdisk created at /tmp/ramdisk/ "<<endl<<endl;
cout<<"Total size available on ramdrive:\n";
system("df -h /mnt/ramdisk");
cout<<"\n\n";
cout<<"Amount of Ramdrive used:\n";
system("du -h /mnt/ramdisk/");
system("cp input.txt /mnt/ramdisk");
system("cp calc.cpp /mnt/ramdisk");
return 0;

}

calc.cpp

#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ofstream fout;
fout.open("/mnt/ramdisk/input.txt");
int a,b,c,d,y=1;
while(y)
{
fout<<endl<<"First number : ";
cout<<"\n\nEnter Number ";
cin>>a;
fout<<a<<endl<<"Second number : ";
cout<<"\nEnter Another Number ";
cin>>b;
fout<<b<<endl;
cout<<"\nSelect your option\n\n1.Addition\n\n2.Subtraction\n\n3.Multiplication\n\n4.Division\n\nPress any key to exit ";
cin>>c;
switch(c)
{
case 1:
{
d=a+b;
cout<<"\n\nAnswer: "<<d;
fout<<"Addition is : "<<d;
break;
}
case 2:
{
d=a-b;
cout<<"\n\nAnswer: "<<d;
fout<<"Subtraction is : "<<d;
break;
}
case 3:
{
d=a*b;
cout<<"\n\nAnswer: "<<d;
fout<<"Multiplication is : "<<d;
break;
}
case 4:
{
d=a/b;
cout<<"\n\nAnswer: "<<d;
fout<<"Division is : "<<d;
break;
}
default:
{
y=0;
break;
}
}
}
fout.close();
return 0;

}

Perform a suitable assignment using Xen Hypervisor or equivalent open source to configure it. Give necessary GUI.

 To install kvm on Fedora:  yum install kvm  yum install virt-manager libvirt libvirt-python python-virtinst  su -c "yum install @v...