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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <ctime>
#include <cstring>
using namespace std;
//Structure=======================================================
const int MAXSIZE=25;
const int MAXBOOKS=100;
struct Book
{
char ISBN[MAXSIZE];
char Title[MAXSIZE];
char Author[MAXSIZE];
int Year;
int Qty;
float Price;
};
//Function Prototypes=======================================================
void Menu(Book[], int&);
void Read(Book[], int&);
void View(Book[], int&);
int main()
{
Book Books[MAXBOOKS];
int numBooks = 0;
Read(Books, numBooks);
cout << "Bookstore Menu \n\n";
Menu(Books, numBooks);
return 0;
}
//Function Definitions======================================================
void Menu(Book Books[], int &count)
{
char Choice;
cout << "Select from the following: \n\n";
cout << "V) View all books \n";
cout << "A) Add a new book \n";
cout << "D) Delete a book \n";
cout << "U) Update a book price and quantity \n";
cout << "Q) Quit the program \n";
cout << "Choice? ";
Choice = toupper(Choice);
while(Choice != 'Q')
{
cin >> ws;
cin.get(Choice);
if(Choice == 'V')
View(Books, count);
else
cout << "Please type a correct response(V, A, D, U, Q) \n";
}
return;
}
void Read(Book Books[], int &count)
{
ifstream Input;
Input.open("Books.dat");
count=0;
while(!Input.eof())
{
Input.getline(Books[count].ISBN, MAXSIZE);
Input.getline(Books[count].Title, MAXSIZE);
Input.getline(Books[count].Author, MAXSIZE);
Input >> Books[count].Year;
Input >> Books[count].Qty;
Input >> Books[count].Price;
count++;
}
Input.close();
}
void View(Book Books[], int &count)
{
cout << "Bookstore Inventory \n\n";
cout << setw(5) << "ISBN NO.";
cout << setw(5) << "Title";
cout << setw(5) << "Author";
cout << setw(5) << "Year";
cout << setw(5) << "Qty";
cout << setw(5) << "Price";
for(int i=0; i<MAXBOOKS; i++)
{
cout << setw(5) << Books[i].ISBN;
cout << setw(5) << Books[i].Title;
cout << setw(5) << Books[i].Author;
cout << setw(5) << Books[i].Year;
cout << setw(5) << Books[i].Qty;
cout << setw(5) << Books[i].Price;
cout << endl;
}
Menu(Books, count);
}
|