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;}
};

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

9 comments:

  1. In Customer Discount: return should be sum and not sum+10 if you want the code to run in skill rack

    ReplyDelete
    Replies
    1. yes, I had done that to prevent it from getting accepted on skillrack, so that I could copy it for the blog,forgot to remove it. Thanks for pointing that out.

      Delete
  2. Thanks for the help

    ReplyDelete
  3. hey.. the black and red coin program is not really running because of the gained_Power function.. I think you might need to modify your code.

    ReplyDelete
  4. The black - red coin code is working. I have tested them all.
    Maybe they modified the question, I'll look into it tonight, but I recommend you try to copy it again, maybe you made a typographicalal mistake.

    ReplyDelete
  5. UPDATE: as of now all codes are still working. I just finished verifying them, Skillrack has not changed any question.

    ReplyDelete
  6. maa ke laude
    BHOSDIKE CODE TERA BAAP COPY KAREGA

    ReplyDelete