5 Feb 2017

PPS 3 - CSE1002

IMPORTANT: Tick option "Request desktop site" while using mobile device, or else code formating may be disturbed. or alternatively hold device in landscape mode.

Input & Output can be dragged and dropped directly from the question (with some editing, as required). Psuedocode can be written easily based on the codes given below or copied from elsewhere. (advice: no one reads any of it, just write any psuedocode anywhere.)
If there is any problem with the formatting of the blog, code etc. or if you have suggestions to improve any aspect of it contact me (reffer to contact/feedback button at top of page) with details of the kind of device used(mobile/laptop) etc.

Snakes And Ladders

#include<stdio.h>
int x;
void read_Values(board &b,snakes &s,ladders &l,position &p,rolls &r){
     cin>>b.row>>b.col>>s.num;
     for(int i=0;i<s.num;scanf("%d%d",&s.st_Grid[i],&s.end_Grid[i]),i++);
     for(int i=0,x=scanf("%d",&l.num);i<l.num;scanf("%d%d",&l.st_Grid[i],&l.end_Grid[i]),i++);
     for(int i=0,x=scanf("%d%d%d",&p.row,&p.col,&r.num);i<r.num;scanf("%d",&r.roll[i]),i++);
}
int find_New_Pos(board &b,snakes &s,ladders &l,position &p,rolls &r){

    int a=(p.row-1)*b.col + p.col;
    for(int i=0;i<r.num;i++){
        a+=r.roll[i];

        for(int j=0;j<l.num||j<s.num;j++){
            if(j<s.num&&a==s.st_Grid[j]) a=s.end_Grid[j];
            else if(j<l.num&&a==l.st_Grid[j]) a=l.end_Grid[j];
        }
    }
    return a;
}





Chess Carrom and Scrabble players

 void set::get(){
    cin>>num_Of_Ele;
    for(int i=0;i<num_Of_Ele;i++) cin>>names[i];
}
void set::print() const {
    for(int i=0;i<num_Of_Ele-1;i++) cout<<names[i]<<",";
    cout<<names[num_Of_Ele-1]<<"\n";
}
set set::intersection(set &a) {
    set x;
    x.num_Of_Ele=0;
    for(int i=0;i<num_Of_Ele;i++)
    for(int j=0;j<a.num_Of_Ele;j++)

    if(!strcmp(names[i],a.names[j])) strcpy(x.names[x.num_Of_Ele++],names[i]);
    return x;
}
set set::difference(set &a){
    set x;
    x.num_Of_Ele=0;
    for(int i=0,flag=1;i<num_Of_Ele;flag=1,i++){
    for(int j=0;j<a.num_Of_Ele;j++)
    if(!strcmp(names[i],a.names[j])) flag=0;
    if(flag) strcpy(x.names[x.num_Of_Ele++],names[i]);
    }
    return x;
}



Tender Scrutiny using reference variable

 
#include<iostream>
using namespace std;
struct a{
    int n;
    char a[30];
    int c;
};
a &min(a l[],int n){
    int min=l[0].c,mini=0;
    for (int i=1;i<n;i++)
    if(l[i].c<min){
        min=l[i].c;
        mini=i;
    }
    return l[mini];
}
int main(){
    int n;
    a l[30];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>l[i].n>>l[i].a>>l[i].c;
    }
    cout<<min(l,n).n<<"\n"<<min(l,n).a;
}


Automatic Vending Machine


#include<iostream>
using namespace std;
int main()
{
    int n,a[20][3],r,c,found=-1;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i][0]>>a[i][1]>>a[i][2];
    cin>>r>>c;
    try{
        for(int i=0;i<n;i++) if(a[i][0]==r) found=i;
        if(found==-1) throw((int)1);
        if(a[found][1]>c) throw((double)1);
        if(a[found][2]==0) throw("x");
        cout<<a[found][0];
    }
    catch(int a) {cout<<"Wrong item code";}
    catch(double a) {cout<<"Insufficient amount";}
    catch(char* a) {cout<<"Less stock";}
}


Vector Operations

(based on new question, earlier there was no pre-written code so the answer was much shorter, however it was changed recently even though some people had already solved it.)

void vector::get(){
    cin>>num;   ele=new int[num];
    for(int i=0;i<num;i++)   cin>>ele[i];
}
vector vector::sum(vector&a){
    vector x;   x.num=num;   x.ele=new int[num];
    for(int i=0;i<num;i++) x.ele[i]=a.ele[i]+ele[i];
    return x;
}
void vector::print(){
    for(int i=0;i<num;i++) cout<<ele[i]<<"\n";
}
int vector::product(vector& a){
    int d=0;
    for(int i=0;i<num;i++) d+=a.ele[i]*ele[i];
    return d;
}
vector::vector(){ num=0; ele=NULL;}
vector::vector(int a){ num=1; ele[0]=a;}

1 comment:

  1. Plzzz don't keep pictures.... If u keep code directly we r more thankful....

    ReplyDelete