14 Apr 2017

PPS6 - CSE1002



16th mid night is the deadline, I know, excuse the delay, I was in a dilemma, couldn't decide if it was worth putting in the extra effort to shorten the codes as much as possible only to have them stolen and then to bear with some of these cheeky cucks that go "but how do we know YOU weren't the one who stole? huh? lmao rekt" anyway here it is.

Seriously NRR gtfo you unscrupulous scum. Grow a backbone.
 
 For Copy Pasting: copyable codes are at the end of this post, scroll to the bottom.

Grade of a Student

Code:




Input:

Roll number
Name
Mark in subject1
Mark in subject2
Mark in subject3
Mark in subject4
Mark in subject5

Output:


Roll number of the student
Name of the student
Grade secured by student

Processing:

Average =sum(marks[])/5

if   Average >= ’90’ and <= ‘100’
Grade=S
else if Average >= ’80’ and < ‘90’
 Grade=A
else if Average >= ’70’ and < ‘80’
 Grade=B
else if Average >= ’60’ and < ‘70’
 Grade=C
else if Average >= ’50’ and < ‘60’
 Grade=D
else if Average >= ’40’ and < ‘50’
 Grade=E
else Grade=F

Psuedocode:


start
input roll,name,m[1],m[2],m[3],m[4],m[5]
if m[1 to 5]<0
      output NegativeMarkException
else if m[1 to 5]>100
      output OutofRangeException
else
    let Average =(m1+m2+m3+m4+m5)/5
     if   Average >= ’90’ and <= ‘100’
           Grade=S
    else if Average >= ’80’ and < ‘90’
            Grade=A
    else if Average >= ’70’ and < ‘80’
            Grade=B
    else if Average >= ’60’ and < ‘70’
            Grade=C
    else if Average >= ’50’ and < ‘60’
            Grade=D
    else if Average >= ’40’ and < ‘50’
            Grade=E
    else Grade=F
    end if
    output roll,name,grade
end if
stop


____________________________________________________________________________________________________________________

Generic Right Shift


Code:

 



Input:


Choice of data type
Number of elements
Element1 in the collection
Element2 in the collection
....
Elementn in the collection
'r'

Output:      

elements in collection after shifting

Processing:


to right shift n elements of A by r places:
let B=A
for i=1 till i=n
       A[i]=B[(i+n-r)%(n+1)]
end for

Psuedocode:

start
input n
input A[1 to n]
input r
let B=A
for i=1 till i=n
          A[i]=B[(i+n-r)%n+1)]
end for
output A[1 to n]
stop

____________________________________________________________________________________________________________________

Check if a Matrix is Sparse or Not

Code:




Input:

r1
c1
Element1 in matrix1
Element2 in matrix1
...
Element r1*c1 in matrix1
r2
c2
Element1 in matrix2
Element2 in matrix2
...
Element r2*c2 in matrix2

Output:

exception message OR
Element1 in matrix3
Element2 in matrix3
...
Element r*c in matrix3
sparce or not sparce

Processing:

C=A+B
is given by
for i=1 till i=r*c
C[i]=A[i]+B[i]
end for

Psuedocode:


start
input r1,c1 m1[1 to r1*c1]
input r2,c2, m2[1 to r2*c2]
if r1=r2 and c1=c2
      output "Dimentions of matrix do not mtch"
else
     let zeros=0
     for i=1 till i=r1*c1
              m3[i]=m1[i]+m2[i]
              output m3[i]
              if m3[i]=0
                      let  zeros=zeros+1
              end if
     end for
      if zeros>r1*c1/2
               output "Matrix is sparce"
       else
               output "Matrix is not sparce"
        end if
end if
stop 

____________________________________________________________________________________________________________________

Elements in a generic box

Code: 


(fixed,question says capacity=20, but they expected capacity=10. smh) thanks to the anonymous guy in the comments for this info.

 



Input:


Choice for type of element
Choice for operation in generic box
{1,2,3,4,5,6,7,8,9,10}
element to be inserted (if required)

Output:

"empty"/"not empty"
"full"/"not full"
elements in the box

Processing:

box is empty if if first=-1
box is full if last=capacity-1
insertion at first:
   for i= last+1 till i=2
              ele[i]=ele[i-1]
     end for
      ele[1]=data
      last=last+1
       mid=(first+last)/2
