Требования: Разработать многомодульную программу, которая демонстрирует выполнение всех операций, определенных вариантом, над линейным однонаправленным динамическим списком. Требования к разработке. 1. Разработать структуру узла списка, структура информационной части узла определена вариантом. Определение структуры узла списка выполните через спецификацию typedef в отдельном заголовочном файле. 2. Разработайте операции над линейным списком, определенные вашим вариантом, а также операции: • создание списка из n узлов • вывод списка • поиск узла с заданным значением (операция должна возвращать указатель на заданный узел). 3. Оформите операции в виде функций и включите в отдельный файл с расширением cpp. Подключите к этому файлу заголовочный файл с определением структуры узла. 4. Разработайте программу согласно заданию. Задания Дан:Номер абонемента, Название книги, дата выдачи, дата возврата, дата фактического возврата.Необходимо: Вставить новый узел в список после последнего узла с таким же номером абонента(дата фактического возврата еще не заполнена). Изменить значение поля фактической даты возврата по указанной книге, указанного абонемента. Удалить узлы, в которых дата возврата и дата фактического возврата совпадают. Определить количество книг, заданного абонемента.| Код | #include "stdafx.h" #include <iostream> #include <list> #include <algorithm> #include <conio.h> using namespace std;
typedef struct Date { int day; int month; int year; }DATE;
typedef struct LibraryStudentData { int id; //читай номер абонемента char name[256]; //название книг int books; //количество кни DATE ofIssue; //дата выдачи DATE ofReturns; //дата возврата DATE ofFactReturns; //дата фактического возврата }LSD;
int sizeofLSD() { int n=0; while(n<=0) { cout << "Input number of nodes in list: "; cin>>n; } return n; }
int booksofLSD() { int n=0; while(n<=0) cin>>n; return n; }
bool isID(LSD first, int second) { if( first.id==second ) return true; else return false; }
bool isDD(DATE first, DATE second) { if( first.day==second.day && first.month==second.month && first.year==second.year ) return true; else return false; }
bool nameLSD(char f[256], char s[256]) { int count=0; for(int i=0;i<256; i++) if(f[i]==s[i]) count++; if(count==256) return true; else return false; }
//создание списка из n узлов void createLSD(list<LSD> &theListLSD, int theSize) { while(theSize) { LSD theLSD; cout << "Input the id of abonement: "; cin>>theLSD.id; cout << "Input abonements's number of books: "; theLSD.books = booksofLSD(); int theBooks = theLSD.books; while(theBooks) { cout << "Input the name of book: "; cin>>theLSD.name; cout << "Input the date of issue(day/month/year): "; cin>>theLSD.ofIssue.day>>theLSD.ofIssue.month>>theLSD.ofIssue.year; cout << "Input the date of return: "; cin>>theLSD.ofReturns.day>>theLSD.ofReturns.month>>theLSD.ofReturns.year; cout << "Input the date of fact return: "; cin>>theLSD.ofFactReturns.day>>theLSD.ofFactReturns.month>>theLSD.ofFactReturns.year; theBooks--; } theListLSD.push_back(theLSD); theSize--; } }
//вывод списка void printLSD(list<LSD> theListLSD) { for(list<LSD>::iterator i = theListLSD.begin(); i!=theListLSD.end(); i++) { LSD theLSD = *i; cout<<"ID of abonent: " << theLSD.id << endl; cout<<"Book's name: " << theLSD.name << endl; cout<<"Date of issue: "<<theLSD.ofIssue.day<<" "<<theLSD.ofIssue.month<<" "<<theLSD.ofIssue.year<<endl; cout<<"Date of return: "<<theLSD.ofReturns.day<<" "<<theLSD.ofReturns.month<<" "<<theLSD.ofReturns.year<<endl; if(theLSD.ofFactReturns.day==0 && theLSD.ofFactReturns.month==0 && theLSD.ofFactReturns.year==0) cout<<"Date of fact return: Date is out"<<endl; else cout<<"Date of fact return: "<<theLSD.ofFactReturns.day<<" "<<theLSD.ofFactReturns.month<<" "<<theLSD.ofFactReturns.year<<endl; cout << endl; } }
//Вставить новый узел в список после последнего узла с таким же номером абонента.(дата возврата еще не указана.) void insertNodeAfter(list<LSD> &theListLSD) { for(list<LSD>::iterator i=theListLSD.begin(); i!=theListLSD.end(); i++) { LSD temp = *i; if(temp.ofFactReturns.day==0 && temp.ofFactReturns.month==0 && temp.ofFactReturns.year==0) { LSD theLSD; cout << "Input the id of abonement: "; cin>>theLSD.id; cout << "Input abonements's number of books: "; theLSD.books = booksofLSD(); int theBooks = theLSD.books; while(theBooks) { cout << "Input the name of book: "; cin>>theLSD.name; cout << "Input the date of issue(day/month/year): "; cin>>theLSD.ofIssue.day>>theLSD.ofIssue.month>>theLSD.ofIssue.year; cout << "Input the date of return: "; cin>>theLSD.ofReturns.day>>theLSD.ofReturns.month>>theLSD.ofReturns.year; cout << "Input the date of fact return: "; cin>>theLSD.ofFactReturns.day>>theLSD.ofFactReturns.month>>theLSD.ofFactReturns.year; theBooks--; } theListLSD.push_back(theLSD); } } printLSD(theListLSD); }
//Изменить значение поля фактической даты возврата по указанной книге, указанного абонемента. void replaceNodes(list<LSD> &theListLSD, int id, char *name) { for(list<LSD>::iterator i=theListLSD.begin(); i!=theListLSD.end(); i++) { LSD theLSD = *i; if(theLSD.id==id && nameLSD(theLSD.name,name)) { cout << "Input the date of fact return: "; cin>>theLSD.ofFactReturns.day>>theLSD.ofFactReturns.month>>theLSD.ofFactReturns.year; } } printLSD(theListLSD); }
//Удалить узлы, в которых дата возврата и дата фактического возврата совпадают. void removeSameDates(list<LSD> &theListLSD) { for(list<LSD>::iterator i = theListLSD.begin(); i!=theListLSD.end(); i++) { LSD theLSD = *i; for(list<LSD>::iterator j = i; j!=theListLSD.end(); i++) { LSD temp = *j; if( theLSD.ofReturns.day == temp.ofFactReturns.day && theLSD.ofReturns.month == temp.ofFactReturns.month && theLSD.ofReturns.year == temp.ofFactReturns.year ) theListLSD.pop_front(); } } printLSD(theListLSD); }
//Определить количество книг, заданного абонемента. void findNodeLSD(list<LSD> theListLSD, int theID) { for(list<LSD>::iterator i = theListLSD.begin(); i!=theListLSD.end(); i++) { LSD theLSD = *i; if(isID(theLSD,theID)) cout << "Number of books: " << theLSD.books << endl; } }
int main() { while(true) { int num=0,size=0;
cout << "1. Insert new node if the fact return data = 0" << endl; cout << "2. replace fact date" << endl; cout << "3. Remove nodes with same fact return and return dates" << endl; cout << "4. Find number of books to abonement" << endl; cout << "5. Exit" << endl;
do { cout << "Choose the task: "; cin >> num; } while(num<1 || num>5); if(num==5) exit(1);
list<LSD> listLSD; size = sizeofLSD();
createLSD(listLSD,size); printLSD(listLSD);
switch(num) { case 1: insertNodeAfter(listLSD); break; case 2: int FindID; char FindName[256]; cout << "Input the find id: "; cin >> FindID; cout << "Input the find book name: "; cin>>FindName; replaceNodes(listLSD,FindID, FindName); break; case 3: removeSameDates(listLSD); break; case 4: cout << "Input the id of abonement:"; cin>>FindID; findNodeLSD(listLSD,FindID); break; } } return 0; }
|
не работает 1. Удаление узла, в котором дата возврата и дата фактического возврата совпадают. Добавлено через 12 минут и 56 секундПомогите пожалуйста. Это сообщение отредактировал(а) goonwarez - 28.12.2009, 22:23
|