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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
|
#include<iostream>
#include<cmath>
#include<iomanip>
#include<fstream>
#include<string.h>
using namespace std;
struct Book
{
char newTitle[31];
char newAuthor[31];
int newCopies;
double newPrice;
};
/***************************************************************
Function: print
Use: prints the book attributes
Arguments: A string
Returns: N/A
***************************************************************/
void print(Book newBook)
{
cout << "Title: " << newBook.newTitle << endl << "Author: " << newBook.newAuthor << endl <<
"Copies in Stock: " << newBook.newCopies << endl << "Price: $" << newBook.newPrice << endl;
}
/***************************************************************
Function: setTitle
Use: changes the title for the book data
Arguments: a character array
Returns: N/A
***************************************************************/
void setTitle(char newTitle[], Book newBook)
{
strcpy(newBook.newTitle, newTitle);
}
/***************************************************************
Function: setAuthor
Use: changes the author for the book data
Arguments: a character array
Returns: N/A
***************************************************************/
void setAuthor(char newAuthor[], Book newBook)
{
strcpy(newBook.newAuthor, newAuthor);
}
/***************************************************************
Function: setCopies
Use: changes the number of copies in stock for the book data
Arguments: an integer representing the number of copies
Returns: N/A
***************************************************************/
void setCopies(int newCopies, Book newBook)
{
if(newCopies >= 0)
{
newBook.newCopies = newCopies;
}
else
{
newBook.newCopies = 0;
cout << endl << "Error: Copies less than zero";
}
}
/***************************************************************
Function: setPrice
Use: changes the price for the book data
Arguments: an integer representing the price
Returns: N/A
***************************************************************/
void setPrice(double newPrice, Book newBook)
{
if(newPrice >= 0)
{
newBook.newPrice = newPrice;
}
else
{
newBook.newPrice = 0;
cout << endl << "Error: Price less than zero";
}
}
/***************************************************************
Function: placeOrder
Use: Determines the outcome of an order placed for a book, whether
it be an insufficient stock, invalid order, or total for a proper
order placed
Arguments: an integer representing the quantity being ordered
Returns: N/A
***************************************************************/
void placeOrder(int orderQuantity, Book newBook)
{
int total;
total = orderQuantity * (newBook.newPrice);
if (orderQuantity <= 0)
{
cout << endl << "Invalid Order Quantity";
}
else if (orderQuantity > newBook.newCopies)
{
cout << endl << "Insufficient Stock";
}
else
{
newBook.newCopies -= orderQuantity;
cout << endl << "Total Cost: " << total;
}
}
/***************************************************************
Function: addStock
Use: Determines the outcome of a restocking procedure taking place
Arguments: an integer representing the quantity being restocked
Returns: N/A
***************************************************************/
void addStock(int restockQuantity, Book newBook)
{
if (restockQuantity <= 0)
cout << endl << "Invalid quantity";
else
newBook.newCopies += restockQuantity;
}
/***************************************************************
Function: main
Use: runs everything else
Arguments:N/A
Returns: N/A
***************************************************************/
int main()
{
Book newBook("Soylent Green", "Andrew Evans", 31, 20);
Book fakeBook("Errors", "Rules Broken", -2, -3);
cout << endl << "Book Information" << endl;
print(newBook);
cout << endl << "Changing Book Title" << endl;
setTitle("This is a New Title", newBook);
cout << endl << "New Book Information" << endl;
print(newBook);
cout << endl << "Changing Book Author" << endl;
setAuthor("Bob Barker", newBook);
cout << endl << "New Book Information" << endl;
print(newBook);
cout << endl << "Changing Copies of Book" << endl;
setCopies(-5, newBook);
cout << endl << "New Book Information" << endl;
print(newBook);
cout << endl << "Changing Copies of Book" << endl;
setCopies(20, newBook);
cout << endl << "New Book Information" << endl;
print(newBook);
cout << endl << "Changing Book Price" << endl;
setPrice(-4, newBook);
cout << endl << "New Book Information" << endl;
print(newBook);
cout << endl << "Changing Book Price" << endl;
setPrice(25, newBook);
cout << endl << "New Book Information" << endl;
print(newBook);
cout << endl << "Placing Order" << endl;
placeOrder(99, newBook);
cout << endl << "Placing Order" << endl;
placeOrder(3, newBook);
cout << endl << "New Book Information" << endl;
print(newBook);
cout << endl << "Adding Stock" << endl;
addStock(0, newBook);
cout << endl << "Adding Stock" << endl;
addStock(12, newBook);
cout << endl << "New Book Information" << endl;
print(newBook);
return 0;
}
| |