insertion at mid:
     for i=last+1 till i=mid+1
              ele[i]=ele[i+1]
      end for
       ele[mid]=data
        last=last+1
         mid=(first+last}/2
insertion at end:
        ele[last+1]=data
         last=last+1
deletion at first:
         for i=1 till i=last-1
                  ele[i]=ele[i+1]
         end for
         last=last-1
         mid=(first+last)/2
deletion at mid:
       for i=mid till i=last-1
                 ele[i]=ele[i+1]
       end for
      last=last-1
       mid=(last+first)/2
deletion at end:
        end=end-1
         mid=(start+end)/2

Psuedocode:

start
let capacity=20
while(1)
      input c
      if c=1
              output "empty"  if first=-1
             else output "not empty"
     if c=2
             output "full"  if last=capacity-1
              else output "not full"
     if c=3
              input data
                for i= last+1 till i=2
                         ele[i]=ele[i-1]
               end for
               ele[1]=data
               last=last+1
               mid=(first+last)/2
       if c=5
              input data
              for i=last+1 till i=mid+1
                       ele[i]=ele[i+1]
              end for
               ele[mid]=data
               last=last+1
               mid=(first+last}/2
       if c=4
               input data
                ele[last+1]=data
                last=last+1
                mid=(last+first)/2
       if c=6
                for i=1 till i=last-1
                      ele[i]=ele[i+1]
                end for
                last=last-1
                mid=(first+last)/2
       if c=8
               for i=mid till i=last-1
                     ele[i]=ele[i+1]
               end for
              last=last-1
               mid=(last+first)/2
      if c=7
               end=end-1
                mid=(start+end)/2
      if c=9
                 for i=first till i=last
                         output ele[i]
                  end for
       if c=10
                 goto end of while
end while
stop


____________________________________________________________________________________________________________________

Count the Number of Items

Code:

     

Input:

Choice of type of input (0- int, 1 – char, 2- book)
number of elements ‘n’
The next ‘n’ lines  contain the details of each element
 Element to be searched

Output:

count of elements

Processing:

count is given by
let count =0
for i=1 till i=n
        if a[i]=s
                  let count=count+1
       end if
end for

Psuedocode:

start
input n
input a[1 to n]
input s
let count =0
for i=1 till i=n
        if a[i]=s
                  let count=count+1
       end if
end for
output count
stop



-----------------------------------------------------------------------------------------------------------------------------------------
CODES FOR COPY-PASTING

GENERIC BOX: (question says capacity=20, but they expected capacity=10. smh)
 #define t template
t<class T>g_Box<T>::g_Box(){first=last=mid=-1;capacity=10;no_Of_Ele=0;ele=new T[20];}
t<class T>bool g_Box<T>::isEmpty(){return !(first+1);}
t<class T>bool g_Box<T>::isFull(){return no_Of_Ele==capacity;}
t<class T>void g_Box<T>::insert_First(T d){if(isFull())return;
    for(int i=last+1;i>0;i--)ele[i]=ele[i-1];
    ele[0]=d;   first=0;    mid=++last/2;   no_Of_Ele++;}
t<class T>void g_Box<T>::insert_Mid(T d){if(isFull())return;
    for(int i=last+1;i>mid;i--)ele[i]=ele[i-1];
    ele[mid]=d; first=0;    mid=++last/2;   no_Of_Ele++;}
t<class T>void g_Box<T>::insert_Last(T d){if(isFull())return;
    ele[++last]=d;first=0;mid=last/2; no_Of_Ele++;}
t<class T>void g_Box<T>::delete_First(){if(isEmpty())return;
    for(int i=0;i<last;i++)ele[i]=ele[i+1];
    mid=--last/2;   no_Of_Ele--;    if(last==-1)mid=first=-1;}
t<class T>void g_Box<T>::delete_Mid(){if(isEmpty())return;
    for(int i=mid;i<last;i++)ele[i]=ele[i+1];
    mid=--last/2;   no_Of_Ele--;    if(last==-1)mid=first=-1;}
t<class T>void g_Box<T>::delete_Last(){if(isEmpty())return;
    mid=--last/2;no_Of_Ele--;if(last==-1)mid=first=-1;}
