1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include"my_class.h"
const int ARRAY_SIZE = 50;
void print(Book_Type array[], int size);
int main()
{
ifstream infile;
Book_Type books[ARRAY_SIZE];
string title, author[4], isbn, pub;
double cost;
int num_copies, num_auth, count = 0;
infile.open("mp7datados.txt");
getline(infile, title);
infile >> num_auth;
for (int i = 0; i < num_auth; i++)
{
getline(infile, author[i]);
}
getline(infile, pub);
infile >> isbn >> cost >> num_copies;
while (!infile.eof())
{
books[count++].load_data(title, num_auth, author, pub, isbn, cost, num_copies);
getline(infile, title);
infile >> num_auth;
for (int i = 0; i < num_auth; i++)
{
getline(infile, author[i]);
}
getline(infile, pub);
infile >> isbn >> cost >> num_copies;
}
print(books, count);
return 0;
}
void print(Book_Type array[], int size)
{
string tite, auth[4], _isbn, pub, author;
double cost;
int num_cops, num_auths;
for (int i = 0; i < size; i++)
{
array[i].return_data(tite, num_auths, auth, pub, _isbn, cost, num_cops);
cout << "Title: " << tite << endl;
if (num_auths > 1)
{
cout << "Authors: ";
for (int x = 0; x < num_auths; x++)
{
auth[x] = author;
cout << author << endl;
}
}
else
{
for (int y = 0; y < num_auths; y++)
{
auth[y] = author;
cout << "Author: " << author << endl;
}
}
cout << "Publisher: " << pub << endl;
cout << "ISBN: " << _isbn << " Price: " << cost << " Number of Copies: " << num_cops << endl;
}
}
|