Другие языки программирования и технологии

Хочу оригинально поздравить парня с днем рождения, парень программист. Помогите написать интересный код, желательно на С++

Уже что-то примерное спрашивали и я написала следующий код.. только не поздравить, а послать )) Что вам надо изменить, дак это размер массива и заменить числа из ASCII таблицы (привет гугл) на нужную последовательность букв, которые вы хотели бы ему написать (каждое число, к примеру 70 это буква из алфавита, в данном случае это большая F).

#include < iostream > //и тут убрать в ковычках пробелы.

using namespace std;

int main(){
int arr[8] = { 70, 85, 67, 75, 32, 89, 79, 85 };
for (auto u : arr)
cout << (char)u;
system("pause");
return 0;
}

А я спать хочу, это нудно)) Если надо будет очень, могу завтра, то есть сегодня вечером изменить.
Лев Супер
Лев Супер
3 431
Лучший ответ
можно слишком хардово сделать, создать папку с паролем, пароль спрятать в интернете, но чтобы он нашел спустя некоторые минуты раздумий, а папке — видео поздравление.

Ну и типа написать, «ой Петя, Вася, Ашот, (нужное подчеркнуть), что-то я не могу открыть эту папку, найди пароль, бла-бла, мяу...»

А простой код будет скучен.
Я так понимаю что код должен быть достаточно прост в обращении и приминении для неопытного кодера. Думаю писать GUI не вариант, если остановиться на консоли то думаю можно просто раскрасить буквы разными цветами. Для этого нужно в скелет консольной программы добавить дополнительную API:

#define STDOUT GetStdHandle(STD_OUTPUT_HANDLE)
#define STDIN GetStdHandle(STD_INPUT_HANDLE)
DWORD WINAPI ConsolePrint(LPCSTR,...);

// Prints a line in to attached console window
DWORD WINAPI ConsolePrint(LPCSTR lpText, ..) {
char lpBuffer[1024];
DWORD dNumWrt = 0;
va_list vargs;
va_start(vargs, lpText);
wvsprintfA(lpBuffer, lpText, vargs);
va_end(vargs);
strcat(lpBuffer, "\r\n");
int i = -1; // Read Position
while (true) {
i++; // in any case
if ( (*(lpBuffer+i)) == '\0' ) { SetConsoleTextAttribute(STDOUT, 7); break; } // We break as we hit NULL terminator
if ( (*(lpBuffer+i)) == '#' && (*(lpBuffer+i+3)) == '^') { // We hit control sequence
// We will process it before writing and move i forward
i++; // pass by # mark
unsigned short int BackgroundColor = 0;
unsigned short int ForegroundColor = 0;
char HexValue[2]; // We need to pass NULL terminated string to strcmp
(*(HexValue+1)) = 0; // So we terminate it ONCE, we wont modify this byte any more!
// First goes Background Color
(*(HexValue)) = (*(lpBuffer+i));
if (!strcmp(HexValue, "F")) { BackgroundColor = 15; }
else if (!stricmp(HexValue, "E")) { BackgroundColor = 14; }
else if (!stricmp(HexValue, "D")) { BackgroundColor = 13; }
else if (!stricmp(HexValue, "C")) { BackgroundColor = 12; }
else if (!stricmp(HexValue, "B")) { BackgroundColor = 11; }
else if (!stricmp(HexValue, "A")) { BackgroundColor = 10; }
else { BackgroundColor = atoi(HexValue); }
// Background Done, move read position forward one byte
i++;
// Now Foreground Color
(*(HexValue)) = (*(lpBuffer+i));
if (!stricmp(HexValue, "F")) { ForegroundColor = 15; }
else if (!stricmp(HexValue, "E")) { ForegroundColor = 14; }
else if (!stricmp(HexValue, "D")) { ForegroundColor = 13; }
else if (!stricmp(HexValue, "C")) { ForegroundColor = 12; }
else if (!stricmp(HexValue, "B")) { ForegroundColor = 11; }
else if (!stricmp(HexValue, "A")) { ForegroundColor = 10; }
else { ForegroundColor = atoi(HexValue); }
// Foreground Done, move read position forward by two bytes (pass by ^ simbol)
i+=1;

WORD TextAttributes = 0;
// We handle them in reverse order
if (BackgroundColor >= 8) { TextAttributes += BACKGROUND_INTENSITY; BackgroundColor -= 8; }
if (BackgroundColor >= 4) { TextAttributes += BACKGROUND_BLUE; BackgroundColor -= 4; }
if (BackgroundColor >= 2) { TextAttributes += BACKGROUND_GREEN; BackgroundColor -= 2; }
if (BackgroundColor >= 1) { TextAttributes += BACKGROUND_RED; BackgroundColor -= 1; }
// BackgroundColor is now 0, we handled all
if (ForegroundColor >= 8) { TextAttributes += FOREGROUND_INTENSITY; ForegroundColor -= 8; }
if (ForegroundColor >= 4) { TextAttributes += FOREGROUND_BLUE; ForegroundColor -= 4; }
if (ForegroundColor >= 2) { TextAttributes += FOREGROUND_GREEN; ForegroundColor -= 2; }
if (ForegroundColor >= 1) { TextAttributes += FOREGROUND_RED; ForegroundColor -= 1; }
SetConsoleTextAttribute(STDOUT, TextAttributes);
continue;
}
WriteConsoleA(STDOUT, (lpBuffer+i), 1, &dNumWrt, NULL);
continue;
}
return dNumWrt;
}

ConsolePrint("#1F^Этот текст будет напечатан синим на белом фоне");
ConsolePrint("#4A^Этот текст будет напечатан красным на зелёном фоне");