Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <clocale>
- #include <fstream>
- #define BOOKS_NUM 3
- using namespace std;
- struct tBook
- {
- char* author;
- char* name;
- int year;
- char* spec;
- };
- tBook* inputBook()
- {
- tBook* temp = new tBook;
- cout<<"Введите автора книги ";
- temp->author = new char[40];
- cin>>temp->author;
- cout<<"Введите наименование книги ";
- temp->name = new char[80];
- cin>>temp->name;
- cout<<"Введите год издания книги ";
- cin>>temp->year;
- cout<<"Введите специальность книги ";
- temp->spec = new char[40];
- cin>>temp->spec;
- return temp;
- }
- int outputBook(tBook* book)
- {
- cout<<"Автор книги: "<<book->author<<endl;
- cout<<"Наименование книги: "<<book->name<<endl;
- cout<<"Год издания: "<<book->year<<endl;
- cout<<"Специальность: "<<book->spec<<endl;
- return 0;
- }
- tBook* readBookFromFile(ifstream& inFile)
- {
- tBook* temp = new tBook;
- temp->author = new char[40];
- temp->name = new char[80];
- temp->spec = new char[40];
- inFile>>temp->author;
- inFile>>temp->name;
- inFile>>temp->year;
- inFile>>temp->spec;
- return temp;
- }
- int writeBookToFile(tBook* book, ofstream& outFile)
- {
- outFile<<book->author<<endl;
- outFile<<book->name<<endl;
- outFile<<book->year<<endl;
- outFile<<book->spec<<endl;
- return 0;
- }
- int task(ifstream inFile)
- {
- return 0;
- }
- int main()
- {
- setlocale(LC_ALL,"rus");
- ofstream outputFile("test.txt");
- for(int i=1;i<=BOOKS_NUM;i++)
- {
- cout<<"Введите данные об "<<i<<"-ой книге"<<endl;
- writeBookToFile(inputBook(), outputFile);
- }
- outputFile.close();
- ifstream inputFile("test.txt");
- for(int i=1;i<=BOOKS_NUM;i++)
- {
- cout<<"Данные об "<<i<<"-ой книге"<<endl;
- outputBook(readBookFromFile(inputFile));
- cout<<endl;
- }
- inputFile.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement