-
Notifications
You must be signed in to change notification settings - Fork 0
Lesson 2 #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Lesson 2 #3
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,105 @@ | ||
| /* | ||
| * ����譥� ������� � �ப� 1 | ||
| * ���� "�᭮�� �몠 �++" | ||
| * ���� �����㭥� �.�. | ||
| * �।� ࠧࠡ�⪨ Notepad++ /��������� MinGW/ | ||
| * codepage OEM866 | ||
| * Домашнее задание к уроку 2 | ||
| * курса "Основы языка С++" | ||
| * автор Недокунев А.В. | ||
| * среда разработки Notepad++ /компилятор MinGW/ | ||
| * codepage UTF-8 | ||
| */ | ||
| #include <iostream> | ||
|
|
||
| int main() | ||
| { | ||
| std::cout << "Hello world!" << std::endl; | ||
| //Задание 1 | ||
| //объявляем и сразу инициализируем | ||
| int type_int = 2147483647; //4 байта -2 147 483 648 / 2 147 483 647 | ||
| unsigned int type_uint = 4294967295; //4 байта | ||
| short type_short = 32767; //2 байта -32 768 / 32 767 | ||
| unsigned short type_ushort = 65535; //2 байта | ||
| long type_long = 2147483647; //4 байта | ||
| unsigned long type_ulong = 4294967295; //4 байта | ||
| char type_char = 'a'; //1 байт | ||
| float type_float = 2147483647.0; //4 байта | ||
| double type_double = 9223372036854775807.0; //8 байт | ||
|
|
||
| //объявляем тип данных enum, заодно и Задание 2 выполним | ||
| enum SYMBOL{PLAYER_1_WIN = 'X', PLAYER_2_WIN = 'O', SPACE = ' ', PLAYER_1 = 'x', PLAYER_2 = 'o', HORIZ = '-', VERT = '|', CROSS = '+'};//объявляем тип данных enum | ||
| //хотя enum вообще-то int, для удобочитаемости пишем символы, а не их коды ASCII | ||
| enum SYMBOL p1 = PLAYER_1;//объявляем переменную и сразу инициализируем | ||
| enum SYMBOL p2 = PLAYER_2; | ||
| enum SYMBOL s = SPACE; | ||
| enum SYMBOL p1w = PLAYER_1_WIN; | ||
| enum SYMBOL p2w = PLAYER_2_WIN; | ||
| enum SYMBOL h = HORIZ; | ||
| enum SYMBOL v = VERT; | ||
| enum SYMBOL x = CROSS; | ||
|
|
||
| //объявляем тип данных struct, заодно и Задание 4* выполним | ||
| static const int size_x = 3, size_y = 3; | ||
| struct sGame_field { | ||
| const int in_line = 3;//количество полей для выигрыша | ||
| struct sCell {//структура для клетки поля | ||
| int x_coord, y_coord;//координаты клетки поля | ||
| int mode;//состояние клетки поля, где 0 - пусто, 1 - занято игроком 1, 2 - занято игроком 2 | ||
| } cell_arr[size_x][size_y]; | ||
| } MyField; | ||
| for (int a = 0; a < size_x; a++) {//инициализируем игровое поле | ||
| for (int b = 0; b < size_y; b++) { | ||
| MyField.cell_arr[a][b].x_coord = a; | ||
| MyField.cell_arr[a][b].y_coord = b; | ||
| MyField.cell_arr[a][b].x_coord = 0; | ||
| }; | ||
| }; | ||
|
|
||
| //объявляем тип данных union | ||
| union type_union { | ||
| int i; | ||
| char c; | ||
| float f; | ||
| }; | ||
| union type_union U_1;//объявляем переменную | ||
| U_1.f = 2147483647.0;//инициализируем | ||
|
|
||
| //Задание 3 | ||
| char field[5][5];//создаем массив | ||
| for (int k = 0; k < 5; k++){//инициализируем массив пустым полем для игры крестики-нолики | ||
| for (int m = 0; m < 5; m++){ | ||
| if ((m % 2 == 0) && (k % 2 == 0)){ | ||
| field[k][m] = s; | ||
| } else if ((m % 2 != 0) && (k % 2 != 0)) { | ||
| field[k][m] = x; | ||
| } else if (m % 2 != 0) { | ||
| field[k][m] = v; | ||
| } else if (k % 2 != 0) { | ||
| field[k][m] = h; | ||
| } | ||
| printf("%c", field[k][m]);//просто, чтобы проверить себя | ||
| } | ||
| printf("\n");//наверное, можно было добавить перевод строки в каждый последний элемент строки (тогда размерность станет [5][6] | ||
| } | ||
|
|
||
| //Задание 5* | ||
| struct s_byte {//объявляем тип данных struct, | ||
| union type_union {//объявляем тип данных union | ||
| int i; | ||
| char c; | ||
| float f; | ||
| }; | ||
| int is_int : 1; | ||
| int is_char : 1; | ||
| int is_float : 1; | ||
| }; | ||
|
|
||
|
|
||
| /* | ||
| printf("sizeof int %d, %d\n", sizeof(int), type_int); | ||
| printf("sizeof uint %d, %u\n", sizeof(unsigned int), type_uint); | ||
| printf("sizeof short %d, %hd\n", sizeof(short), type_short); | ||
| printf("sizeof short %d, %hu\n", sizeof(unsigned short), type_ushort); | ||
| printf("sizeof long %d, %ld\n", sizeof(long), type_long); | ||
| printf("sizeof long %d, %lu\n", sizeof(unsigned long), type_ulong); | ||
| printf("sizeof char %d, %c\n", sizeof(char), type_char); | ||
| printf("sizeof float %d, %f\n", sizeof(float), type_float); | ||
| printf("sizeof double %d, %f\n", sizeof(double), type_double); | ||
| */ | ||
| return 0; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 насколько я вижу, это массив из символов и никто не мешает мне положить в него что-то, что не является частью перечисления
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если я правильно понял, надо было:
enum SYMBOL [5][5]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
нет, SYMBOL field_s [5][5]