
- •Курсова робота з дисципліни «Програмування. Частина ііі. Структури даних та алгоритми»
- •Завдання на курсову роботу
- •Теоретична частина
- •1.1 Базові типи даних
- •1.1.1 Логічний тип даних
- •1.1.2 Символьні типи даних
- •1.1.3 Цілочисельні типи даних
- •1.1.4 Дійсні типи даних
- •1.2 Похідні типи даних
- •1.2.1 Тип даних «Рядок»
- •1.2.2 Тип даних «Перерахування» («Перелік»)
- •1.2.3 Тип даних «Масив»
- •1.2.4 Тип даних «Структура»
- •1.2.5 Тип даних «Об’єднання»
- •Система тестів
- •3.1 Базові типи даних
- •3.2 Похідні типи даних
- •3.2.1 Рядок символів
- •3.2.2 Переліки
- •3.2.3 Масив
- •3.2.4 Структура
- •3.2.5 Об’єднання
- •Результати виконання програми
- •Висновки
- •Додатки
-
Додатки
#include <stdio.h>
#include <conio.h>
#include <iostream>
using namespace std;
int main (void)
{
setlocale(0, ""); // Ввід кирилиці
cout << " ЗАВДАННЯ 1:" << endl;
cout << " 1.1 Логiчний тип" << endl;
bool b;
b = 99;
unsigned char *b_1 = (unsigned char *)(&b);
for (int i = 0; i < sizeof(b); i++)
printf("%02X ", b_1[i]);
cout << endl<<endl;
cout << " 1.2 Символьний тип" << endl;
wchar_t ch4;
ch4 = 't';
unsigned char *ch4_1 = (unsigned char *)(&ch4);
for (int i = 0; i < sizeof(ch4); i++)
printf("%02X ", ch4_1[i]);
cout << endl<<endl;
cout << " 1.3 Цiлий тип" << endl;
unsigned i3;
i3 = 4730;
unsigned char *i3_1 = (unsigned char *)(&i3);
for (int i = 0; i < sizeof(i3); i++)
printf("%02X ", i3_1[i]);
cout << endl<<endl;
cout << " 1.4 Дiйсний тип" << endl;
long double d3;
d3=-198.22e9;
unsigned char *d3_1 = (unsigned char *)(&d3);
for (int i = 0; i < sizeof(d3); i++)
printf("%02X ", d3_1[i]);
cout << endl<<endl;
cout << " ЗАВДАННЯ 2:" << endl;
cout << " 2.1 Рядок символiв" << endl;
cout << "33 6E 31 0A 37 61 32 63 38 65 36 6E 34 63 37 23 00" <<endl;
cout << endl<<endl;
cout << " 2.2 Представлення перерахувань" << endl;
enum color10 {
BLUE,
GREEN,
CYAN,
RED,
BROWN,
GRAY = 1,
YELLOW,
WHІTE,
MAGENTA,
LІGHTGRAY,
DARKGRAY = -2,
BLACK
} c1= CYAN,
c2= BROWN,
c3= DARKGRAY;
unsigned char *c1_1 = (unsigned char *)(&c1);
cout << "c1: ";
for (int i = 0; i < sizeof(c1); i++)
printf("%02X ", c1_1[i]);
cout << endl;
unsigned char *c2_1 = (unsigned char *)(&c2);
cout << "c2: ";
for (int i = 0; i < sizeof(c2); i++)
printf("%02X ", c2_1[i]);
cout << endl;
unsigned char *c3_1 = (unsigned char *)(&c3);
cout << "c3: ";
for (int i = 0; i < sizeof(c3); i++)
printf("%02X ", c3_1[i]);
cout << endl<<endl;
cout << " 2.3 Представлення масивiв" << endl;
wchar_t array10[][3][2] = {{1,123}, {23,'4', true}};
array10[0][0][0] = 0;
array10[0][0][1] = 132;
array10[0][1][0] = 66;
array10[0][1][1] = 22;
array10[0][2][0] = 154;
array10[0][2][1] = 44;
array10[1][0][0] = 176;
array10[1][0][1] = 132;
array10[1][1][0] = 88;
array10[1][1][1] = 154;
unsigned char *array10_1 = (unsigned char *)(&array10);
for (int i = 0; i < sizeof(array10); i++)
printf("%02X ", array10_1[i]);
cout << endl<<endl;
cout << " 2.4 Представлення структур" << endl;
struct str6 {
unsigned long e:3;
unsigned long :2;
short :2;
signed short d;
unsigned :7;
double a;
short b:7;
char f;
char c[9];
}str;
str.a = 22.198;
str.b = 5580;
str.c[0] = 'K';
str.c[1] = 'i';
str.c[2] = 'n';
str.c[3] = 'd';
str.c[4] = 'r';
str.d =240660;
str.e =7128;
str.f = 7;
unsigned char *str_1 = (unsigned char *)(&str);
for (int i = 0; i < sizeof(str); i++)
printf("%02X ", str_1[i]);
cout << endl<<endl;
cout << " 2.5 Представлення об'єднань" << endl;
union un4 {
char a[14];
struct {
short d[5];
unsigned b;
float e;
};
int c;
} un;
un.e =44171;
un.c = 118800;
un.a[0] = '2';
un.a[1] = '8';
un.a[2] = '6';
un.a[3] = '4';
un.a[4] = '7';
unsigned char *un_1 = (unsigned char *)(&un);
for (int i = 0; i < sizeof(un); i++)
printf("%02X ", un_1[i]);
cout << endl;
getch();
return 0;
}