6 Mar 2017

PPS 4 - 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.. the other blogs.. to post their rather long codes first so that they wont copy mine, but its been 4 days and they haven't posted anything so I decided to go first.  Thank you for your patience.
If you admin a blog: get outta here nigga, stop stealing; "game on!!!"? sure but lets keep it fair.

Computing Area Of different Shapes

Code:



Input:

base and height of a rectangle.
top, bottom and height of a trapezoid.
radius of a circle.

Output:

area of a rectangle, trapezoid and circle

Processing:

area of a rectangle= h * b
area of a trapezoid= h * [ t + b ] / 2
area of a circle = pi * r^2, where pi = 3.14

Psuedocode:

start
input l,w
output l*w
input t,b,h
output h*(t+b)/2
input r
output 3.14*r*r
stop

____________________________________________________________________________________________________________________

Sort a Given Set of Points

Code:




Input:

n;
x, y coordinates of n points

Output:

'n' points in sorted order

Processing:

to sort array p:
for i=2 till i=n
        t=p[i]
        for j=i-1 till j=1 while ar[j]>t
                ar[j+1]=ar[j]
         end for
        ar[j+1]=t
end for

Psuedocode:

start
input n
for int i=1 till i=n
         input p[i].x,p[i].y
end for
for i=2 till i=n
        let t=p[i]
        for j=i-1 till j=1 while ar[j]>t
                let ar[j+1]=ar[j]
         end for
        let ar[j+1]=t
end for
for int i=1 till i=n
         output p[i].x, "    ", p[i].y
end for
stop

____________________________________________________________________________________________________________________

Vector operations

Code:




Input:

n1 , dimension of vector 1
elements of vector 1
n2; dimension of vector 2
elements of vector 2
  i
  j

Output:

i-th element of vector1
j-th element of vector2
v1+v2
v1-v2

Processing:

v3= v1+v2: is obtained by
for i=1 till i=dimention of v1
       v3[i]=v1[i]+v2[i]
v3= v1-v2: is obtained by
for i=1 till i=dimention of v1
       v3[i]=v1[i]-v2[i]

Psuedocode:

start
input n1
for i=1 till i=n1
       input v1[i]
end for
input n2
for i=1 till i=n2
       input v2[i]
end for
input i,j
output v1[i],v2[j]
for i=1 till i=n1
       sum[i]=v1[i]+v2[i]
       diff[i]=v1[i]-v2[i]
end for
for i=1 till i=n1
       output sum[i]
end for
for i=1 till i=n1
       output diff[i]
end for
stop

____________________________________________________________________________________________________________________

String operations

Code:





Input:

s1, string
s2, string
n rotation index

Output:

rotation(S1,n)
oddfirst(S2)
evenfirst(S1)
Spin(S1,S2)
Oddevenswap(S1,S2)
Evenoddswap(S1,S2)

Processing:

rotation(S,n) is the string  S1 such that the letter in the k-th  position  in S is the (n-k+1)-th letter in S1.

oddfirst of a string S is got by placing all the letters occurring in the odd positions of S sequentially  and then placing all the letters occurring in the even positions of S, sequentially.

evenfirst of a string S is got by placing all the letters occurring in the even positions of S sequentially and then placing all the letters occurring in the odd positions of S, sequentially.

Spin of two strings S1 and S2 is got by placing the first letter of S2 between the first and the second letter  of S1, placing the second letter  of S2 between the second and the third letter of S1 and so on.

Oddevenswap(S1,S2) produces a string such that the  letters occurring in the odd positions  of S1 are  replaced by the letters occurring in the corresponding even positions of S2.

evenoddwap(S1,S2) produces a string such that the  letters occurring in the even  positions  of S1 are  replaced by the letters occurring in the corresponding odd  positions of S2.

Psuedocode:

start
input s1,s2,n
let s=rotation(s1,n)
output s
let s=oddfirst(s2) {a string S  got by placing all the letters occurring in the odd positions of s2 sequentially  and then placing all the letters occurring in the even positions of S, sequentially.}
output s
let s=evenfirst(s1) {a string S is got by placing all the letters occurring in the even positions of s1 sequentially and then placing all the letters occurring in the odd positions of S, sequentially. }
output s
let s=spin(s1,s2){ got by placing the first letter of S2 between the first and the second letter  of S1, placing the second letter  of S2 between the second and the third letter of S1 and so on. }
output s
let s=oddevenswap(s1,s2) {a string such that the  letters occurring in the odd positions  of S1 are  replaced by the letters occurring in the corresponding even positions of S2}
output s
let s=evenoddswap(s1,s2){ a string such that the  letters occurring in the even  positions  of S1 are  replaced by the letters occurring in the corresponding odd  positions of S2}
output s
stop

____________________________________________________________________________________________________________________

Boarding Pass


Code:

            (updated)

 

 

Input:

name
x
Age
Address
date
mobile number
fare

Output:

name
Boarding pass number
age
date
mobile number
fare

Processing:

Boarding pass number = "CA" + x
if age between 12 and 58, fare= 0.8*fare
 if age 'above 58 , fare=0.6*fare
 if age under 12, fare=0.5*fare

Psuedocode:

start
input name,x,age,add,date,mob,fare
let pass= concatenation of "CA" and x
 if age between 12 and 58
         fare= 0.8*fare
 else if age 'above 58 ,
         fare=0.6*fare
else if age under 12,
          fare=0.5*fare
end if
output name,pass,age,date,mob,fare
stop

No comments:

Post a Comment