3 #3
Ссылка в новой задаче
Block a user
Удалить ветку «%!s()»
Удаление ветки необратимо. Несмотря на то, что удаленная ветка может просуществовать некоторое время перед тем, как она будет окончательно удалена, это действие НЕВОЗМОЖНО отменить в большинстве случаев. Продолжить?
#include
#include
#include
#include
#include
using namespace std;
//3.1
struct Student {
char name[17];
uint16_t year;
float average_score;
uint8_t gender : 1;
uint8_t courses : 7;
Student* head_student;
};
void print_hex(const void* data, size_t size) {
const uint8_t* bytes = reinterpret_cast<const uint8_t*>(data);
for (size_t i = 0; i < size; i++) {
cout << hex << uppercase << setw(2) << setfill('0')
<< static_cast(bytes[i]) << " ";
}
cout << dec;
}
void print_binary(const void* data, size_t size) {
const uint8_t* bytes = reinterpret_cast<const uint8_t*>(data);
for (size_t i = 0; i < size; i++) {
for (int j = 7; j >= 0; j--) {
cout << ((bytes[i] >> j) & 1);
}
cout << " ";
}
}
//3.2
int main() {
Student students[3];
//3.3
cout << "Адрес массива: " << &students << endl;
cout << "Размер массива: " << sizeof(students) << " байт" << endl << endl;
//3.4
for (int i = 0; i < 3; i++) {
cout << "Студент " << i << (i == 0 ? " (Староста)" : " ") << endl;
print_hex(&students[i], sizeof(Student));
cout << endl;
cout << " name: ";
print_hex(&students[i].name, sizeof(students[i].name));
cout << endl;
cout << " year: ";
print_hex(&students[i].year, sizeof(students[i].year));
cout << endl;
cout << " average_score: ";
print_hex(&students[i].average_score, sizeof(students[i].average_score));
cout << endl;
}
}