From f14b6e3fecff3c146bb5a205a73cbd01226ad807 Mon Sep 17 00:00:00 2001 From: rogozinay Date: Sun, 14 Jan 2024 20:51:40 +0300 Subject: [PATCH] Add main_students in projects --- lab04.cbp | 1 + lab04.h | 21 +++++++++++++++++++++ main.cpp | 17 +++++++++++++++++ source.cpp | 1 - 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lab04.cbp b/lab04.cbp index f341753..01a158d 100644 --- a/lab04.cbp +++ b/lab04.cbp @@ -39,6 +39,7 @@ + diff --git a/lab04.h b/lab04.h index da95e11..ae16678 100644 --- a/lab04.h +++ b/lab04.h @@ -4,6 +4,7 @@ #include #include #include +#include #pragma once void print_in_hex(uint8_t byte); @@ -13,4 +14,24 @@ void print_in_binary(const void* data, size_t size); uint16_t perform_bitwise_operation(uint16_t operand1, char operation, uint16_t operand2); void print_calculation(uint16_t result); +// Student +struct Student { + char name[17]; + uint16_t admissionYear; + float averageGrade; + unsigned int gender : 1; + unsigned int completedCourses; + Student* groupLeader; + + // Initialisation + Student(const char* n, uint16_t year, float grade, unsigned int g, unsigned int courses, Student* leader) + : admissionYear(year), averageGrade(grade), gender(g), completedCourses(courses), groupLeader(leader) + { + strncpy(name, n, sizeof(name) - 1); + name[sizeof(name) - 1] = '\0'; + } +}; + +void printStudentDetails(const Student& student); + #endif // LAB04_H_INCLUDED diff --git a/main.cpp b/main.cpp index 34253e3..ae14a56 100644 --- a/main.cpp +++ b/main.cpp @@ -43,3 +43,20 @@ int main_calc(){ return 0; } + + int main_students() { + // Student + Student students[3] = { + Student("Alice", 2019, 4.5, 0, 3, nullptr), + Student("Bob", 2019, 4.2, 1, 2, nullptr), + Student("Charlie", 2019, 4.7, 1, 4, nullptr) // Обратите внимание, что тут нет указателя на groupLeader + }; + + // Details + for (int i = 0; i < 3; ++i) { + std::cout << "\nDetails of Student " << i + 1 << ":" << std::endl; + printStudentDetails(students[i]); + } + + return 0; +} diff --git a/source.cpp b/source.cpp index 3d3f8f3..fad404d 100644 --- a/source.cpp +++ b/source.cpp @@ -1,5 +1,4 @@ #include "lab04.h" -#include "calc_bits.h" #include