-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththird.cpp
More file actions
99 lines (63 loc) · 1.15 KB
/
third.cpp
File metadata and controls
99 lines (63 loc) · 1.15 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Programm to implement CDMA
* Prateek Prasher
*/
#include <iostream>
using namespace std;
int main()
{
int cA[4],
cB[4],
sA[4],
sB[4],
cS[4],
A,
B,
sum = 0;
// Get the codes
cout << "Enter the first code: ";
for(int i = 0; i < 4; i++)
{
cin >> cA[i];
if(cA[i] == 0)
{
cA[i] = -1;
}
}
cout << endl << "Enter the second code: ";
for(int i = 0; i < 4; i++)
{
cin >> cB[i];
if(cB[i] == 0)
{
cB[i] = -1;
}
}
// Get the data
cout << endl << "Enter A and B: "; cin >> A >> B;
if(A == 0)
A = -1;
if(B == 0)
B = -1;
// Now process at the sending end
cout << endl << "Intermediate code mixing A and B is: ";
for(int i = 0; i < 4; i++)
{
cS[i] = (A * cA[i]) + (B * cB[i]);
cout << cS[i];
cout << " ";
}
// Now process at the receiving end
for(int i = 0; i < 4; i++)
{
sum += cS[i] * cA[i]; // For A
}
cout << endl << "A's received as: " << (sum > 0) ? 1 : 0; cout << endl;
sum = 0;
for(int i = 0; i < 4; i++)
{
sum += cS[i] * cB[i]; // For B
}
cout << endl << "B's received as: " << (sum > 0) ? 1 : 0; cout << endl;
return 1;
}