Додана лабораторна робота № 11
This commit is contained in:
parent
57af7f9747
commit
f9f0a2e364
10 changed files with 309 additions and 0 deletions
14
lab11/README.md
Normal file
14
lab11/README.md
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
# Лабораторна робота № 11
|
||||||
|
|
||||||
|
Тема Реалізація програмних засобів оброблення динамічних структур даних та бінарних файлів
|
||||||
|
|
||||||
|
Мета роботи полягає у набутті ґрунтовних вмінь і практичних навичок командної (колективної) реалізації програмного забезпечення, розроблення функцій оброблення динамічних структур даних, використання стандартних засобів C++ для керування динамічною пам'яттю та бінарними файловими потоками.
|
||||||
|
|
||||||
|
Завдання
|
||||||
|
1. У складі команди IT-проекта розробити програмні модулі оброблення динамічної структури даних.
|
||||||
|
2. Реалізувати програмний засіб на основі розроблених командою IT-проекта модулів.
|
||||||
|
|
||||||
|
Варіант № 1
|
||||||
|
|
||||||
|
|
||||||
|
Кропивницький | <a href="http://www.kntu.kr.ua/">ЦНТУ</a> | 2023
|
BIN
lab11/Report/Report.pdf
Executable file
BIN
lab11/Report/Report.pdf
Executable file
Binary file not shown.
BIN
lab11/TestSuite/TestSuite.doc
Executable file
BIN
lab11/TestSuite/TestSuite.doc
Executable file
Binary file not shown.
14
lab11/prj/ModulesMykhailenko.h
Executable file
14
lab11/prj/ModulesMykhailenko.h
Executable file
|
@ -0,0 +1,14 @@
|
||||||
|
#include <vector>
|
||||||
|
#include "struct_type_project_1.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void add(vector<Product>&, wstring, wstring, wstring, wstring);
|
||||||
|
|
||||||
|
void remove(vector<Product>&, wstring);
|
||||||
|
|
||||||
|
bool read(vector<Product>&, string);
|
||||||
|
|
||||||
|
bool save(vector<Product>&, string);
|
||||||
|
|
||||||
|
void search(vector<Product>&, wstring);
|
41
lab11/prj/ModulesMykhailenko/ModulesMykhailenko.cbp
Executable file
41
lab11/prj/ModulesMykhailenko/ModulesMykhailenko.cbp
Executable file
|
@ -0,0 +1,41 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_project_file>
|
||||||
|
<FileVersion major="1" minor="6" />
|
||||||
|
<Project>
|
||||||
|
<Option title="ModulesMykhailenko" />
|
||||||
|
<Option pch_mode="2" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Build>
|
||||||
|
<Target title="Debug">
|
||||||
|
<Option output="bin/Debug/ModulesMykhailenko" prefix_auto="1" extension_auto="1" />
|
||||||
|
<Option working_dir="" />
|
||||||
|
<Option object_output="obj/Debug/" />
|
||||||
|
<Option type="2" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Option createDefFile="1" />
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-Wall" />
|
||||||
|
<Add option="-g" />
|
||||||
|
</Compiler>
|
||||||
|
</Target>
|
||||||
|
<Target title="Release">
|
||||||
|
<Option output="bin/Release/ModulesMykhailenko" prefix_auto="1" extension_auto="1" />
|
||||||
|
<Option working_dir="" />
|
||||||
|
<Option object_output="obj/Release/" />
|
||||||
|
<Option type="2" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Option createDefFile="1" />
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-Wall" />
|
||||||
|
<Add option="-O2" />
|
||||||
|
</Compiler>
|
||||||
|
<Linker>
|
||||||
|
<Add option="-s" />
|
||||||
|
</Linker>
|
||||||
|
</Target>
|
||||||
|
</Build>
|
||||||
|
<Unit filename="ModulesMykhailenko.cpp" />
|
||||||
|
<Unit filename="struct_type_project_1.cpp" />
|
||||||
|
<Extensions />
|
||||||
|
</Project>
|
||||||
|
</CodeBlocks_project_file>
|
98
lab11/prj/ModulesMykhailenko/ModulesMykhailenko.cpp
Executable file
98
lab11/prj/ModulesMykhailenko/ModulesMykhailenko.cpp
Executable file
|
@ -0,0 +1,98 @@
|
||||||
|
#include <codecvt>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <locale>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include "ModulesMykhailenko.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
vector<Product> products;
|
||||||
|
|
||||||
|
void add(vector<Product> &vec, wstring section, wstring sectionName, wstring code, wstring name) {
|
||||||
|
vec.push_back({});
|
||||||
|
Product& back = vec.back();
|
||||||
|
back.section = section;
|
||||||
|
back.sectionName = sectionName;
|
||||||
|
back.code = code;
|
||||||
|
back.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void remove(vector<Product> &vec, wstring record) {
|
||||||
|
bool found = false;
|
||||||
|
for (vector<Product>::iterator it = vec.begin(); it != vec.end();) {
|
||||||
|
if (it->code == record) {
|
||||||
|
found = true;
|
||||||
|
it = vec.erase(it);
|
||||||
|
} else
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found)
|
||||||
|
wcout << L"Видалено." << endl;
|
||||||
|
else
|
||||||
|
wcout << L"Не знайдено." << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool read(vector<Product> &vec, string file) {
|
||||||
|
vector<vector<wstring>> content;
|
||||||
|
vector<wstring> row;
|
||||||
|
wstring line, word;
|
||||||
|
|
||||||
|
wifstream data;
|
||||||
|
data.open(file);
|
||||||
|
|
||||||
|
data.imbue(locale(locale(), new codecvt_utf8<wchar_t>));
|
||||||
|
|
||||||
|
if (data.is_open()) {
|
||||||
|
while(getline(data, line)) {
|
||||||
|
row.clear();
|
||||||
|
|
||||||
|
wstringstream str(line);
|
||||||
|
|
||||||
|
while(getline(str, word, L'\u0009'))
|
||||||
|
row.push_back(word);
|
||||||
|
content.push_back(row);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < content.size(); i++) {
|
||||||
|
vec.push_back({});
|
||||||
|
Product& back = vec.back();
|
||||||
|
back.section = content[i][0];
|
||||||
|
back.sectionName = content[i][1];
|
||||||
|
back.code = content[i][2];
|
||||||
|
back.name = content[i][3];
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool save(vector<Product> &vec, string file) {
|
||||||
|
wofstream data;
|
||||||
|
data.open(file);
|
||||||
|
|
||||||
|
data.imbue(locale(locale(), new codecvt_utf8<wchar_t>));
|
||||||
|
|
||||||
|
if (!data)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < vec.size(); i++)
|
||||||
|
data << vec[i].section << L'\u0009' << vec[i].sectionName << L'\u0009' << vec[i].code << L'\u0009' << vec[i].name << endl;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void search(vector<Product> &vec, wstring record) {
|
||||||
|
bool found = false;
|
||||||
|
for (unsigned int i = 0; i < vec.size(); i++) {
|
||||||
|
if (vec[i].code == record) {
|
||||||
|
found = true;
|
||||||
|
wcout << vec[i].code << L": " << vec[i].name << L", належить до розділу " << vec[i].section << L" (" << vec[i].sectionName << L")" << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found)
|
||||||
|
wcout << L"Не знайдено." << endl;
|
||||||
|
}
|
84
lab11/prj/prj_1_Mykhailenko/main.cpp
Executable file
84
lab11/prj/prj_1_Mykhailenko/main.cpp
Executable file
|
@ -0,0 +1,84 @@
|
||||||
|
#include <clocale>
|
||||||
|
#include <codecvt>
|
||||||
|
#include <locale>
|
||||||
|
#include <iostream>
|
||||||
|
#include "ModulesMykhailenko.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
ios_base::sync_with_stdio(false);
|
||||||
|
wcout.imbue(locale(locale(), new codecvt_utf8<wchar_t>));
|
||||||
|
wcin.imbue(locale(locale(), new codecvt_utf8<wchar_t>));
|
||||||
|
setlocale(LC_ALL, "");
|
||||||
|
|
||||||
|
read(products, "data.tsv");
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
int choice;
|
||||||
|
|
||||||
|
wcout << L"Довідник кодів товарів згідно з УКТЗЕД" << endl <<
|
||||||
|
L"1. Пошук запису" << endl <<
|
||||||
|
L"2. Зберігання довідника у заданий файл" << endl <<
|
||||||
|
L"3. Додавання нового запису у довідник" << endl <<
|
||||||
|
L"4. Вилучення запису із довідника" << endl <<
|
||||||
|
L"5. Завершення роботи програми і запис даних" << endl <<
|
||||||
|
L"Введіть необхідну дію: ";
|
||||||
|
|
||||||
|
wcin >> choice;
|
||||||
|
wcin.ignore();
|
||||||
|
switch (choice) {
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
wstring record;
|
||||||
|
wcout << L"Введіть номер запису: ";
|
||||||
|
getline(wcin, record);
|
||||||
|
search(products, record);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
wstring path;
|
||||||
|
wcout << L"Введіть шлях до файла: ";
|
||||||
|
getline(wcin, path);
|
||||||
|
wstring_convert<codecvt_utf8<wchar_t>, wchar_t> converter;
|
||||||
|
string converted_path = converter.to_bytes(path);
|
||||||
|
save(products, converted_path);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
wstring section;
|
||||||
|
wstring sectionName;
|
||||||
|
wstring code;
|
||||||
|
wstring name;
|
||||||
|
wcout << L"Введіть код розділу: ";
|
||||||
|
getline(wcin, section);
|
||||||
|
wcout << L"Введіть назву розділу: ";
|
||||||
|
getline(wcin, sectionName);
|
||||||
|
wcout << L"Введіть код товару: ";
|
||||||
|
getline(wcin, code);
|
||||||
|
wcout << L"Введіть назву товару: ";
|
||||||
|
getline(wcin, name);
|
||||||
|
add(products, section, sectionName, code, name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 4:
|
||||||
|
{
|
||||||
|
wstring record;
|
||||||
|
wcout << L"Введіть номер запису: ";
|
||||||
|
getline(wcin, record);
|
||||||
|
remove(products, record);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 5:
|
||||||
|
{
|
||||||
|
save(products, "data.tsv");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
wcout << L"Помилкові дані." << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
40
lab11/prj/prj_1_Mykhailenko/prj_1_Mykhailenko.cbp
Executable file
40
lab11/prj/prj_1_Mykhailenko/prj_1_Mykhailenko.cbp
Executable file
|
@ -0,0 +1,40 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_project_file>
|
||||||
|
<FileVersion major="1" minor="6" />
|
||||||
|
<Project>
|
||||||
|
<Option title="prj_1_Mykhailenko" />
|
||||||
|
<Option pch_mode="2" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Build>
|
||||||
|
<Target title="Debug">
|
||||||
|
<Option output="bin/Debug/prj_1_Mykhailenko" prefix_auto="1" extension_auto="1" />
|
||||||
|
<Option object_output="obj/Debug/" />
|
||||||
|
<Option type="1" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-g" />
|
||||||
|
</Compiler>
|
||||||
|
</Target>
|
||||||
|
<Target title="Release">
|
||||||
|
<Option output="bin/Release/prj_1_Mykhailenko" prefix_auto="1" extension_auto="1" />
|
||||||
|
<Option object_output="obj/Release/" />
|
||||||
|
<Option type="1" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-O2" />
|
||||||
|
</Compiler>
|
||||||
|
<Linker>
|
||||||
|
<Add option="-s" />
|
||||||
|
</Linker>
|
||||||
|
</Target>
|
||||||
|
</Build>
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-Wall" />
|
||||||
|
<Add option="-fexceptions" />
|
||||||
|
</Compiler>
|
||||||
|
<Unit filename="main.cpp" />
|
||||||
|
<Extensions>
|
||||||
|
<lib_finder disable_auto="1" />
|
||||||
|
</Extensions>
|
||||||
|
</Project>
|
||||||
|
</CodeBlocks_project_file>
|
18
lab11/prj/struct_type_project_1.h
Executable file
18
lab11/prj/struct_type_project_1.h
Executable file
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef STRUCT_TYPE_PROJECT_1_H_INCLUDED
|
||||||
|
#define STRUCT_TYPE_PROJECT_1_H_INCLUDED
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
struct Product {
|
||||||
|
wstring section;
|
||||||
|
wstring sectionName;
|
||||||
|
wstring code;
|
||||||
|
wstring name;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern vector<Product> products;
|
||||||
|
|
||||||
|
#endif // STRUCT_TYPE_PROJECT_1_H_INCLUDED
|
BIN
lab11/tasks/L11-var--001.jpg
Executable file
BIN
lab11/tasks/L11-var--001.jpg
Executable file
Binary file not shown.
After Width: | Height: | Size: 261 KiB |
Reference in a new issue