-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9. Octal.cpp
58 lines (58 loc) · 1.03 KB
/
9. Octal.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<iostream>
#include<math.h>
using namespace std;
class octal
{
public:
int oct[200],count;
octal(int);
friend int operator +(octal,int);
friend ostream & operator <<(ostream &,octal&);
};
octal::octal(int x)
{
int a[200];
int i=0,rem,n;
while(x!=0)
{
rem=x%8;
a[i]=rem;
i=i+1;
x=x/8;
}
count =i;
n=count-1;
for(i=0;i<count;i++)
oct[i]=a[n-i];
}
int operator +(octal o1,int n)
{
int s=0;
for(int i=0;i<o1.count;i++)
{
s=s+(o1.oct[(o1.count)-i-1]*pow(8,i));
}
return(n+s);
}
ostream & operator <<(ostream &print,octal &h)
{
for(int i=0;i<h.count;i++)
{
print<<h.oct[i];
}
return print;
}
int main()
{
int x,y,k;
cout<<"Enter integer:-";
cin>>x;
octal h(x);
cout<<"Enter an integer to add:-";
cin>>k;
y=h+k;
cout<<"Octal of "<<x<<" is "<<h<<"\n";
cout<<"The integer after adding is ";
cout<<y;
return 0;
}