Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdlib.h>
- #include<string.h>
- #include<iostream>
- #include<fstream>
- using namespace std;
- const size_t MAX_LEN = 256;
- struct book {
- char author[MAX_LEN];
- char name[MAX_LEN];
- int edition;
- int price;
- };
- void book_copy(const book &a, book &b){
- strcpy(b.author, a.author);
- strcpy(b.name, a.name);
- b.edition = a.edition;
- b.price = a.price;
- }
- void read(book &b, istream &is){
- is >> b.author >> b.name >> b.edition >> b.price;
- }
- void write(const book &b, ostream &os){
- os << b.author << " "
- << b.name << " "
- << b.edition << " "
- << b.price << "\n";
- }
- int main(){
- ifstream in("input.txt");
- int n;
- in >> n;
- book *lib = new book[n];
- for (int i = 0; i < n; ++i){
- read(lib[i], in);
- }
- for (int i = 0; i < n; ++i){
- for (int j = i + 1; j < n; ++j){
- if (strcmp(lib[i].name, lib[j].name) > 0){
- swap(lib[i], lib[j]);
- }
- }
- }
- in.close();
- ofstream out("input.txt");
- out << n << "\n";
- for (int i = 0; i < n; ++i){
- write(lib[i], out);
- }
- delete[] lib;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement