## ~riderius/cpp-code

52f13cb94b3e89c64a7bc43b5d6ce9a528abd2cf — RIDERIUS 9 months ago
```stylized by Google style
```
```10 files changed, 69 insertions(+), 73 deletions(-)

M Celsius_to_Fahrenheit_converter.cpp
M Light_years_to_Astronomical_Units_Converter.cpp
M codetime.cpp
M decimal2binary.cpp
M digit_or_letter.cpp
M digits_analysis.cpp
M guess_the_number.cpp
M math_stat.cpp
M reverse_int.cpp
M screensaver.cpp
```
`M Celsius_to_Fahrenheit_converter.cpp => Celsius_to_Fahrenheit_converter.cpp +1 -2`
```@@ 6,8 6,7 @@ double converter(int celsius);
int main()
{
int celsius;
-    while (true)
-    {
+    while (true) {
cout << "PLease enter a celsius value: ";
cin >> celsius;
cout << celsius << " degrees Celsius is " << converter(celsius) << " degrees Fahrenheit." << endl;

```
`M Light_years_to_Astronomical_Units_Converter.cpp => Light_years_to_Astronomical_Units_Converter.cpp +0 -1`
```@@ 10,7 10,6 @@ int main()
cout << "Enter the number of light years: ";
cin >> light_years;
cout << light_years << " light years = " << converter(light_years) << " astronomical units." << endl;
-
}
double converter(double light_years)
{

```
`M codetime.cpp => codetime.cpp +9 -7`
```@@ 1,22 1,24 @@
-#include <iostream>
+#include <cstdlib>
#include <ctime>
+#include <iostream>
#include <string>
-#include <cstdlib>

-void execute(const char * path) {
+void execute(const char* path)
+{
std::system(path);
}

-int main(int argc, char* argv[]) {
+int main(int argc, char* argv[])
+{
using namespace std;
string path;
-    if(argc == 1)
+    if (argc == 1)
getline(cin, path);
-    else if(argc == 2)
+    else if (argc == 2)
path = argv[1];
else {
path = argv[1];
-        for(int i = 2; i < argc; i++) {
+        for (int i = 2; i < argc; i++) {
path += " ";
path += argv[i];
}

```
`M decimal2binary.cpp => decimal2binary.cpp +7 -6`
```@@ 1,15 1,15 @@
-﻿#include <iostream>
-#include <cstdlib>
+﻿#include <cstdlib>
+#include <iostream>

int HHH(unsigned int a, int n);

-int main(int argc, char *argv[]) {
+int main(int argc, char* argv[])
+{
using namespace std;
unsigned int num;
if (argc > 1) {
num = atoi(argv[1]);
-    }
-    else
+    } else
cin >> num;
int temp = num, sizeofnumber = 0;
while (temp > 0) {

@@ 25,7 25,8 @@ int main(int argc, char *argv[]) {
return 0;
}

-int HHH(unsigned int a, int n) {
+int HHH(unsigned int a, int n)
+{
int d = sizeof(a) * 8;
a = a << (d - n);
a = a >> (d - 1);

```
`M digit_or_letter.cpp => digit_or_letter.cpp +2 -1`
```@@ 1,6 1,7 @@
#include <iostream>

-int main(void) {
+int main(void)
+{
using namespace std;

char symbol;

```
`M digits_analysis.cpp => digits_analysis.cpp +9 -17`
```@@ 1,5 1,5 @@
-#include <iostream>
#include <climits>
+#include <iostream>

int SumOfDigits(int n);
int NumberOfZeroes(int n);

@@ 25,10 25,8 @@ int main(void)
int NumberOfZeroes(int n)
{
int result = 0;
-    while (n != 0)
-    {
-        if (n % 10 == 0)
-        {
+    while (n != 0) {
+        if (n % 10 == 0) {
result++;
}
n /= 10;

@@ 39,8 37,7 @@ int NumberOfZeroes(int n)
int SumOfDigits(int n)
{
int result = 0;
-    while (n != 0)
-    {
+    while (n != 0) {
result += n % 10;
n /= 10;
}

@@ 50,10 47,8 @@ int SumOfDigits(int n)
int MinDigit(int n)
{
int min = INT_MAX;
-    while (n != 0)
-    {
-        if (n % 10 < min)
-        {
+    while (n != 0) {
+        if (n % 10 < min) {
min = n % 10;
}
n /= 10;

@@ 64,10 59,8 @@ int MinDigit(int n)
int MaxDigit(int n)
{
int max = INT_MIN;
-    while (n != 0)
-    {
-        if (n % 10 > max)
-        {
+    while (n != 0) {
+        if (n % 10 > max) {
max = n % 10;
}
n /= 10;

@@ 78,8 71,7 @@ int MaxDigit(int n)
int reverse(int n)
{
int result = 0;
-    while (n != 0)
-    {
+    while (n != 0) {
result = result * 10 + n % 10;
n /= 10;
}

```
`M guess_the_number.cpp => guess_the_number.cpp +7 -5`
```@@ 1,8 1,9 @@
-#include <iostream>
#include <cstdlib>
#include <ctime>
+#include <iostream>

-int main(int argc, char* argv[]) {
+int main(int argc, char* argv[])
+{
using namespace std;

int highest_num;

@@ 15,7 16,7 @@ int main(int argc, char* argv[]) {

srand(time(NULL));
int secret_num = 1 + rand() % highest_num, your_num, attempts = 0;
-    while(your_num != secret_num) {
+    while (your_num != secret_num) {
cout << "Enter the number: ";
cin >> your_num;
if (secret_num < your_num)

@@ 24,7 25,8 @@ int main(int argc, char* argv[]) {
cout << "Our number is greater" << endl;
attempts++;
}
-    cout << "You guessed. Number of attempts: " << attempts << ". " << "The hidden number is " << secret_num << endl;
-
+    cout << "You guessed. Number of attempts: " << attempts << ". "
+         << "The hidden number is " << secret_num << endl;
+
return 0;
}

```
`M math_stat.cpp => math_stat.cpp +12 -9`
```@@ 1,10 1,11 @@
-﻿#include <iostream>
-#include <cmath>
+﻿#include <cmath>
+#include <iostream>

long long fib(long long n);
long long factorial(long long num);

-int main(int argc, char *argv[]) {
+int main(int argc, char* argv[])
+{
using namespace std;

const long double Pi = 3.1415926535897932;

@@ 18,10 19,10 @@ int main(int argc, char *argv[]) {
cout << endl;
}

-    cout << "square " << num*num << endl;
-    cout << "cube " << num*num*num << endl;
+    cout << "square " << num * num << endl;
+    cout << "cube " << num * num * num << endl;
cout << "sqrt " << sqrt(num) << endl;
-    if(num > -1 && num < 21) {
+    if (num > -1 && num < 21) {
cout << "fib " << fib(num) << endl;
cout << "factorial " << factorial(num) << endl;
}

@@ 36,7 37,8 @@ int main(int argc, char *argv[]) {
return 0;
}

-long long fib(long long n) {
+long long fib(long long n)
+{
long long fib0 = 0, fib1 = 1, temp, count = 1;
while (count != n) {
temp = fib1;

@@ 47,9 49,10 @@ long long fib(long long n) {
return fib1;
}

-long long factorial(long long n) {
+long long factorial(long long n)
+{
long long num = 1;
-    for(int i = 1; i <= n; i++) {
+    for (int i = 1; i <= n; i++) {
num *= i;
}
return num;

```
`M reverse_int.cpp => reverse_int.cpp +1 -2`
```@@ 14,8 14,7 @@ int main()
int reverse(int n)
{
int result = 0;
-    while (n != 0)
-    {
+    while (n != 0) {
result = result * 10 + n % 10;
n /= 10;
}

```
`M screensaver.cpp => screensaver.cpp +21 -23`
```@@ 1,8 1,9 @@
-#include <ncurses.h>
#include <cstring>
#include <locale>
+#include <ncurses.h>

-int main(void) {
+int main(void)
+{
setlocale(LC_ALL, "");
initscr();

@@ 15,19 16,19 @@ int main(void) {

clear();

-    init_pair(0,  COLOR_RED,     COLOR_BLACK);
-    init_pair(1,  COLOR_GREEN,   COLOR_BLACK);
-    init_pair(2,  COLOR_YELLOW,  COLOR_BLACK);
-    init_pair(3,  COLOR_BLUE,    COLOR_BLACK);
-    init_pair(4,  COLOR_MAGENTA, COLOR_BLACK);
-    init_pair(5,  COLOR_CYAN,    COLOR_BLACK);
-    init_pair(6,  COLOR_BLUE,    COLOR_WHITE);
-    init_pair(7,  COLOR_WHITE,   COLOR_RED);
-    init_pair(8,  COLOR_BLACK,   COLOR_GREEN);
-    init_pair(9, COLOR_BLUE,    COLOR_YELLOW);
-    init_pair(10, COLOR_WHITE,   COLOR_BLUE);
-    init_pair(11, COLOR_WHITE,   COLOR_MAGENTA);
-    init_pair(12, COLOR_BLACK,   COLOR_CYAN);
+    init_pair(0, COLOR_RED, COLOR_BLACK);
+    init_pair(1, COLOR_GREEN, COLOR_BLACK);
+    init_pair(2, COLOR_YELLOW, COLOR_BLACK);
+    init_pair(3, COLOR_BLUE, COLOR_BLACK);
+    init_pair(4, COLOR_MAGENTA, COLOR_BLACK);
+    init_pair(5, COLOR_CYAN, COLOR_BLACK);
+    init_pair(6, COLOR_BLUE, COLOR_WHITE);
+    init_pair(7, COLOR_WHITE, COLOR_RED);
+    init_pair(8, COLOR_BLACK, COLOR_GREEN);
+    init_pair(9, COLOR_BLUE, COLOR_YELLOW);
+    init_pair(10, COLOR_WHITE, COLOR_BLUE);
+    init_pair(11, COLOR_WHITE, COLOR_MAGENTA);
+    init_pair(12, COLOR_BLACK, COLOR_CYAN);

int x = 0, y = 0;

@@ 35,29 36,26 @@ int main(void) {
noecho();
halfdelay(2);

-    for(int i = 0; i < 13; i++) {
+    for (int i = 0; i < 13; i++) {
color_set(i, NULL);

x++;
y++;
-        if(x > COLS - strlen(str)) {
+        if (x > COLS - strlen(str)) {
x = 0;
-        }
-        else if(y > LINES - 2) {
+        } else if (y > LINES - 2) {
y = 0;
}

-
-        if(i == 12)
+        if (i == 12)
i = 0;

refresh();
char ch = getch();
-        if(ch == 'q')
+        if (ch == 'q')
break;
-
}
endwin();
return 0;

```