25 Feb 2017

inlab 5 - CSE1002

 Tick option "Request desktop site" while using mobile device, or else code formating may be disturbed.


Code:

void item::get(){
    cin>>prod_name>>prod_code>>prod_price>>stock_In_Hand;}
void item::print() const{
cout<<prod_name<<"\n"<<prod_code<<"\n"<<prod_price<<"\n"<<stock_In_Hand<<"\n";}
void store::get_details(){ cin>>num_Of_Items;
    for(int i=0;i<num_Of_Items;items[i++].get());}
void store_keeper::stock_mgmt(store &a){
    for(int i=0;i<a.num_Of_Items;i++)

    if(a.items[i].stock_In_Hand<10) a.items[i].print();}

Input:

n (number of products)
next n lines contain:
    Name of the product
    Product code
    Price
    stock in hand

Output:

complete details of the product whose available stock is less than 10

Processing:

for i=1 till i=number of items
      if i'th item's stock<10
                output i'th item's details

Psuedocode:

start
input n
for i=1 till i=n
      input name,code,price,stock for i'th item
end for
for i=1 till i=n
      if i'th item's stock<10
                output i'th item's name, code, price, stock
      end if
end for
stop

10 Feb 2017

inlab 4 - CSE1002

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

If there is any problem with the formatting of the blog, code (not likely.) etc. or if you have suggestions to improve any aspect of it contact me (reffer to contact/feedback button at top of page) along with details of the kind of device used(mobile/laptop) etc.


Code:

#include<iostream>
using namespace std;
class ap{
    int f; int d;
public:
    ap()               {cin>>f>>d;}
    int an(int x)      {return f+d*(x-1);}
    int r(int x)       {return (x-f)/d +1;}
    int ad(int a,int b){return abs((a-b)*d);}
};
int main(){
ap a; int z,x,c,v;
cin>>z>>x>>c>>v;
cout<<a.an(z)<<"\n"<<a.r(x)<<"\n"<<a.ad(c,v);
}


(update:) if however there is some fixed code written before and after the code window then write the following code in the box (skillrack seems to have again changed the original question format)



void apr::get(){cin>>first>>diff;}

int apr::compute_term(unsigned int n){ return(first+(n-1)*diff);}
int apr::find_r(int k){ return(((k-first)/diff)+1);}
int apr::abs_diff(unsigned int p,unsigned int q){
    return(abs((p-q)*diff)); }



Input:

First line contains the first term of the AP
Next line contains the common difference d
Next line contains the value of k
Next line contains the value of p
Next line contains the value of q

Output:

First line contains the nth of the arithmetic progression
Next line contains the value of ‘r’
Next line contains the absolute difference between a_p and a_q

Psuedocode:

start
input f,d,k,p,q
let nth= f+d*(n-1)
let r= (k-f)/d +1
let abs_dif= absolute value of (p-q)*d
output nth,r,abs_dif
stop

8 Feb 2017

inlab 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.

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) along with details of the kind of device used(mobile/laptop) etc.


Code:


#include<stdio.h>
using namespace std;
int main(){
int x=1,n;
for(int i=(int)scanf("%d\n%*s%*s",&n);i<n;x*=i++,scanf("%*s"));
printf("%d",x);
}


Input:

Number of cities
Name of the cities
Home city name

Output:

Number of routes to be analyzed in brute force approach

Psuedocode:

start
input n
let x=1
for i=1 till i=n
       let x=x*i
       input string y
end for
output x
stop

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