TAB

One of the works done by our Robotics and Machine Learning division,
SELF-LEVELING QUADCOPTER
Arduino based Quadcopter.
Self-leveling is acheived by the aligning the quadcopter using the readings from the gryo as well as the accelerometer.
A four channel RC transmitter is used to control the movement of the quadcopter when in flight. Kindly subscribe to our YouTube Channel and stay tuned.

Friday 12 February 2016

PRACTICE PROBLEM 3 : (11-2 to 17-2) : Automatic vending machine

FOR DETAILED EXPLANATION : VIDEO
----------------------------------------------------------------------------------------------------------------------
Please watch the video,your views mean a lot!
========================================================================
#include<iostream>
using namespace std;
class item
{
long id;
long cost;
long stock;
public:
void read()
{
cin>>id;
cin>>cost;
cin>>stock;
}
int check(int n)
{
if(n==id)
return 1;
else
throw(0);
}
int costcheck(int n)
{
if(n>cost)
return 1;
else
throw(0.0);
}
int stockcheck()
{
if(stock>=1)
return 1;
else
throw string("ERROR");
}
void display()
{
cout<<id;
}


};
int main()
{
int n;
cin>>n;
item I[n];
for(int i=0;i<n;i++)
{
I[i].read();
}
int it,c;
cin>>it;
cin>>c;
int c2=0;
//cout<<"\n";
for(int i=0;i<n;i++)
{
try
{
I[i].check(it);
I[i].costcheck(c);
I[i].stockcheck();
I[i].display();
}
catch(int i)
{
c2++;
}
catch(double k)
{
cout<<"Insufficient amount"<<endl;
break;
}catch(string a)
{
cout<<"Less stock"<<endl;
break;
}
}
if(c2==n)
cout<<"Wrong item code";
return 0;
}

2 comments:

  1. #include
    #include
    using namespace std;
    struct details
    { char code[20];
    int cost;
    int stock;
    }d[10];
    int main()
    { int n;
    char cd[20];
    int price;
    cin>>n;
    for(int i=0;i>d[i].code;
    cin>>d[i].cost;
    cin>>d[i].stock;
    }
    cin>>cd>>price;
    for(int i=0;i=d[i].cost) && (d[i].stock>0) )
    {cout<=d[i].cost) && (d[i].stock<=0))
    {cout<<"Less stock"; break;}
    else
    {cout<<"Wrong item code";break;}

    }

    return 0;}




    //hidden text error

    ReplyDelete
    Replies
    1. Code looks incomplete.
      Moreover your for loops have incomplete braces and double initializing of i.I am unable to comprehend. Logic doesn't seem to be right .Please clearify.

      Delete