-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeek4_2.cpp
More file actions
49 lines (47 loc) · 817 Bytes
/
Copy pathWeek4_2.cpp
File metadata and controls
49 lines (47 loc) · 817 Bytes
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
//Using half adder in bitwise
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int add(int x,int y)
{
while (y != 0)
{
int carry = x&y;
x = x^y;
y = carry << 1;
}
return x;
}
main()
{
ifstream aFile("a.txt");
string text;
if(aFile.is_open())
{
getline(aFile,text);
}
string text1,text2;
int checkpoint=0;
for(int i=0;i<text.size();i++)
{
if(text[i]!=' ')
text1.push_back(text[i]);
else
{
checkpoint=i+1;
break;
}
}
for(int i=checkpoint;i<text.size();i++)
{
text2.push_back(text[i]);
}
int num1 = stoi(text1);
int num2 = stoi(text2);
ofstream bFile("b.txt");
if(bFile.is_open())
{
bFile << add(num1,num2);
}
}