t<class T>void g_Box<T>::print(){if(!no_Of_Ele)cout<<"Box empty\n";
    else for(int i=0;i<no_Of_Ele;)cout<<ele[i++]<<"\n";}

 
grade of student:

#define s student
void s::get(){cin>>rollno>>name;
    for(int i=5;i--;){
        cin>>marks[5-i];
        if(marks[5-i]>100)throw moreException();
        if(marks[5-i]<0)throw negException();}  }
void s::print(){cout<<rollno<<"\n"<<name<<"\n"<<grade;}
void s::calc_Avg(){avg=0;for(int i=5;i--;avg+=marks[5-i]/5);}
void s::find_Grade(){
    grade=avg>90?'S':avg>80?'A':avg>70?'B':avg>60?'C':avg>50?'D':avg>40?'E':'F';}
void negException::error_Msg() const{cout<<"Negative Marks Not Allowed";}
void moreException::error_Msg() const{cout<<"Marks Greater than 100 Not Allowed";}
int main(){
    student a;
    try{
        a.get();a.calc_Avg();a.find_Grade();a.print();
    }
    catch(negException x){x.error_Msg();}
    catch(moreException x){x.error_Msg();}
}


Matrix is sparce or not:
#define t template
#define m mismatchDimension
t<class T>void matrix<T>::get(){
    cin>>row>>col;for(int i=0;i<row*col;i++)cin>>ele[i/col][i%col];}
t<class T>bool matrix<T>::check_Sparse(){ int z=0;
    for(int i=0;i<row*col;i++)if(!ele[i/col][i%col])z++; return z>row*col/2;}
t<class T> matrix<T> matrix<T>::add(matrix &b){
    if(row-b.row||col-b.col) throw m();
    matrix a;a.row=row;a.col=col; for(int i=0;i<row*col;i++)
        a.ele[i/col][i%col]=ele[i/col][i%col]+b.ele[i/col][i%col];return a;}
t<class T> void matrix<T>::print(){
    for(int i=0;i<row*col;i++)cout<<ele[i/col][i%col]<<"\n";}
void m::error_Msg()const{cout<<"Dimension of matrices do not match\n";}


Count number of items:
template<class T,class S>int count(T *data,int size,S search){
    int c=0;
    for(int i=0;i<size;i++)c+=data[i]==search?1:0; return c;}
void book::get(){cin>>id>>name>>a_Name>>price;}
bool book::operator==(string s){return s==name;}
int main(){
    int c,s,i;cin>>c>>s;
    if(c==1){int a[s],x;for(i=0;i<s;i++)cin>>a[i];  cin>>x;
        cout<<count<int,int>(a,s,x);}
    if(c==2){char a[s],x;for(i=0;i<s;i++)cin>>a[i]; cin>>x;
        cout<<count<char,char>(a,s,x);}
    if(c==3){book a[s];string x;for(i=0;i<s;i++)a[i].get();cin>>x;
        cout<<count<book,string>(a,s,x);}
}



Generic right shift:
 template<class T>void right_Shift(T *ele,int n,int r){
    T z[n];for(int i=0;i<n;i++)z[i]=ele[i];
    for(int i=0;i<n;i++)ele[i]=z[(i+n-r)%n];}

11 Apr 2017

Inlab 8 - CSE1002

 You don't need to tick the "Request desktop site" option in your browser anymore while using a mobile device, but if you don't then the code formatting of the code given as text for copying will be disturbed.

 

Code:

[Now VERIFIED] 
{100% working.}

 

  If you know how to copy paste on skillrack then you can copy the code from below:

template<class T>
AC_BinaryTree<T>::AC_BinaryTree(){no_Of_Ele=0;capacity=20; ele=new T[20];}
template<class T> bool AC_BinaryTree<T>::isEmpty(){return !no_Of_Ele;}
template<class T> bool AC_BinaryTree<T>::isFull(){return (no_Of_Ele==20);}
template<class T> void AC_BinaryTree<T>::insert(T x){
    if (isFull()) {cout<<"Tree full insertion cannot be made\n";return;}
    ele[no_Of_Ele++]=x;
}                               //jugaadu-skillrack.blogspot.in
template<class T> T AC_BinaryTree<T>::leftChild(int x){
    if(2*x+1<no_Of_Ele) {ERR_Flag=false; return ele[2*x+1];}
    cout<<"No left child\n"; ERR_Flag=true; return ele[0];
}
template<class T> T AC_BinaryTree<T>::rightChild(int x){
    if(2*x+2<no_Of_Ele) {ERR_Flag=false; return ele[2*x+2];}
    cout<<"No right child\n"; ERR_Flag=true; return ele[0];
}
template<class T> T AC_BinaryTree<T>::parent(int x){return ele[(x-1)/2];}

