You are on page 1of 6

August 31, 2022 [NA ASSIGNMENT 2 (035,053)

Bahria University, Islamabad Campus


Department of Software Engineering
Class/Section: BSE-6
(SUMMER 2022 Semester)

NA ASG # 2

SYEDA TAYYABA TANVEER 01-131192-035

MUHAMMAD FAIZAN ULLAH 01-131192-053

SUBMITTED TO: SIR ALEEM AHMED


August 31, 2022 [NA ASSIGNMENT 2 (035,053)

Code
// NA_ASG__2_053_035

#include<iostream>
using namespace std;

int create_difference_table()
{
float x[20], f[20][20];
int i, j, size;

// total number of values


cout << "Enter total number of values: " << endl;
cin >> size;
cout<< endl;
cout << "---------Enter values-----------" << endl << endl;
for (i = 0; i < size; i++)
{
cout << "x[" << i << "] = ";
cin >> x[i];
cout << "y[" << i << "] = ";
cin >> f[i][0];
}

/*Difference Table*/
for (i = 1; i < size; i++)
{
for (j = 0; j < size - i; j++)
{
f[j][i] = f[j + 1][i - 1] - f[j][i - 1];
}
}

cout << endl << "------------------DIFFERENCE TABLE-------------------" <<


endl;
for (i = 0; i < size; i++)
{
cout << x[i];
for (j = 0; j < size - i; j++)
{
cout << "\t" << f[i][j];
}
cout << endl;
}

//Error finding
bool check = false;
i = 3;
j = 0;
{
//4th
if (f[i][j] >= 0 && f[i][j+1] <0 && f[i][j + 2] >= 0 && f[i][j + 3]<0
&& f[i][j + 4] >=0)
August 31, 2022 [NA ASSIGNMENT 2 (035,053)

{
check = true;
if (check = true)
{
cout << endl;
cout << "-----------Error is in 4th order--------------"
<< endl;
return 0;
}
}
if (f[i][j+1] >= 0 && f[i][j + 2] < 0 && f[i][j + 3] >= 0 && f[i][j +
4] < 0 && f[i][j + 5] >= 0)
{
check = true;
if (check = true)
{
cout << endl;
cout << "-----------Error is in 4th order--------------"
<< endl;
return 0;
}
}
//3rd
i = 2;
if (f[i][j] >= 0 && f[i][j + 1] < 0 && f[i][j + 2] >= 0 && f[i][j + 3]
< 0)
{
check = true;
if (check = true)
{
cout << endl;
cout << "-----------Error is in 3rd order--------------"
<< endl;
return 0;
}
}
if (f[i][j+1] >= 0 && f[i][j + 2] < 0 && f[i][j + 3] >= 0 && f[i][j +
4] < 0)
{
check = true;
if (check = true)
{
cout << endl;
cout << "-----------Error is in 3rd order--------------"
<< endl;
return 0;
}
}
if (f[i][j+2] >= 0 && f[i][j + 3] < 0 && f[i][j + 4] >= 0 && f[i][j +
5] < 0)
{
check = true;
if (check = true)
{
cout << endl;
cout << "-----------Error is in 3rd order--------------"
<< endl;
return 0;
August 31, 2022 [NA ASSIGNMENT 2 (035,053)

}
}
if (f[i][j+3] >= 0 && f[i][j + 4] < 0 && f[i][j + 5] >= 0 && f[i][j +
6] < 0)
{
check = true;
if (check = true)
{
cout << endl;
cout << "-----------Error is in 3rd order--------------"
<< endl;
return 0;
}
}

//2nd
i = 1;
if (f[i][j] >= 0 && f[i][j + 1] < 0 && f[i][j + 2] >= 0)
{
check = true;
if (check = true)
{
cout << endl;
cout << "-----------Error is in 2nd order--------------"
<< endl;
return 0;
}
}
if (f[i][j+1] >= 0 && f[i][j + 2] < 0 && f[i][j + 3] >= 0)
{
check = true;
if (check = true)
{
cout << endl;
cout << "-----------Error is in 2nd order--------------"
<< endl;
return 0;
}
}
if (f[i][j+2] >= 0 && f[i][j + 3] < 0 && f[i][j + 4] >= 0)
{
check = true;
if (check = true)
{
cout << endl;
cout << "-----------Error is in 2nd order--------------"
<< endl;
return 0;
}
}
if (f[i][j=3] >= 0 && f[i][j + 4] < 0 && f[i][j + 5] >= 0)
{
check = true;
if (check = true)
{
cout << endl;
cout << "-----------Error is in 2nd order--------------"
<< endl;
August 31, 2022 [NA ASSIGNMENT 2 (035,053)

return 0;
}
}
if (f[i][j+4] >= 0 && f[i][j + 5] < 0 && f[i][j + 6] >= 0)
{
check = true;
if (check = true)
{
cout << endl;
cout << "-----------Error is in 2nd order--------------"
<< endl;
return 0;
}
}
if (f[i][j+5] >= 0 && f[i][j + 6] < 0 && f[i][j + 7] >= 0)
{
check = true;
if (check = true)
{
cout << endl;
cout << "-----------Error is in 2nd order--------------"
<< endl;
return 0;
}
}

void main()
{
create_difference_table(); // with error finding
}

output
August 31, 2022 [NA ASSIGNMENT 2 (035,053)

in the above output 4th order error pattern of

+ (e)

- (-4e)

+ (6e)

- (e)

Is present in 4th order of above difference table.

X----------X----------X

You might also like