booths.h file:
#ifndef BOOTHS_H
#define BOOTHS_H
class booths //Class Booths
{public:
int q,a,b;
public:
booths();
void operation();
};
#endif // BOOTHS_H
booths.cpp
#include "booths.h"
#include "mainwindow.h"
booths::booths()
{
q=0;
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include"booths.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow,public booths
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow(); /*
void operations();
void binary(int,int*); Functions
void add(int*,int*);
void rshift(int,int*); */
booths b1;
private slots: //Functions
void on_multiply_clicked();
void on_clear_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include"booths.h"
#include"math.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow() //Destructor
{
delete ui;
}
void MainWindow::operations()
{int i,j;
int A[8]={0,0,0,0,0,0,0,0},C[8]={0,0,0,0,0,0,0,1},
C1[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
int s=0,z=0,Q[8],M[8],temp1[8],ans[16],y,x=0,c=0;
b1.a=ui->lineEdit->text().toInt();
b1.b=ui->lineEdit_2->text().toInt();
binary(b1.a,M); //binary M
binary(b1.b,Q); //binary Q
ui->display->setText(ui->display->text()+
"\n-------------------------------------------------------------\n");
ui->display->setText(ui->display->text()+
"Operation A\t\t Q\t\t Q'\t M");
ui->display->setText(ui->display->text()+"\n\n INITIAL\t");
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+
QString::number(A[i]));
ui->display->setText(ui->display->text()+"\t");
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+QString::number(Q[i]));
ui->display->setText(ui->display->text()+"\t");
ui->display->setText(ui->display->text()+
QString::number(b1.q)+"\t");
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+QString::number(M[i]));
for(j=0;j<8;j++)
{
if(Q[7]==0&&b1.q==1)
{
ui->display->setText(ui->display->text()+"\n A:=A+M \t");
add(A,M); //Add A + M
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+
QString::number(A[i]));
ui->display->setText(ui->display->text()+"\t");
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+
QString::number(Q[i]));
ui->display->setText(ui->display->text()+"\t");
ui->display->setText(ui->display->text()+
QString::number(b1.q)+"\t");
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+
QString::number(M[i]));
}
if(Q[7]==1&&b1.q==0)
{
ui->display->setText(ui->display->text()+"\n A:=A-M \t");
for(i=0;i<8;i++)
temp1[i]=1-M[i];
add(temp1,C);
add(A,temp1);
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+
QString::number(A[i]));
ui->display->setText(ui->display->text()+"\t");
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+
QString::number(Q[i]));
ui->display->setText(ui->display->text()+"\t");
ui->display->setText(ui->display->text()+
QString::number(b1.q)+"\t");
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+
QString::number(M[i]));
}
ui->display->setText(ui->display->text()+"\n ASR \t");
y=A[7];
b1.q=Q[7];
rshift(A[0],A);
rshift(y,Q);
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+
QString::number(A[i]));
ui->display->setText(ui->display->text()+"\t");
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+
QString::number(Q[i]));
ui->display->setText(ui->display->text()+"\t");
ui->display->setText(ui->display->text()+
QString::number(b1.q)+"\t");
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+
QString::number(M[i]));
}
ui->display->setText(ui->display->text()+
"\n-------------------------------------------------------------\n");
ui->display->setText(ui->display->text()+
"\nThe Answer in Binary is: \n");
for(i=0;i<8;i++)
ans[i]=A[i];
for(i=0;i<8;i++)
ans[i+8]=Q[i];
for(i=0;i<16;i++)
ui->display->setText(ui->display->text()+
QString::number(ans[i]));
if(((b1.a<0)&&(b1.b>0))||((b1.a>0)&&(b1.b< 0)))
{
for(i=0;i<16;i++)
ans[i]=1-ans[i];
for(i=15;i>=0;i--)
{
x=ans[i];
ans[i]=c^x^C1[i];
if(((c==1)&&(x==1))||((x==1)&&(C1[i]==1))||((C1[i]==1)&&(c==1)))
c=1;
else
c=0;
}
}
for(i=15;i>=0;i--)
{
s=s+(pow(2,z)*ans[i]);
z=z+1;
}
if(((b1.a<0)&&(b1.b>0))||((b1.a>0)&&(b1.b< 0)))
ui->display->setText(ui->display->text()+"\nThe Answer in Decimal is: \n-"+
QString::number(s)+"\n");
else
ui->display->setText(ui->display->text()+"\nThe Answer in Decimal is: \n"+
QString::number(s)+"\n");
}
void MainWindow::binary(int x,int*arr) //Binary Function
{
int i,p=x,c[8]={0,0,0,0,0,0,0,1};
for(i=0;i< 8;i++)
arr[i] = 0;
if(x < 0)
x = x *-1;
i = 7;
do
{
arr[i]=x%2;
x = x/2;
i--;
}while(x!=0);
if(p< 0)
{
for(i=0;i< 8;i++)
arr[i]=1-arr[i];
add(arr,c);
}
ui->display->setText(ui->display->text()+
"\n The Binary Equivalent is: ");
for(i=0;i<8;i++)
{ui->display->setText(ui->display->text()+QString::number(arr[i]));
}
}
void MainWindow::add(int *a,int *b) //Add Function
{
int x,i,c=0;
for(i=7;i>=0;i--)
{
x=a[i];
a[i]=c^x^b[i];
if(((c==1)&&(x==1))||((x==1)&&(b[i]==1))||((b[i]==1)&&(c==1)))
c = 1;
else
c = 0;
}
}
void MainWindow::rshift(int x,int *y) //RightShift Function
{
int i;
for(i=7;i>0;i--)
y[i] = y[i-1];
y[0] = x;
}
void MainWindow::on_multiply_clicked() //Operations()
{
operations();
}
void MainWindow::on_clear_clicked()
{
ui->display->clear();
ui->lineEdit->clear();
ui->lineEdit_2->clear();
}
#ifndef BOOTHS_H
#define BOOTHS_H
class booths //Class Booths
{public:
int q,a,b;
public:
booths();
void operation();
};
#endif // BOOTHS_H
booths.cpp
#include "booths.h"
#include "mainwindow.h"
booths::booths()
{
q=0;
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include"booths.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow,public booths
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow(); /*
void operations();
void binary(int,int*); Functions
void add(int*,int*);
void rshift(int,int*); */
booths b1;
private slots: //Functions
void on_multiply_clicked();
void on_clear_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include"booths.h"
#include"math.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow() //Destructor
{
delete ui;
}
void MainWindow::operations()
{int i,j;
int A[8]={0,0,0,0,0,0,0,0},C[8]={0,0,0,0,0,0,0,1},
C1[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
int s=0,z=0,Q[8],M[8],temp1[8],ans[16],y,x=0,c=0;
b1.a=ui->lineEdit->text().toInt();
b1.b=ui->lineEdit_2->text().toInt();
binary(b1.a,M); //binary M
binary(b1.b,Q); //binary Q
ui->display->setText(ui->display->text()+
"\n-------------------------------------------------------------\n");
ui->display->setText(ui->display->text()+
"Operation A\t\t Q\t\t Q'\t M");
ui->display->setText(ui->display->text()+"\n\n INITIAL\t");
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+
QString::number(A[i]));
ui->display->setText(ui->display->text()+"\t");
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+QString::number(Q[i]));
ui->display->setText(ui->display->text()+"\t");
ui->display->setText(ui->display->text()+
QString::number(b1.q)+"\t");
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+QString::number(M[i]));
for(j=0;j<8;j++)
{
if(Q[7]==0&&b1.q==1)
{
ui->display->setText(ui->display->text()+"\n A:=A+M \t");
add(A,M); //Add A + M
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+
QString::number(A[i]));
ui->display->setText(ui->display->text()+"\t");
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+
QString::number(Q[i]));
ui->display->setText(ui->display->text()+"\t");
ui->display->setText(ui->display->text()+
QString::number(b1.q)+"\t");
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+
QString::number(M[i]));
}
if(Q[7]==1&&b1.q==0)
{
ui->display->setText(ui->display->text()+"\n A:=A-M \t");
for(i=0;i<8;i++)
temp1[i]=1-M[i];
add(temp1,C);
add(A,temp1);
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+
QString::number(A[i]));
ui->display->setText(ui->display->text()+"\t");
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+
QString::number(Q[i]));
ui->display->setText(ui->display->text()+"\t");
ui->display->setText(ui->display->text()+
QString::number(b1.q)+"\t");
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+
QString::number(M[i]));
}
ui->display->setText(ui->display->text()+"\n ASR \t");
y=A[7];
b1.q=Q[7];
rshift(A[0],A);
rshift(y,Q);
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+
QString::number(A[i]));
ui->display->setText(ui->display->text()+"\t");
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+
QString::number(Q[i]));
ui->display->setText(ui->display->text()+"\t");
ui->display->setText(ui->display->text()+
QString::number(b1.q)+"\t");
for(i=0;i<8;i++)
ui->display->setText(ui->display->text()+
QString::number(M[i]));
}
ui->display->setText(ui->display->text()+
"\n-------------------------------------------------------------\n");
ui->display->setText(ui->display->text()+
"\nThe Answer in Binary is: \n");
for(i=0;i<8;i++)
ans[i]=A[i];
for(i=0;i<8;i++)
ans[i+8]=Q[i];
for(i=0;i<16;i++)
ui->display->setText(ui->display->text()+
QString::number(ans[i]));
if(((b1.a<0)&&(b1.b>0))||((b1.a>0)&&(b1.b< 0)))
{
for(i=0;i<16;i++)
ans[i]=1-ans[i];
for(i=15;i>=0;i--)
{
x=ans[i];
ans[i]=c^x^C1[i];
if(((c==1)&&(x==1))||((x==1)&&(C1[i]==1))||((C1[i]==1)&&(c==1)))
c=1;
else
c=0;
}
}
for(i=15;i>=0;i--)
{
s=s+(pow(2,z)*ans[i]);
z=z+1;
}
if(((b1.a<0)&&(b1.b>0))||((b1.a>0)&&(b1.b< 0)))
ui->display->setText(ui->display->text()+"\nThe Answer in Decimal is: \n-"+
QString::number(s)+"\n");
else
ui->display->setText(ui->display->text()+"\nThe Answer in Decimal is: \n"+
QString::number(s)+"\n");
}
void MainWindow::binary(int x,int*arr) //Binary Function
{
int i,p=x,c[8]={0,0,0,0,0,0,0,1};
for(i=0;i< 8;i++)
arr[i] = 0;
if(x < 0)
x = x *-1;
i = 7;
do
{
arr[i]=x%2;
x = x/2;
i--;
}while(x!=0);
if(p< 0)
{
for(i=0;i< 8;i++)
arr[i]=1-arr[i];
add(arr,c);
}
ui->display->setText(ui->display->text()+
"\n The Binary Equivalent is: ");
for(i=0;i<8;i++)
{ui->display->setText(ui->display->text()+QString::number(arr[i]));
}
}
void MainWindow::add(int *a,int *b) //Add Function
{
int x,i,c=0;
for(i=7;i>=0;i--)
{
x=a[i];
a[i]=c^x^b[i];
if(((c==1)&&(x==1))||((x==1)&&(b[i]==1))||((b[i]==1)&&(c==1)))
c = 1;
else
c = 0;
}
}
void MainWindow::rshift(int x,int *y) //RightShift Function
{
int i;
for(i=7;i>0;i--)
y[i] = y[i-1];
y[0] = x;
}
void MainWindow::on_multiply_clicked() //Operations()
{
operations();
}
void MainWindow::on_clear_clicked()
{
ui->display->clear();
ui->lineEdit->clear();
ui->lineEdit_2->clear();
}
Output
display function not working. Showing error
ReplyDeleteerror: 'class Ui::MainWindow' has no member named 'display'
ui->display->setText(ui->display->text()+
^