Input:

Choice for type of element (1,2)

Choice for operation in tree (1,2,3,4,5,6,7)
if choice of operation =3 then: Element to be inserted

Output:


For options 1 and 2 'Empty' or 'Not empty', 'Full' or 'Not full' appropriately
value of leftchild / rightchild / parent when option is chosen and 'No left child' or 'No right child' when applicable

Processing:


left child of ele[x] is given by ele[x*2 +1]
right child of ele[x] is given by ele[x*2 +2]

parent of ele[x] is given by ele[(x-1)/2]

Psuedocode: 



start
let num=0, cap=20.
while (true)
    input choice
        if choice=1
            if num=0 output "Empty"
            else output "Not Empty"
        if choice=2
            if num=cap output "Full"
            else output "Not Full"
        if choice=3
            if num<=cap input ele[num] and let num=num+1
            else output "Tree full insertion cannot be made"
        if choice=4
            input x          
            if (2*x+1<num) output ele[2*x+1]
                else output "No left child"
        if choice=5
            input x          
            if (2*x+2<num) output ele[2*x+2]
                else output "No right child"
        if choice=6
            input x
            output ele[(x-1)/2]
        if choice=7
            goto end of while
        end if
end while
stop


23 Mar 2017

Inlab 7 - CSE1002

Do Not Tick option "Request desktop site" anymore while using mobile device.

 

Code:

Choose any one of the following 3:


Shortest Version[Now Verified]:


Fail Safe Version[Verified]:
(in case the book title/Author's Name has spaces in it 
{because in that case simple use of cin will not work since, in a way, the default delimiters are whitespaces so we need to change it to '\n' with getline() }) {as it turns out, the names do not contain spaces so "shortest code" will work this is no longer "recommended" or needed}.
  

Long version[Verified]
( in case you wanted a long version(?) )

Input:

Type of material (0/1)
isbn number
title
author
year of publication
number of pages/duration 

Output:

isbn number
title
cost 

Processing:

for books: 
      cost=pages
for CD:
       cost=2*duration  

Psuedocode: 


start
input type,isbn,title,author,year
if type=0
       input pages
       let cost = pages 
else
      input duration
      let cost = 2*duration
end if
output isbn,title,cost
stop   

20 Mar 2017

PPS 5 - CSE1002

DO NOT Tick option "Request desktop site" anymore while using mobile device.

Bear with the delay, again. No excuses, I'm just lazy. Thank you for your patience.
UPDATE:  all the codes for copy-pasting now available as simple text(copyable),scroll to the bottom of this post.

College Application

Code:



Input:

Type of application
Name
Age        
m1
m2
...
m6
m7(only for engineering student)

Output:

Name
Cut-off marks

Processing:

if student is engineering student then
       cut_off=(m3+m4+m5)/3 + m7
else
      cut _off=(m1+m2+m3+m4+m5+m6)/6


Psuedocode:

start
input type,no,name,age,m1,m2,m3,m4,m5,m6
if type=1
      input m7
      let cut_off=(m3+m4+m5)/3 + m7
else
      let cut _off=(m1+m2+m3+m4+m5+m6)/6
end if
output cut_off
stop

____________________________________________________________________________________________________________________

Cost of Pizza

Code:



Input:

0 for veg pizza and 1 for chicken pizza
Radius
Number of ingredients required
Name of ingredient1
Quantity of ingredient1 required (in grams)
Name of ingredient2
Quantity of ingredient2 required
....
Name of ingredient-n
Quantity of ingredient-n required
Number of ingredients available
Name of ingredient-1 available
Cost of 100 gm of ingredient1 available
Name of ingredient-2
Cost of 100 gm of ingredient2
...
Name of ingredient-n
Cost of 100 gm of ingredient-n

Output:

cost of pizza

Processing:

for i=1 till i=num
       cost =cost +qty[i]*price of ing[i] *pi*radius^2
end for
cost=cost +50
if chicken pizza
         cost =cost +50
