Professional Documents
Culture Documents
бд 3
бд 3
Кафедра САПР
ЗВІТ
до лабораторної роботи № 3 з курсу:
“ Організація баз даних і знань ”
Виконав:
студент групи КН-24
Дикий Н. В.
Прийняв:
Головацький Р. І.
ЛЬВІВ 2016
1. ТЕМА
2. МЕТА РОБОТИ
3. ЛАБОРАТОРНЕ ЗАВДАННЯ
4. ТЕОРЕТИЧНІ ВІДОМОСТІ
5. ТЕКСТ ПРОГРАМИ
#include <iostream> char*
#include <fstream> strcpy(config, c = new char;
#include <conio.h> "-");
#include <locale.h> group = 0; f.read(c,
#include <iomanip> subgr = 0; sizeof(char));
}
using namespace std; void Enter() { f.seekg(-1,
cin >> num ios::cur);
struct Index { >> name >> shrt >> mass cout
int min; >> melt >> boil >> val >> << "==========Блок " << +
int pos; config >> group >> subgr; +i << "==========" <<
}; } endl;
void Print(int w) while
Index GetData(fstream { (*c != 0) {
&f);
void WriteData(Index tmp,
fstream &f); if (f.tellg() >=
cout.setf(ios::left); tmp.pos + 500) {
void IndexSort();
cout <<
void
setw(w) << num << setw(w)
RemakePointers(fstream& break;
<< name << setw(w) <<
f);
shrt << setw(w) << mass
<< setw(w) << melt << }
class Element {
setw(w) << boil <<
int num; pos = f.tellg();
setw(w) << val << setw(w)
char name[20];
<< config << setw(w) <<
char shrt[5];
group << setw(w) << subgr Get(f);
double mass;
<< endl;
double melt;
} Print(15);
double boil;
void
int val;
Print_All(fstream& f,
char config[20]; f.seekg(pos + 100,
fstream& in) {
int group; ios::beg);
Index tmp;
int subgr;
int pos;
public: f.read(c,
int i = 0;
Element() { sizeof(char));
f.seekg(0,
num = 19;
ios::beg);
while if (!f.eof()) {
strcpy(name, "-"); (in.tellg() <
FileLength(in)) { f.seekg(-1,
strcpy(shrt, "-"); tmp ios::cur);
mass = 0; = GetData(in);
melt = 0;
boil = 0; }
f.seekg(tmp.pos,
val = 0; ios::beg);
else {
ofstream f <<
*c = 0; e("D:\\Mykola\\ (char)0;
Elem_Index.txt"); }
char* c = int
}
new char; FindOffset(fstream& in,
}
int a; int ck) {
}
cout << Index tmp;
}
"Виберiть варiант:" << Index last;
int GetNum() {
endl; in.seekg(0,
return num;
cout << "1 ios::beg);
}
- Створити пустий файл" tmp =
void Get(fstream&
<< endl; GetData(in);
f) {
cout << "2 if (ck <
f >> num >>
- Заповнити файл даними" tmp.min) return 0;
name >> shrt >> mass >>
<< endl; while
melt >> boil >> val >>
cin >> a; (in.tellg() <
config >> group >> subgr;
switch (a) FileLength(in)) {
}
{ last
int
case 1: = tmp;
FileLength(fstream& f) {
cout tmp =
int off =
<< "Файл створено" << GetData(in);
f.tellg();
endl; if
int len =
((ck < tmp.min) && (ck >=
0;
BlockCreate(f, 0); last.min))
f.seekg(0,
ios::end); e <<
len = 0 << " " << 0 << endl; return last.pos;
f.tellg(); }
break; if (ck >=
case 2: tmp.min) return tmp.pos;
f.seekg(off,
}
ios::beg);
void
return len; d.read(c,
Reorganize(fstream &f,
} sizeof(char));
fstream& in, int off) {
void
cout <<
BlockCreate(fstream& f, while (!d.eof()){ "Reorganizing" << endl;
int pos) {
Element
f.write(c, *arr = new Element[6];
f.seekp(pos, sizeof(char)); Index ob;
ios::beg); int pos =
f.seekp(pos off;
d.read(c,
+ 499, ios::beg); int end =
sizeof(char));
f << FileLength(f);
}
(char)0; arr[0] =
cout
} *this;
<< "Файл створено" <<
void
endl;
BlockCreate(ofstream& f,
f.seekg(pos,
int pos) {
f.close(); ios::beg);
for (int i
f.seekp(pos, = 1; i < 6; i++) {
ios::beg); d.close();
f.seekp(pos
e.close(); Get(f);
+ 499, ios::beg);
f <<
(char)0; arr[i] = *this;
break;
} }
void CreateFile() } ClearEntry(f,
{ void pos);
ofstream ClearEntry(fstream& f,
f("D:\\Mykola\\ int pos) { f.seekg(pos + 100,
Elem_1.txt"); ios::beg);
ifstream pos =
f.seekp(pos,
d("D:\\Mykola\\ ios::beg); f.tellg();
Elem_Original.txt"); }
for (int i
= 0; i < 100; i++)
for (int i Reorganize(f, in, f.read(c,
= 0; i < 5; i++) off); sizeof(char));
for
(int j = 0; j < 5 - i; j+ return; f.seekg(-1,
+) ios::cur);
} while
if (arr[j].num > (*c != 0) {
arr[j + 1].num)
f.read(c,
swap(arr[j], arr[j + 1]); if (f.tellg() >=
sizeof(char));
ob.pos = tmp.pos + 500) {
FileLength(f);
ob.min = if (!f.eof()) {
break;
arr[3].num;
cout << f.seekg(-1,
"Створено новий блок" << ios::cur); }
endl;
} pos = f.tellg();
BlockCreate(f,
end); else *c = 0; Get(f);
in.seekg(0, }
ios::end); cout << if (num == a) {
"After" << endl;
WriteData(ob, in); f << num << cout <<
" " << name << " " << "Запис знайдено:" <<
f.seekg(off, shrt << " " << mass << " endl;
ios::beg); " << melt << " " << boil
for (int i << " " << val << " " <<
b = true;
= 0; i < 3; i++) config << " " << group <<
" " << subgr << endl;
cout << Print(15);
"Entered" << endl;
arr[i].FileWrite(f, in, }
off);
for (int i f.seekp(off,
= 3; i < 6; i++) ios::beg); f.seekg(pos + 100,
f.seekp(off ios::beg);
+ 100, ios::beg);
} f.read(c,
arr[i].FileWrite(f, in,
void sizeof(char));
end);
Search_1(fstream& f,
}
fstream& in) {
void if (!f.eof()) {
int a;
FileWrite(fstream& f,
bool b =
fstream & in, int off) { f.seekg(-1,
false;
Index tmp; ios::cur);
f.seekg(off, int pos;
ios::beg); f.seekg(0, }
char* c = ios::beg);
new char; cout << else {
f.read(c, "Введiть данi:" << endl;
sizeof(char)); cin >> a;
f.seekg(-1, *c = 0;
while
ios::cur); (in.tellg() <
FileLength(in)) { }
while (*c != 0) { tmp }
= GetData(in); }
if (!b)
f.seekp(100, cout << "Запис не
ios::cur); f.seekg(tmp.pos, знайдено" << endl;
ios::beg); }
if void
((int)f.tellp()==(off + char* c = new Search_2(fstream& f,
500)) { char; fstream& in) {
char *s =
new char[20];
bool b =
false; f.seekg(-1, if (strcmp(s,
Index tmp; ios::cur); shrt) == 0) {
int pos;
f.seekg(0,
} cout <<
ios::beg);
"Запис знайдено:" <<
cout <<
else { endl;
"Введiть данi:" << endl;
cin >> s;
while *c = 0; b = true;
(in.tellg() <
FileLength(in)) { } Print(15);
tmp }
= GetData(in); } }
if (!b)
f.seekg(tmp.pos, cout << "Запис не f.seekg(pos + 100,
ios::beg); знайдено" << endl; ios::beg);
}
char* c = new void
f.read(c,
char; Search_3(fstream& f,
sizeof(char));
fstream& in) {
char *s =
f.read(c, if (!f.eof()) {
new char[5];
sizeof(char));
bool b =
false; f.seekg(-1,
f.seekg(-1, Index tmp; ios::cur);
ios::cur); int pos;
f.seekg(0, }
while (*c != 0) { ios::beg);
cout << else {
if (f.tellg() >= "Введiть данi:" << endl;
tmp.pos + 500) { cin >> s;
while *c = 0;
(in.tellg() <
break; }
FileLength(in)) {
tmp }
} = GetData(in); }
if (!b)
pos = f.tellg(); f.seekg(tmp.pos, cout << "Запис не
ios::beg); знайдено" << endl;
Get(f); }
void
char* c = new Search_4(fstream& f,
if (strcmp(s, char;
fstream& in) {
name) == 0) {
double d;
f.read(c, bool b =
cout << sizeof(char)); false;
"Запис знайдено:" << Index tmp;
endl; f.seekg(-1, int pos;
ios::cur); f.seekg(0,
b = true; ios::beg);
while (*c != 0) { cout <<
Print(15); "Введiть данi:" << endl;
cin >> d;
if (f.tellg() >=
while
} tmp.pos + 500) {
(in.tellg() <
FileLength(in)) {
f.seekg(pos + 100, break; tmp =
ios::beg); GetData(in);
}
f.read(c, f.seekg(tmp.pos,
sizeof(char)); pos = f.tellg(); ios::beg);
char*
if (!f.eof()) { Get(f); c = new char;
bool b = f.seekg(-1,
f.read(c, false; ios::cur);
sizeof(char)); Index tmp;
int pos; }
f.seekg(0,
f.seekg(-1,
ios::beg);
ios::cur); else {
cout <<
"Введiть данi:" << endl;
while (*c != 0) { cin >> d; *c = 0;
while
if (f.tellg() >= (in.tellg() < }
tmp.pos + 500) { FileLength(in)) { }
tmp }
break; = GetData(in); if (!b)
cout << "Запис не
f.seekg(tmp.pos, знайдено" << endl;
}
ios::beg); }
void
pos = f.tellg(); Search_6(fstream& f,
char* c = new
fstream& in) {
Get(f); char;
double d;
bool b =
f.read(c, false;
if (mass == d) {
sizeof(char)); Index tmp;
cout << int pos;
f.seekg(-1, f.seekg(0,
"Запис знайдено:" <<
endl; ios::cur); ios::beg);
cout <<
while (*c != 0) { "Введiть данi:" << endl;
b = true; cin >> d;
while
Print(15); if (f.tellg() >=
(in.tellg() <
tmp.pos + 500) {
FileLength(in)) {
} tmp =
break; GetData(in);
f.seekg(pos + 100,
} f.seekg(tmp.pos,
ios::beg);
ios::beg);
f.read(c, pos = f.tellg(); char*
sizeof(char)); c = new char;
Get(f);
if (!f.eof()) { f.read(c,
if (melt == d) { sizeof(char));
f.seekg(-1,
ios::cur); cout << f.seekg(-1,
"Запис знайдено:" << ios::cur);
endl; while
} (*c != 0) {
else { b = true;
if (f.tellg() >=
Print(15); tmp.pos + 500) {
*c = 0;
break;
} }
} }
} f.seekg(pos + 100,
if (!b) ios::beg);
cout << "Запис не pos = f.tellg();
знайдено" << endl; f.read(c,
} sizeof(char)); Get(f);
void
Search_5(fstream& f, if (!f.eof()) { if (boil == d) {
fstream& in) {
double d; cout <<
"Запис знайдено:" << f.seekg(-1, int pos;
endl; ios::cur); f.seekg(0,
ios::beg);
b = true; while (*c != 0) { cout <<
"Введiть данi:" << endl;
cin >> s;
Print(15); if (f.tellg() >=
while
tmp.pos + 500) {
(in.tellg() <
} FileLength(in)) {
break; tmp =
f.seekg(pos + 100, GetData(in);
ios::beg); }
f.seekg(tmp.pos,
f.read(c, pos = f.tellg(); ios::beg);
sizeof(char)); char*
Get(f); c = new char;
if (!f.eof()) {
if (val == a) { f.read(c,
f.seekg(-1, sizeof(char));
ios::cur); cout <<
"Запис знайдено:" << f.seekg(-1,
} endl; ios::cur);
while
(*c != 0) {
else { b = true;
Результат виконання:
6. ВИСНОВОК