Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c2f4e94

Browse files
author
Abdullah
committed
init
0 parents commit c2f4e94

24 files changed

+2010
-0
lines changed

‎.gitignore‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
*.smod
22+
23+
# Compiled Static libraries
24+
*.lai
25+
*.la
26+
*.a
27+
*.lib
28+
29+
# Executables
30+
*.exe
31+
*.out
32+
*.app

‎2_0_decode_message.cpp‎

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#include <iostream>
2+
3+
using std::cin;
4+
using std::cout;
5+
6+
int getModulo(int nr, int mode);
7+
char getCharacter(int nr, int mode);
8+
char getPunctuation(int nr);
9+
enum modeType {UPPERCASE, LOWERCASE, PUNCTUATION};
10+
11+
int main()
12+
{
13+
14+
char digit;
15+
char ch = '0';
16+
int nr = 0;
17+
int mode = UPPERCASE;
18+
int modulo = 0;
19+
digit = cin.get();
20+
21+
22+
while(digit != 10) {
23+
while (!(digit == 10 || digit == ',')) {
24+
nr = nr*10 + digit - '0';
25+
digit = cin.get();
26+
}
27+
modulo = getModulo(nr, mode);
28+
if (modulo == 0) {
29+
mode = ++mode % 3;
30+
} else {
31+
ch = getCharacter(modulo, mode);
32+
cout << ch;
33+
}
34+
nr = 0;
35+
digit = cin.get();
36+
}
37+
38+
}
39+
40+
41+
42+
int getModulo(int nr, int mode) {
43+
if (nr == 0) return 0;
44+
switch(mode) {
45+
case UPPERCASE:
46+
return nr % 27;
47+
break;
48+
case LOWERCASE:
49+
return nr % 27;
50+
break;
51+
case PUNCTUATION:
52+
return nr % 9;
53+
break;
54+
default:
55+
return '0';
56+
break;
57+
}
58+
59+
60+
}
61+
62+
char getCharacter(int modulo, int mode)
63+
{
64+
switch(mode) {
65+
case 0:
66+
return 'A' + modulo - 1;
67+
break;
68+
case 1:
69+
return 'a' + modulo - 1;
70+
break;
71+
case 2:
72+
return getPunctuation(modulo);
73+
break;
74+
default:
75+
return '0';
76+
break;
77+
}
78+
}
79+
80+
char getPunctuation(int modulo)
81+
{
82+
switch(modulo) {
83+
case 1:
84+
return '!';
85+
break;
86+
case 2:
87+
return '?';
88+
break;
89+
case 3:
90+
return ',';
91+
break;
92+
case 4:
93+
return '.';
94+
break;
95+
case 5:
96+
return ' ';
97+
break;
98+
case 6:
99+
return ';';
100+
break;
101+
case 7:
102+
return '"';
103+
break;
104+
case 8:
105+
return '\'';
106+
break;
107+
default:
108+
return '0';
109+
break;
110+
}
111+
}
112+
113+
114+

‎2_0_half_square.cpp‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <iostream>
2+
3+
using std::cin;
4+
using std::cout;
5+
6+
int main()
7+
{
8+
9+
char digitChar;
10+
11+
char c;
12+
13+
int oddSum = 0;
14+
int evenSum = 0;
15+
int finalSum = 0;
16+
17+
int i = 1;
18+
cout << "Enter a number and press enter to validate: ";
19+
digitChar = cin.get();
20+
while (digitChar != 10) {
21+
int digit = 0;
22+
digit = digitChar - '0';
23+
if (i % 2 == 0) { //If position is even from left
24+
evenSum += digit;
25+
digit *= 2;
26+
if (digit >= 10) {
27+
digit = 1 + (digit - 10);
28+
}
29+
oddSum += digit;
30+
finalSum = evenSum;
31+
} else { //If position is odd from left
32+
oddSum += digit;
33+
digit *= 2;
34+
if (digit >= 10) {
35+
digit = 1 + (digit - 10);
36+
}
37+
evenSum += digit;
38+
finalSum = oddSum;
39+
}
40+
digitChar = cin.get();
41+
i++;
42+
cout << "Checksum is " << finalSum << "\n";
43+
}
44+
if (finalSum % 10 == 0) {
45+
cout << "The digit is valid! \n";
46+
} else {
47+
cout << "The digit is invalid! \n";
48+
}
49+
50+
51+
}
52+
53+

