fork download
  1. struct Book {
  2. char author[50];
  3. char title[100];
  4. char publisher[50];
  5. int year;
  6. int pages;
  7. };
  8.  
  9. // характеристики книг
  10. void setBook(struct Book *book, char author[], char title[], char publisher[], int year, int pages) {
  11. strcpy(book->author, author);
  12. strcpy(book->title, title);
  13. strcpy(book->publisher, publisher);
  14. book->year = year;
  15. book->pages = pages;
  16. }
  17.  
  18. // Получить авторов
  19. char* getAuthor(struct Book *book) {
  20. return book->author;
  21. }
  22.  
  23. // Получить название
  24. char* getTitle(struct Book *book) {
  25. return book->title;
  26. }
  27.  
  28. // Получить издателя
  29. char* getPublisher(struct Book *book) {
  30. return book->publisher;
  31. }
  32.  
  33. // год
  34. int getYear(struct Book *book) {
  35. return book->year;
  36. }
  37.  
  38. // кол-во стр
  39. int getPages(struct Book *book) {
  40. return book->pages;
  41. }
  42.  
  43. // вывод инфы
  44. void showBook(struct Book *book) {
  45. printf("Author: %s\n", book->author);
  46. printf("Title: %s\n", book->title);
  47. printf("Publisher: %s\n", book->publisher);
  48. printf("Year: %d\n", book->year);
  49. printf("Pages: %d\n", book->pages);
  50. }
  51.  
  52. int main() {
  53. struct Book books[3]; // массива книг
  54. // Описание книг
  55. setBook(&books[0], "Pushkin", "book", "news", 2000, 300);
  56. setBook(&books[1], "Gogol", "Revesora", "TwoBooks", 2010, 400);
  57. setBook(&books[2], "Gogol", "Dead souls", "Own", 2015, 500);
  58.  
  59. // Вывод списка книг заданного автора
  60. printf("Books by Author1:\n");
  61. for(int i = 0; i < 3; i++) {
  62. if(strcmp(getAuthor(&books[i]), "Author1") == 0) {
  63. showBook(&books[i]);
  64. }
  65. }
  66.  
  67. // Вывод списка книг выпущенных заданным издателем
  68. printf("Books published by Publisher1:\n");
  69. for(int i = 0; i < 3; i++) {
  70. if(strcmp(getPublisher(&books[i]), "Publisher1") == 0) {
  71. showBook(&books[i]);
  72. }
  73. }
  74.  
  75. // Вывод списка книг выпущенных после заданного года
  76. int year = 2010;
  77. printf("Books published after %d:\n", year);
  78. for(int i = 0; i < 3; i++) {
  79. if(getYear(&books[i]) > year) {
  80. showBook(&books[i]);
  81. }
  82. }
  83.  
  84. return 0;
  85. }
  86.  
  87.  
Success #stdin #stdout 0s 5300KB
stdin
1999
stdout
Books by Author1:
Books published by Publisher1:
Books published after 2010:
Author: Gogol
Title: Dead souls
Publisher: Own
Year: 2015
Pages: 500