Prefix Increment

#include <iostream>
using namespace std;
class increment
{
  public:
  float a,b,c;
  void getx()
  {
    cin>>a>>b>>c;
  }
  void operator ++();
 
};
void increment::operator ++()
  {
   a=a+1.0;
  b=b+1.0;
  c=c+1.0;
   cout<<a<<" "<<b<<" "<<c;
}
int main() {
increment obj;
  obj.getx();
  obj.operator ++();
return 0;
}

3 comments:

  1. Declare a,b,c as double not float it will be 100%.

    ReplyDelete
  2. #include
    using namespace std;
    class increment
    {
    public:
    float a,b,c;
    void getx()
    {
    cin>>a>>b>>c;
    }
    void operator ++();

    };
    void increment::operator ++()
    {
    a=a+1.0;
    b=b+1.0;
    c=c+1.0;
    cout<<a<<" "<<b<<" "<<c;
    }
    int main() {
    increment obj;
    obj.getx();
    obj.operator ++();
    return 0;
    }

    ReplyDelete