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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
const int SIZE = 3; //the size of the arrays
struct BookInfo
{
string title; //title of book
double price; //price of book
};
struct Author
{
string name; //author of book
BookInfo books; //array that holds 3 books the author has written
};
//a[];
void showInfo(Author[], int);
void getInfo(Author[], int);
int main()
{
Author a[SIZE] = { {"NONE", {"NONE", 0}},
{ "NONE",{ "NONE", 0 }},
{ "NONE",{ "NONE", 0 }}
};
cout << "Here is the data after initialization" << endl;
showInfo(a, SIZE);
cout << endl;
cout << "Get user's input" << endl;
getInfo(a, SIZE);
cout << endl;
showInfo(a, SIZE);
cout << endl;
system("pause");
return 0;
}
//**************************************************
//*This function displays the information stored *
//*in a[] *
//**************************************************
void showInfo(Author a[], int size)
{
for (int i = 0; count < size; i++)
{
cout << "The author: " << a[i].name << endl;
for (int j = 0; j < size; j++)
{
cout << "\tThe title: " << a[j].books.title << ", the price: $" << a[j].books.price << endl;
}
}
}
//**************************************************
//*This function gets array information from the *
//*user *
//**************************************************
void getInfo(Author a[], int size)
{
for (int i = 0; i < size; i++) {
cout << "Enter the author's name: ";
getline(cin, a[i].name);
for (int j = 0; j < size; j++) {
cout << "Enter the title " << (j + 1) << " :";
getline(cin, a[j].books.title);
if (a[j].books.title != "NONE")
{
cout << "Enter price " << (j + 1) << " :$";
cin >> a[j].books.price;
cin.ignore();
}
else
break;
}
cout << endl;
}
cout << endl;
}
|