end if

Psuedocode:

start
input type,radius,n
for i=1 till i=n
       input ing[i],qty[i]
end for
input n1
for i=1 till i=n
       input ing1[i],price[i]
end for
let cost=50
for i=1 till i=num
       cost =cost +qty[i]*price of ing[i](from ing1,price table) *pi*radius^2
end for
if type=1
         cost =cost +50
end if
output cost
stop

____________________________________________________________________________________________________________________

Black Coin in Board game

Code:


Input:

b.w; Weight of black coin
b.r; Current row position of coin
b.c; Current column position of coin
m; Number of moves made by black coin

Output:

b.w; Weight of black coin
List of possible next positions

Processing:

if m=>5
 then convert black coin to red coin
if coin is black
       possible move is b.r+1,b.c
if coin is red
       possible moves is given by
       r.r-1,r.c;    r.r+1,r.c;    r.r,r.c-1;  r.r,r.c+1;  
       r.r-1,r.c-1;r.r+1,r.c-1;r.r-1,r.c+1;r.r+1,r.c+1 

Psuedocode:

start
input w, b.r, b.c, m;
if m>=5
          let r.r=b.r,  r.c=b.c,  r.w=b.w;
          output r.w;  r.r-1,r.c;    r.r+1,r.c;    r.r,r.c-1;  r.r,r.c+1;   r.r-1,r.c-1;r.r+1,r.c-1;r.r-1,r.c+1;r.r+1,r.c+1
else
          output b.w;   b.r+1,b.c;
end if
stop

____________________________________________________________________________________________________________________

Customer discount

Code:

       (fixed)





Input:

Type of customer
Name
Mobile number
Address
Customer id
Number of bills
bill1
....
bill-n

Output:

Total amount to be paid by the customer for 'n' bills

Processing:

if customer is ordinary discount is 0%
else discount is as determined by given table based on the initial cost.

Psuedocode:

start
input type,name,no,add,id,n
let sum=0
for i=1 till i=n
        input b[i]
        let sum=sum+b[i]
end for
if type=1
        let c=0
    for i=0 till i=n
    c=c+b[i]
        if c>=20000
             sum=sum-b[i]*0.04
       else        if c>=15000
             sum=sum-b[i]*0.03
       else        if c>=10000
             sum=sum-b[i]*0.02
       else        if c>=5000
              sum=sum-b[i]*0.99
        end if
end if
output sum
stop

____________________________________________________________________________________________________________________

Polygon in a Two Dimensional Space


Code:

 

 

 

Input:

value of X- coordinate of point1
value of Y- coordinate of point1
...
value of X- coordinate of point6
value of Y- coordinate of point6
Next eight entries are Vertices of a
value of X- coordinate of point1
value of Y- coordinate of point1
...
value of X- coordinate of point
value of Y- coordinate of point
index of the vertex  of the polygon, whose coordinate has to be printed. 

Output:

Area of triangle
Area of quadrilateral
Value of X- coordinate and Y- coordinate of point-n separated by tab or print Out of range if index is not in range

Processing:

area of a polygon is given by the aforementioned formula.

area of triangle=mod(x1y2-x2y1+x2y3-x3y2+x3y1-x1y3)/2

area of quad=mod(x1y2-x2y1+x2y3-x3y2+x3y4-x4y3+x4y1-x1y4)/2

Psuedocode:

start
input x1,y1,x2,y2,x3,y3
area=mod(x1y2-x2y1+x2y3-x3y2+x3y1-x1y3)/2
output area
input x1,y1,x2,y2,x3,y3,x4,y4
area=mod(x1y2-x2y1+x2y3-x3y2+x3y4-x4y3+x4y1-x1y4)/2
output area
input i
if i<=4
   output x[i],y[i]
else
   output outofrange
end if
stop


-----------------------------------------------------------------------------------------------------------------------------------------
CODES FOR COPY-PASTING
---customer----------------------------------------


#include<iostream>
using namespace std;
class customer{
    protected:
    char na[30],add[50],no[12],id[10];
    int b[50],n,sum;
    public:
    void get(){cin>>na>>no>>add>>id>>n;    sum=0;
        for(int i=0;i<n;sum+=b[i++])cin>>b[i];
    }
    int calc_Total(){return sum;}
};                      //jugaadu-skillrack.blogspot.in
class preferred_Customer:public customer{
    public:
    int calc_Total(){
        for(int i=0,s=b[0];i<n;s+=b[++i])
        sum-=b[i]*(s>=20000?4:s>=15000?3:s>=10000?2:s>=5000?1:0)/100;
        return sum; }
};


