Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Kursovaya Ostroverhov.docx
Скачиваний:
4
Добавлен:
18.09.2019
Размер:
6.22 Mб
Скачать

Код файла Сlass2.Cpp

#include "stdafx.h"

#include "Class2.h";

#include <iostream>

void Class2::Add(exWork * data){

if(!this -> first) this -> first = data;

else{

this -> current = this -> first;

while(this -> current -> next) this -> current = this -> current -> next ;

this -> current -> next = data;

}

data = NULL;

delete data;

};

void Class2::Show(){

if(!this -> first) std::cout << "List 2 is empty\n";

else{

this -> current = this -> first;

std::cout << "List2:\n";

do{

std:: cout << "exId = " << this -> current -> exId << ", comment = " << this -> current -> comment << ", id = " << this -> current -> id << "\n";

this -> current = this -> current -> next;

} while(this -> current);

}

};

bool Class2::Remove(int id){

if(!this -> first) return false;

else if(this -> first -> id == id){

this -> current = this -> first;

this -> first = this -> first -> next;

delete this -> current;

return true;

}else{

this -> current = this -> first;

while(this -> current -> next){

if(this -> current -> next -> id == id){

exWork * temp = this -> current -> next;

this -> current -> next = this -> current -> next -> next;

delete temp;

return true;

}

this -> current = this -> current -> next;

}

}

return false;

};

void Class2::exList(int id){

std::cout << "Excursion list:\n";

this -> current = this -> first;

while(this -> current){

if(this -> current -> id == id) std:: cout << "exId = " << this -> current -> exId << ", comment = " << this -> current -> comment << ", id = " << this -> current -> id;

this -> current = this -> current -> next;

}

std::cout << std::endl;

}

void Class2::FileSave(){

FILE *f = fopen("class2.txt", "w");

this -> current = this -> first;

while(this -> current){

fprintf(f, "exId = %d, comment = %s, id = %d\n", this -> current -> exId, this -> current -> comment, this -> current -> id);

this -> current = this -> current -> next;

}

fclose(f);

}

void Class2::FileLoad(){

FILE *f = fopen("class2.txt", "r");

char * s = new char[201];

this -> current = this -> first;

if(this -> current) while(this -> current -> next) this -> current = this -> current -> next;

while(fgets(s,150,f) != NULL ){

exWork * temp = new exWork;

temp -> next = NULL;

s = strtok(s," ,=");

s = strtok(0," ,=");

temp -> exId = atoi(s);

s = strtok(0," ,=");

s = strtok(0," ,=");

temp -> comment = s;

s = strtok(0," ,=");

s = strtok(0," ,=");

temp -> id = atoi(s);

if(!this -> first){

this -> first = temp;

temp = NULL;

delete temp;

this -> current = this -> first;

}else{

this -> current -> next = temp;

temp = NULL;

delete temp;

this -> current = this -> current -> next;

}

}

fclose(f);

}

char * Class2::Return(int exId){

this -> current = this -> first;

while(this -> current){

if(this -> current -> exId == exId) return this -> current -> comment;

this -> current = this -> current -> next;

}

return "Not in database";

};

Код файла Сlass3.h

#ifndef Class1.h

#include "Class1.h"

#endif

#ifndef Class2.h

#include "Class2.h"

#endif

struct turList{

int id;

char * fio;

int passN;

int * Id;

char * hotel;

char * date;

int nDays;

turList *next;

};

class Class3{

public:

Class3(): first(0), current(0) {};

void FileSave();

void FileLoad();

void Add(turList *);

bool Remove(int);

void Show();

void info(int, Class1 &, Class2 &);

private:

turList *first;

turList *current;

};

Код файла Сlass3.cpp

#include "stdafx.h"

#include "Class3.h"

#include <iostream>

void Class3::Add(turList * data){

if(!this -> first) this -> first = data;

else{

this -> current = this -> first;

while(this -> current -> next) this -> current = this -> current -> next ;

this -> current -> next = data;

}

data = NULL;

delete data;

};

void Class3::Show(){

if(!this -> first) std::cout << "List 3 is empty\n";

else{

this -> current = this -> first;

std::cout << "List3:\n";

do{

std:: cout << "FIO = " << this -> current -> fio << ", pass number = " << this -> current -> passN << ", id = " << this -> current -> id << ", IDs: ";

for(int* i = this -> current -> Id; i[0]; i++) std::cout << i[0] << ", ";

std:: cout << "hotel = " << this -> current -> hotel << ", date = " << this -> current -> date << ", number of days = " << this -> current -> nDays << "\n";

this -> current = this -> current -> next;

} while(this -> current);

}

};