‎2_0_luhne_checksum.cpp‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <iostream>
2+
3+
using std::cin;
4+
using std::cout;
5+
6+
int main()
7+
{
8+
9+
char digitChar;
10+
11+
int oddSum = 0;
12+
int evenSum = 0;
13+
int finalSum = 0;
14+
15+
int pos = 1;
16+
cout << "Enter a number and press enter to validate: ";
17+
digitChar = cin.get();
18+
while (digitChar != 10) {
19+
int digit = 0;
20+
digit = digitChar - '0';
21+
if (pos % 2 == 0) { //If position is even from left
22+
evenSum += digit;
23+
digit *= 2;
24+
if (digit >= 10) {
25+
digit = 1 + (digit - 10);
26+
}
27+
oddSum += digit;
28+
finalSum = evenSum;
29+
} else { //If position is odd from left
30+
oddSum += digit;
31+
digit *= 2;
32+
if (digit >= 10) {
33+
digit = 1 + (digit - 10);
34+
}
35+
evenSum += digit;
36+
finalSum = oddSum;
37+
}
38+
digitChar = cin.get();
39+
pos++;
40+
cout << "Checksum is " << finalSum << "\n";
41+
}
42+
if (finalSum % 10 == 0) {
43+
cout << "The digit is valid! \n";
44+
} else {
45+
cout << "The digit is invalid! \n";
46+
}
47+
48+
49+
}
50+
51+

‎2_1_hash_shape.cpp‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <sstream>
2+
#include <iostream>
3+
#include <iomanip>
4+
5+
using std::cin;
6+
using std::cout;
7+
using std::endl;
8+
using std::setw;
9+
10+
int main()
11+
{
12+
13+
int shapeWidth = 8;
14+
15+
for (int row = 0; row < 4; row++) {
16+
cout << setw(row+1);
17+
for(int hashNum = 0; hashNum < shapeWidth-2*row; hashNum++) {
18+
cout << "#";
19+
}
20+
cout << "\n";
21+
}
22+
}

‎2_2_hash_shape.cpp‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <sstream>
2+
#include <iostream>
3+
#include <iomanip>
4+
5+
using std::cin;
6+
using std::cout;
7+
using std::endl;
8+
using std::setw;
9+
10+
int main()
11+
{
12+
13+
int shapeWidth = 8;
14+
int repeat = shapeWidth;
15+
int change = 2;
16+
17+
18+
for (int width = 2; width > 0; width+=change) {
19+
cout << setw((shapeWidth - width)/2+1);
20+
for(int hashNum = 0; hashNum < width; hashNum++) {
21+
cout << "#";
22+
}
23+
cout << "\n";
24+
if (width == repeat)
25+
{
26+
width += 2;
27+
change *= -1;
28+
repeat = -1;
29+
continue;
30+
}
31+
}
32+
}

‎2_3_hash_shape.cpp‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <sstream>
2+
#include <iostream>
3+
#include <iomanip>
4+
5+
using std::cin;
6+
using std::cout;
7+
using std::endl;
8+
using std::setw;
9+
10+
int main()
11+
{
12+
enum lr {LEFT, RIGHT, NEXT};
13+
14+
int hashSizeInCenter = 4;
15+
int repeat = hashSizeInCenter;
16+
int spaceWidth = (hashSizeInCenter-1)*4+1;
17+
int indent = 1;
18+
int pos = LEFT;
19+
int change = 1;
20+
21+
22+
for (int width = 1; width > 0; width += change) {
23+
pos = LEFT;
24+
while (pos != NEXT) {
25+
if (pos == LEFT) {
26+
cout << setw(indent);
27+
}
28+
else {
29+
cout << setw(spaceWidth);
30+
}
31+
for (int hashNum = 0; hashNum < width; hashNum++)
32+
{
33+
cout << "#";
34+
}
35+
pos = ++pos % 3;
36+
}
37+
cout << "\n";
38+
if (width == repeat)
39+
{
40+
width += change;
41+
change *= -1;
42+
repeat = -1;
43+
continue;
44+
}
45+
spaceWidth -= 4*change;
46+
indent += change;
47+
48+
}
49+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /