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

No comments:

Post a Comment

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...