bool Class3::Remove(int id){

if(!this -> first) return false;

else if(this -> first -> id == id){

this -> current = this -> first;

this -> first = this -> first -> next;

delete this -> current;

return true;

}else{

this -> current = this -> first;

while(this -> current -> next){

if(this -> current -> next -> id == id){

turList * temp = this -> current -> next;

this -> current -> next = this -> current -> next -> next;

delete temp;

return true;

}

this -> current = this -> current -> next;

}

}

return false;

};

void Class3::FileSave(){

FILE *f = fopen("class3.txt", "w");

this -> current = this -> first;

while(this -> current){

fprintf(f, "FIO =%s, pass_number = %d, id = %d, IDs: ", this -> current -> fio, this -> current -> passN, this -> current -> id);

for(int* i = this -> current -> Id; i[0]; i++) fprintf(f ,"%d, ",i[0]);

fprintf(f, "hotel = %s, date = %s, number_of_days = %d\n", this -> current -> hotel, this -> current -> date, this -> current -> nDays);

this -> current = this -> current -> next;

}

fclose(f);

}

void Class3::FileLoad(){

FILE *f = fopen("class3.txt", "r");

char * s = new char[255];

this -> current = this -> first;

if(this -> current) while(this -> current -> next) this -> current = this -> current -> next;

while(fgets(s,254,f) != NULL ){

turList * temp = new turList;

temp -> next = NULL;

s = strtok(s," ,=:");

s = strtok(0,",=:");

temp -> fio = s;

s = strtok(0," ,=:");

s = strtok(0," ,=:");

temp -> passN = atoi(s);

s = strtok(0," ,=:");

s = strtok(0," ,=:");

temp -> id = atoi(s);

s = strtok(0," ,=:");

s = strtok(0," ,=:");

int * i = new int[10];

int j(0);

for(;strcmp(s,"hotel") != 0;j++){

i[j] = atoi(s);

s = strtok(0," ,=:");

}

i[j] = NULL;

temp -> Id = new int[j-1];

for(int k = 0; k <= j; k++) temp -> Id[k] = i[k];

delete[] i;

s = strtok(0," ,=:");

temp -> hotel = s;

s = strtok(0," ,=:");

s = strtok(0," ,=:");

temp -> date = s;

s = strtok(0," ,=:");

s = strtok(0," ,=:");

temp -> nDays = atoi(s);

if(!this -> first){

this -> first = temp;

temp = NULL;

delete temp;

this -> current = this -> first;

}else{

this -> current -> next = temp;

temp = NULL;

delete temp;

this -> current = this -> current -> next;

}

}

fclose(f);

}

void Class3::info(int passN, Class1 & cl1, Class2 & cl2){

std::cout << "Information about pass number " << passN << ":\n";

this -> current = this -> first;

while(this -> current){

if(this -> current -> passN == passN){

std::cout << "FIO = " << this -> current -> fio << ", destination = " << cl1.Return(this -> current -> id) << ", excursion name: ";

for(int* i = this -> current -> Id; i[0]; i++) std::cout << cl2.Return(i[0]) << ", ";

std::cout << "hotel = " << this -> current -> hotel << ", departure date = " << this -> current -> date << ", arrival date = ";

char * s = new char;

strcpy(s,this -> current -> date);

s = strtok(s,".");

int d,m,y,count(0);

d = atoi(s);

s = strtok(0,".");

m = atoi(s);

s = strtok(0,".");

y = atoi(s);

s = NULL;

delete s;

d += this -> current -> nDays;

if( m == 2 || m == 6 || m == 7 ) d+= (m - 1) * 30 + 1;

else if( m == 1 || m == 4 || m == 5 ) d+= (m - 1) * 30;

else if( m == 8 ) d+= 212;

else if( m == 9 || m == 10 ) d+= (m - 1) * 30 + 3;

else if( m == 11 || m == 12 ) d+= (m - 1) * 30 + 4;

if( ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) && m > 2 ) d++;

while( d > 365 ){

d-= 365;

count++;

}

y+= count;

count -= y % 4;

if( count > 0 ){

d-= count / 4;

}

if( d < 0 ){

y--;

d+= 365;

if( ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) && m > 2) d++;

}

m = 1;

if( d > 31 ){

m++;

d-= 31;

count = 0;

if( ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) ) count++;

if( d > 28 + count ){

m++;

d-= (28 + count);

if( d > 31 ){

m++;

d-= 31;

if( d > 30 ){

m++;

d-= 30;

if( d > 31){

m++;

d-= 31;

if( d > 30 ){

m++;

d-= 30;

if( d > 31 ){

m++;

d-= 31;

if( d > 31 ){

m++;

d-= 31;

if( d > 30 ){

m++;

d-= 30;

if( d > 31 ){

m++;

d-= 31;

if( d > 30 ){

m++;

d-= 30;

}

}

}

}

}

}

}

}

}

}

}

std::cout << d << "." << m << "." << y;

return;

}

this -> current = this -> current -> next;

}

std::cout << "Not in database.\n";

}

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]