Сравнить коммиты
3 Коммитов
52634d6920
...
8313e24a46
| Автор | SHA1 | Дата | |
|---|---|---|---|
| 8313e24a46 | |||
| f14b6e3fec | |||
| 6212f92b90 |
@@ -39,6 +39,7 @@
|
|||||||
<Unit filename="lab04.h" />
|
<Unit filename="lab04.h" />
|
||||||
<Unit filename="main.cpp" />
|
<Unit filename="main.cpp" />
|
||||||
<Unit filename="source.cpp" />
|
<Unit filename="source.cpp" />
|
||||||
|
<Unit filename="students.cpp" />
|
||||||
<Extensions>
|
<Extensions>
|
||||||
<lib_finder disable_auto="1" />
|
<lib_finder disable_auto="1" />
|
||||||
</Extensions>
|
</Extensions>
|
||||||
|
|||||||
22
lab04.h
22
lab04.h
@@ -1,8 +1,10 @@
|
|||||||
#ifndef LAB04_H_INCLUDED
|
#ifndef LAB04_H_INCLUDED
|
||||||
#define LAB04_H_INCLUDED
|
#define LAB04_H_INCLUDED
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <cstring>
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
void print_in_hex(uint8_t byte);
|
void print_in_hex(uint8_t byte);
|
||||||
@@ -12,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);
|
uint16_t perform_bitwise_operation(uint16_t operand1, char operation, uint16_t operand2);
|
||||||
void print_calculation(uint16_t result);
|
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
|
#endif // LAB04_H_INCLUDED
|
||||||
|
|||||||
83
main.cpp
83
main.cpp
@@ -1,29 +1,65 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <cassert>
|
||||||
#include "lab04.h"
|
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
// Ôóíêöèÿ äëÿ ïðåäñòàâëåíèÿ nibble (4 áèò) â øåñòíàäöàòåðè÷íîé ñèñòåìå
|
||||||
|
char nibble_to_hex(uint8_t i) {
|
||||||
|
// Ìàññèâ öèôð â øåñòíàäöàòåðè÷íîé ñèñòåìå
|
||||||
|
char digits[] = "0123456789abcdef";
|
||||||
|
|
||||||
|
// Ïðîâåðêà íà êîððåêòíîñòü àðãóìåíòà
|
||||||
|
assert(0x0 <= i && i <= 0xf);
|
||||||
|
|
||||||
|
// Âîçâðàùàåì ñèìâîë äëÿ nibble èç ìàññèâà digits
|
||||||
|
return digits[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ôóíêöèÿ äëÿ ïå÷àòè îäíîãî áàéòà â øåñòíàäöàòåðè÷íîé è äâîè÷íîé ôîðìå
|
||||||
|
void print_in_hex(uint8_t byte) {
|
||||||
|
// Ïå÷àòü â øåñòíàäöàòåðè÷íîé ôîðìå
|
||||||
|
cout << "Hex: " << nibble_to_hex(byte >> 4) << nibble_to_hex(byte & 0xf) << endl;
|
||||||
|
|
||||||
|
// Ïå÷àòü â äâîè÷íîé ôîðìå
|
||||||
|
cout << "Binary: ";
|
||||||
|
for (int i = 7; i >= 0; --i) {
|
||||||
|
cout << ((byte >> i) & 1);
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
uint8_t singleByte = 0xAB;
|
// Òåñòèðîâàíèå ôóíêöèè nibble_to_hex
|
||||||
uint8_t byteArray[] = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0 };
|
//for (int i = 0; i <= 0xf; ++i) {
|
||||||
|
//assert(nibble_to_hex(i) == nibble_to_hex(i));
|
||||||
|
//}
|
||||||
|
|
||||||
cout << "Print in Hex:" << endl;
|
assert(nibble_to_hex(0x0) == '0');
|
||||||
print_in_hex(singleByte);
|
assert(nibble_to_hex(0x1) == '1');
|
||||||
|
assert(nibble_to_hex(0x2) == '2');
|
||||||
|
assert(nibble_to_hex(0x3) == '3');
|
||||||
|
assert(nibble_to_hex(0x4) == '4');
|
||||||
|
assert(nibble_to_hex(0x5) == '5');
|
||||||
|
assert(nibble_to_hex(0x6) == '6');
|
||||||
|
assert(nibble_to_hex(0x7) == '7');
|
||||||
|
assert(nibble_to_hex(0x8) == '8');
|
||||||
|
assert(nibble_to_hex(0x9) == '9');
|
||||||
|
assert(nibble_to_hex(0xa) == 'a');
|
||||||
|
assert(nibble_to_hex(0xb) == 'b');
|
||||||
|
assert(nibble_to_hex(0xc) == 'c');
|
||||||
|
assert(nibble_to_hex(0xd) == 'd');
|
||||||
|
assert(nibble_to_hex(0xe) == 'e');
|
||||||
|
assert(nibble_to_hex(0xf) == 'f');
|
||||||
|
|
||||||
cout << endl;
|
// Ïå÷àòü áàéòà â øåñòíàäöàòåðè÷íîé è äâîè÷íîé ôîðìå
|
||||||
print_in_hex(byteArray, sizeof(byteArray));
|
uint8_t test_byte = 0x2f;
|
||||||
|
print_in_hex(test_byte);
|
||||||
cout << "\nPrint in Binary:" << endl;
|
|
||||||
print_in_binary(singleByte);
|
|
||||||
cout << endl;
|
|
||||||
print_in_binary(byteArray, sizeof(byteArray));
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main_calc(){
|
|
||||||
|
int main_calc() {
|
||||||
uint16_t operand1, operand2;
|
uint16_t operand1, operand2;
|
||||||
char operation;
|
char operation;
|
||||||
|
|
||||||
@@ -43,3 +79,20 @@ int main_calc(){
|
|||||||
|
|
||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include "lab04.h"
|
#include "lab04.h"
|
||||||
#include "calc_bits.h"
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user