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)
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

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