Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "iostream"
- #include "io.h"
- struct Info {
- char Author[20];
- char Name[20];
- int Cost;
- };
- class Book {
- Info* mas;
- int N;
- public:
- void ReadFL();
- void Output();
- void Sort();
- };
- void Book::ReadFL() {
- FILE *f;
- fopen_s(&f,"Book.dat", "rb");
- int d;
- d = _fileno(f);
- long L = filelength(d);
- N = L / sizeof(Info);
- mas = new Info;
- for (int i = 0; i < N; i++) {
- fread(mas + i, sizeof(Info), 1, f);
- }
- fclose(f);
- }
- void Book::Sort() {
- Info zap;
- int f;
- for (int i = 0; i < N - 1; i++)
- {
- for (int j = i + 1; j < N; j++)
- {
- mas[i].Cost < mas[j].Cost;
- if (f) {
- zap = mas[i];
- mas[i] = mas[j];
- mas[j] = zap;
- }
- }
- }
- }
- void Book::Output() {
- char* Aut;
- Aut = new char;
- std::cout << "Enter author name" << std::endl;
- std::cin >> Aut;
- printf("%-20s", "Author");
- printf("%-20s", "Name");
- printf("%-20s", "Cost");
- for (int i = 0; i < N; i++) {
- if (Aut == mas[i].Author) {
- printf("%-20s", mas[i].Author);
- printf("%-20s", mas[i].Name);
- printf("%-20s", mas[i].Cost);
- }
- }
- }
- int main()
- {
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement