6 Mar 2017

inlab 6 - CSE1002

Tick option "Request desktop site" while using mobile device, or else code formating may be disturbed.

Sorry for the delay, I was waiting for other blogs to post their rather long codes first so that they wont copy mine, but they haven't posted so I decided to go first.  Thank you for your patience.
If you admin a blog:  stop lurkin bruh; like I said earlier lets keep it fair.

 

Code:

New code, shortened version of the previous one:
 
(click image to expand it)
or download clear image at: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9665z9aGqQs1H7A4yOL9X5W8P1yZNTYpFCmQddp-nxABegOfLyIg-7i6x0G7L0oMoSbsRdnGqL5IqNQFZ3DI7yqHiCU_kiXDHExPnOzFQxPBbpJtjllLDlolWGoM2adjTHtkaMoTlhSoF/s1600/inlab6_e.png

 

Input:

num1;  Number of terms in polynomial 1
co-efficient of term-i of polynomial 1,
exponent of term-i of polynomial 1; ( i=1 to num1)
num2Number of terms in polynomial2
co-efficient of term-i of polynomial 2,
exponent of term-i of polynomial 2; ( i=1 to num2)

Output:

sum of polynomial 1 and 2
pre-increment  of sum of polynomial 1 and 2
post-increment  of sum of polynomial 1 and 2

Processing:

if
x's coefficient= p's highest term's coefficient + 1  
x's exponent= p's highest term's exponent + 1
then ++p is defined as
 p + x

Psuedocode: 

{shortened because if the procedure for addition is included it will be too long} 
start
input num1
for i=1 till i=num1
      input p1[i].c , p1[i].e;
end for
input num2
for i=1 till i=num2
      input p2[i].c , p2[i].e;
end for
p3=p1+p2
for i=1 till i=num3
      output p3[i].c , p3[i].e;
end for
let x= p2[1]
let x.c=x.c+1
let x.e=x.e+1
let p2=p2+x
let p4=p2
let x= p1[1]
let x.c=x.c+1
let x.e=x.e+1
let p1=p1+x
let p5=p1+p4
for i=1 till i=num5
      output p5[i].c , p5[i].e;
end for
let x= p3[1]
let x.c=x.c+1
let x.e=x.e+1
let p3=p3+x
for i=1 till i=num3
      output p5[i].c , p5[i].e;
end for
stop



even shorter Psuedocode in case you're running out of time:

start
input p1
input p2
p3=p1+p2
output p3
let x= p2[1]
let x.c=x.c+1, x.e=x.e+1
let p2=p2+x, p4=p2
let x= p1[1]
let x.c=x.c+1, x.e=x.e+1
let p1=p1+x, p5=p1+p4
output p5
let x= p3[1]
let x.c=x.c+1, x.e=x.e+1
let p3=p3+x
output p3
stop

No comments:

Post a Comment