//PROGRAM TO FIND THE 1s COMPLEMENT OF THE ENTERED BINARY NUMBER
/*MADE BY KRISHNA AGARWAL*/
#include<iostream.h>
#include<conio.h>
#include<string.h>
class binary
{
char s[30];
public:
void read(void)
{
cout<<"enter a binary number\n";
cin>>s;
}
void ckh_bin(void)
{
for(int i=0;s[i]!=0;i++)
{
if(s[i]!=0&&s[i]!=0)
{
cout<<"\nincorrect binary format....program is quit\n";
getch();
exit(0);
}
}
}
void ones(void)
{
void chk_bin(); //calling member function
for(int i=0;s[i]!=0;i++)
{
if(s[i]=='0')
s[i]='1';
else
s[i]='0';
}
}
void displayones(void)
{
ones(); //calling member function
cout<<"\nthe 1s complement of the above binary number is \n"<<s;
}
}; //class end bracket
void main()
{
clrscr();
binary b;
b.read();
b.displayones();
getch();
}
/*MADE BY KRISHNA AGARWAL*/
#include<iostream.h>
#include<conio.h>
#include<string.h>
class binary
{
char s[30];
public:
void read(void)
{
cout<<"enter a binary number\n";
cin>>s;
}
void ckh_bin(void)
{
for(int i=0;s[i]!=0;i++)
{
if(s[i]!=0&&s[i]!=0)
{
cout<<"\nincorrect binary format....program is quit\n";
getch();
exit(0);
}
}
}
void ones(void)
{
void chk_bin(); //calling member function
for(int i=0;s[i]!=0;i++)
{
if(s[i]=='0')
s[i]='1';
else
s[i]='0';
}
}
void displayones(void)
{
ones(); //calling member function
cout<<"\nthe 1s complement of the above binary number is \n"<<s;
}
}; //class end bracket
void main()
{
clrscr();
binary b;
b.read();
b.displayones();
getch();
}
No comments:
Post a Comment