Перейти из форума на сайт.

НовостиФайловые архивы
ПоискАктивные темыТоп лист
ПравилаКто в on-line?
Вход Забыли пароль? Первый раз на этом сайте? Регистрация
Компьютерный форум Ru.Board » Компьютеры » Прикладное программирование » Задачи по C/С++

Модерирует : ShIvADeSt

 Версия для печати • ПодписатьсяДобавить в закладки
На первую страницук этому сообщениюк последнему сообщению

Открыть новую тему     Написать ответ в эту тему

ItsJustMe

Silver Member
Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору

Код:
//book.h
//что из этого кинуть в book.cpp - реши сам(а).
#include <tchar.h>
#include <windows.h>
#include <iostream>
#include <fstream>
using namespace std;
 
class Person
{
protected:
  LPTSTR name;  
  LPTSTR surname;  
  LPTSTR tel;  
  int age;
  Person *next;
  void set(LPTSTR ln, LPTSTR fn, int a, LPTSTR t)
  {
    if (ln)
    {
      int c = lstrlen(ln);
      if (c)
      {
        surname = new TCHAR[c + 1];
        lstrcpy(surname, ln);
      }
    }
    if (fn)
    {
      int c = lstrlen(fn);
      if (c)
      {
        name = new TCHAR[c + 1];
        lstrcpy(name, fn);
      }
    }
    if (tel)
    {
      int c = lstrlen(t);
      if (c)
      {
        tel = new TCHAR[c + 1];
        lstrcpy(tel, t);
      }
    }
    if (a < 0)
      a = 0;
    age = a;
  }
  void set(Person *p)
  {
    if (p)
      set(p->LastName(), p->FirstName(), p->Age(), p->Phone());
  }
  bool equal(Person *p)
  {
    bool b = false;
    if (p)
    {
      b = true;
      if (LastName() && p->LastName())
        b = !_tcsicmp(LastName(), p->LastName());
      if (b)
      {
        if (FirstName() && p->FirstName())
          b = !_tcsicmp(FirstName(), p->FirstName());
        if (b)
        {
          if (Age() && p->Age())
            b = Age() == p->Age();
          if (b)
          {
            if (Phone() && p->Phone())
              b = !_tcsicmp(Phone(), p->Phone());
          }
        }
      }
    }
    return b;
  }
public:
  Person(LPTSTR ln = NULL, LPTSTR fn = NULL, int a = 0, LPTSTR t = NULL)
  : surname(NULL), name(NULL), tel(NULL), age(0), next(NULL)
  {
    set(ln, fn, a, t);
  }
  ~Person()
  {
    delete next;
    delete[] tel;
    delete[] name;
    delete[] surname;
  }
  LPCTSTR FirstName() const {return name;}
  LPCTSTR LastName() const {return surname;}
  LPCTSTR Phone() const {return tel;}
  int Age() const {return age;}
  void Print(LPCTSTR f = NULL) const
  {
    if (f && lstrlen(f))
    {
      wfilebuf wOutFile;
      wOutFile.open(f, ios_base::out | ios_base::trunc | ios_base::binary);
      if (wOutFile.is_open())
      {
        TCHAR wBuffer[1024];
        wOutFile.pubsetbuf(wBuffer, (streamsize)1024);
        TCHAR buffer[1024];
        wsprintf(buffer, _T("\nLast name: %s\nFirst name: %s\nAge: %d\nPhone: %s\n") << LastName(), FirstName(), Age(), Phone());
        wOutFile.sputn(buffer, (streamsize)lstrlen(buffer));
        wOutFile.close();
      }
    }
    else
      wcout << endl << _T("Last name: ") << LastName() << endl << _T("First name: ") << FirstName() << endl << _T("Age: ") << Age() << endl << _T("Phone: ") << Phone() << endl;
  }
};
 
class Book : public Person
{
  int count;
  static Person* del(Person *p)
  {
    Person *res = NULL;
    if (p)
    {
      res = p->next;
      p->next = NULL;
      delete p;
    }
    return res;
  }
public:
  Book() : Person(), count(0)
  {
  }
  int Count() const {return count;}
  bool Add(Person *p)
  {
    if (p)
    {
      if (!surname)
        set(p->LastName(), p->FirstName(), p->Age(), p->Phone());
      else
      {
        Person *n = this;
        while (n->next)
          n = n->next;
        n->next = new Person(p->LastName(), p->FirstName(), p->Age(), p->Phone());
      }
      count++;
      return true;
    }
    return false;
  }
  bool Delete(Person *p)
  {
    if (p)
    {
      if (equal(p))
      {
        set(next);
        next = del(next);
      }
      else
      {
        Person *n = this;
        while (n->next && !n->next->equal(p))
          n = n->next;
        n->next = del(n->next);
      }
      if (count)
        count--;
      return true;
    }
    return false;
  }
  bool Clear()
  {
    delete next;
    next = NULL;
    count = 0;
  }
  int FindFirst() const (return (count) ? 0 : -1;}
  int FindNext(int start = 0) const {return ((start >= 0) && (start < count - 1)) ? (start + 1) : -1;}
  void Print(LPCTSTR f = NULL) const
  {
    Person::Print(f);
    Person *n = this;
    while (n->next)
    {
      n->next->Print(f);
      n = n->next;
    }
  }
};

Всего записей: 2028 | Зарегистр. 02-09-2005 | Отправлено: 15:07 05-11-2007
Открыть новую тему     Написать ответ в эту тему

На первую страницук этому сообщениюк последнему сообщению

Компьютерный форум Ru.Board » Компьютеры » Прикладное программирование » Задачи по C/С++


Реклама на форуме Ru.Board.

Powered by Ikonboard "v2.1.7b" © 2000 Ikonboard.com
Modified by Ru.B0ard
© Ru.B0ard 2000-2024

BitCoin: 1NGG1chHtUvrtEqjeerQCKDMUi6S6CG4iC

Рейтинг.ru