OOPS_basic_2
#include <iostream>
#include <string>
using namespace std;
class maths{
private:
string s;
public:
void input(void);
void checkbinary(void);
void onecompliment();
void display();
};
void maths:: input()
{ cin>>s;
}
void maths:: checkbinary()
{
for(int i=0;i<s.length();i++)
{
if(!(s.at(i)=='0'||s.at(i)=='1'))
{
cout<<"Not a binary number"<<endl;
exit(0);
}
}
}
void maths::onecompliment()
{
for(int i=0;i<s.length();i++)
{
if(s.at(i)=='1')
s.at(i)='0';
else
s.at(i)='1';
}
}
void maths::display()
{
cout<<s<<endl;
}
int main() {
maths first;
first.input();
first.display();
first.checkbinary();
first.onecompliment();
first.display();
return 0;
}
Comments
Post a Comment