---area of polygon-------------------------------------


ostream& operator<<(ostream& o,point p){o<<p.x<<"\n"<<p.y<<"\n";return o;}
point::point(){}
polygon::polygon(int n){num_Of_Ver=n;vertices=new point[n];}
polygon::~polygon(){delete vertices;}
void polygon::get(){for(int i=0;i<num_Of_Ver;i++)cin>>vertices[i].x>>vertices[i].y;}
point& polygon::operator[](int idx){if (idx>num_Of_Ver) throw (outofrange());
    return vertices[idx];}                         
double polygon::area(){double a=0;for(int i=0;i<num_Of_Ver;i++)
    a+=vertices[i].x*vertices[(i+1)%num_Of_Ver].y-vertices[i].y*vertices[(i+1)%num_Of_Ver].x;
    return a<0?-a/2:a/2;}
void outofrange::what(){cout<<"Out of range";}



---black coin red coin------------------------------------------


void coin::get(){cin>>weight>>curr_X>>curr_Y;}
void coin::print(){cout<<weight<<"\n";}
int coin::get_Curr_X(){return curr_X;}
int coin::get_Curr_Y(){return curr_Y;}
int coin::get_Weight(){return weight;}
class black_Coin: public coin{public:
    int gained_Power(){int m; cin>>m; return (m>=5)?1:0;}
    virtual void move(){cout<<curr_X<<","<<curr_Y+1<<"\n";}
};                                    
class red_Coin: public coin{public:
    void set_Curr_Pos_Wt(black_Coin b)
    {weight=b.get_Weight();curr_Y=b.get_Curr_Y();curr_X=b.get_Curr_X();}
    virtual void move(){int x=curr_X,y=curr_Y;
        cout<<x-1<<","<<y<<"\n"<<x+1<<","<<y<<"\n"<<x<<","<<y-1<<"\n"<<x<<","<<y+1<<"\n";
    cout<<x-1<<","<<y-1<<"\n"<<x+1<<","<<y-1<<"\n"<<x-1<<","<<y+1<<"\n"<<x+1<<","<<y+1<<"\n";}
};


---college--------------------------------------------------------


void college_Appln::get(){cin>>appln_No>>name>>age;for(int i=0;i<6;i++)cin>>marks[i];}
void arts_Appln::calc_Cutoff(){cutoff=0;for(int i=0;i<6;cutoff+=marks[i++]);cutoff/=6;}
void arts_Appln::print(){cout<<name<<"\n"<<fixed<<setprecision(2)<<cutoff;}
void engg_Appln::print(){cout<<name<<"\n"<<fixed<<setprecision(2)<<cutoff;}
void engg_Appln::get(){college_Appln::get();cin>>entrance;}
void engg_Appln::calc_Cutoff(){cutoff=(marks[2]+marks[3]+marks[4])/3 +entrance;}



---pizza----------------------------------------------------------


class pizza:public circle,public cookeditem{
  public: float c;
 void get_P(){cin>>radius>>num;for(int i=0;i<num;i++)cin>>ing_Qty[i].name>>ing_Qty[i].qty;}
 float compute_Cost(kitchen k){c=50;for(int i=0;i<num;i++)
    c+=ing_Qty[i].qty*k.get_Cost(ing_Qty[i].name)*3.14*radius*radius/100;}
 void print_P(){cout<<fixed<<setprecision(2)<<c;}
};                                                 
void kitchen::get_K(){
    cin>>num1;for(int i=0;i<num1;i++)cin>>ing_Cost[i].name>>ing_Cost[i].price;}
float kitchen::get_Cost(char *n){
    for(int i=0;i<num1;i++)if(!strcmp(n,ing_Cost[i].name))return ing_Cost[i].price;}
class veg_Pizza:public pizza{int x;};
class chik_Pizza:public pizza{public:
    float compute_Cost(kitchen k){pizza::compute_Cost(k);c+=50;}
};

---------------------------------------------------------------

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)
num2;  Number 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

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