Advertisement
kqlul123

Untitled

Jan 29th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "iostream"
  3. #include "io.h"
  4.  
  5. struct Info {
  6. char Author[20];
  7. char Name[20];
  8. int Cost;
  9. };
  10.  
  11. class Book {
  12. Info* mas;
  13. int N;
  14. public:
  15. void ReadFL();
  16. void Output();
  17. void Sort();
  18. };
  19.  
  20. void Book::ReadFL() {
  21. FILE *f;
  22. fopen_s(&f,"Book.dat", "rb");
  23. int d;
  24. d = _fileno(f);
  25. long L = filelength(d);
  26. N = L / sizeof(Info);
  27. mas = new Info;
  28. for (int i = 0; i < N; i++) {
  29. fread(mas + i, sizeof(Info), 1, f);
  30. }
  31. fclose(f);
  32. }
  33.  
  34. void Book::Sort() {
  35. Info zap;
  36. int f;
  37. for (int i = 0; i < N - 1; i++)
  38. {
  39. for (int j = i + 1; j < N; j++)
  40. {
  41. mas[i].Cost < mas[j].Cost;
  42. if (f) {
  43. zap = mas[i];
  44. mas[i] = mas[j];
  45. mas[j] = zap;
  46. }
  47. }
  48. }
  49. }
  50.  
  51. void Book::Output() {
  52. char* Aut;
  53. Aut = new char;
  54. std::cout << "Enter author name" << std::endl;
  55. std::cin >> Aut;
  56. printf("%-20s", "Author");
  57. printf("%-20s", "Name");
  58. printf("%-20s", "Cost");
  59.  
  60. for (int i = 0; i < N; i++) {
  61. if (Aut == mas[i].Author) {
  62. printf("%-20s", mas[i].Author);
  63. printf("%-20s", mas[i].Name);
  64. printf("%-20s", mas[i].Cost);
  65. }
  66. }
  67. }
  68.  
  69. int main()
  70. {
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement