Code:
// Bookstore Project 3.cpp : Defines the entry point for the console application.
// Declarations
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <istream>
using namespace std;
// Start Function Prototypes
void splash(void);
void header(string screenLine);
void menu(string isbn, string title, string author, string new_used, string enrolled, string requirement, int order);
void input(string isbn, string title, string author, string new_used, string enrolled, string requirement);
void output(string isbn, string title, string author, string new_used, string enrolled, string requirement, string resp, int order);
// End Function Prototypes
int _tmain(int argc, _TCHAR* argv[])
{
string isbn;
string title;
string author;
string new_used;
string enrolled;
string requirement;
int order;
// Use User Functions As Defined Below.
splash ();
menu(isbn, title, author, new_used, enrolled, requirement, order);
return 0;
}
// Start User Functions
void splash(void) //Splash Screen To Display On Program Start
{
system ("cls");
cout << endl;
cout << setw(53) << "San Diego Miramar College" << endl;
cout << endl;
cout << setw(52) << "Bookstore Order Program" << endl;
for (int i=0; i<3; i++)
cout << endl;
cout << setw(48) << "Revision #: 1.1" << endl;
cout << endl;
cout << setw(52) << "Program By: Joshua Hess" << endl;
for (int i=0; i<12; i++)
cout << endl;
cout << setw(53) << "Press <ENTER> To Continue";
cin.get();
}
void header(string screenLine)
{
string line1="San Diego Miramar College";
string line2="Bookstore Order Program";
system("cls");
cout << " "<<line1<<endl;
cout << " "<<line2<<endl;
}
void input(string isbn, string title, string author, string new_used, string enrolled, string requirement)//Input Screen For User To Input Information
{
string screenName = "Data Input Screen";
string screenLine= "Main Menu";
system ("cls");
header(screenLine);
cout << endl;
cout << setw(50) << screenName << endl;
cout << endl;
cout << endl;
cout << "Enter The Book ISBN: ";
getline(cin, isbn);
cout << "Enter The Book Title: ";
getline(cin, title);
cout << "Enter The Book Author: ";
getline(cin, author);
cout << endl;
cout << endl;
cout << setw(79) << "------------------------------------------------------------------------------" << endl;
cout << endl;
cout << endl;
cout << "Enter New or Used Book (N / U): ";
getline(cin, new_used);
cout << "Enter Required or Not Required (R / NR): ";
getline(cin, requirement);
cout << "Enter the Estimated Enrollment: ";
getline(cin, enrolled);
}
void menu(string isbn, string title, string author, string new_used, string enrolled, string requirement, int order) //Menu Function To Allow User To Select Input, Output, or Quit.
{
string option1 = "<I>nput";
string option2 = "<O>utput";
string option3 = "<E>xit";
string prompt = "Enter I, O, or E ";
string screenLine = "Main Menu";
string resp;
do
{
system ("cls");
header(screenLine);
cout << endl;
cout << setw(45) << screenLine << endl;
cout << endl;
cout << endl;
cout << setw(30) << option1 << endl;
cout << endl;
cout << setw(30) << option2 << endl;
cout << endl;
cout << setw(30) << option3 << endl;
cout << endl;
cout << setw(32) << prompt;
getline(cin, resp);
switch(resp.at(0))
{
case 'I':
case 'i':
input(isbn, title, author, new_used, enrolled, requirement);
break;
case 'O':
case 'o':
output(isbn, title, author, new_used, enrolled, requirement, resp, order);
break;
case 'E':
case 'e':
break;
default:
cout << "Entry Error - Enter I, O, or E: ";
getline(cin, resp);
}
}while((resp.at(0) !='E')&&(resp.at(0) !='e'));
}
void output(string isbn, string title, string author, string new_used, string enrolled, string requirement, string resp, int order) //Results Screen To Display Input And Calculations
{
string screenLine = "Main Menu";
string screenName = "Data Output Screen";
system ("cls");
header(screenLine);
cout << endl;
cout << setw(26) << "ISBN : " << isbn << endl;
cout << setw(26) << "Title : " << title << endl;
cout << setw(26) << "Author : " << author << endl;
cout << endl;
cout << setw(79) << "------------------------------------------------------------------------------" << endl;
cout << endl;
cout << setw(38) << "Projected Number of Books To Order" << endl;
cout << setw(77) << "For required books: Expected percentage of students buying a new book" << endl;
cout << setw(43) << "at 47%, and 35% purchasing if used." << endl;
cout << setw(76) << "For non-required books: Expected percentage of students buying a new" << endl;
cout << setw(48) << "book at 26%, and 10% purchasing if used." << endl;
cout << endl;
cout << setw(29) << "Expected Enrollment: " << enrolled << endl;
cout << setw(37) << "Book Status (N=New, U=Used): ";
//Will display New and Used instead of N and U
if ((new_used.at(0)=='N')||(new_used.at(0)=='n'))
cout << "New" << endl;
else
cout << "Used" << endl;
cout << setw(40) << "Required / Not Required (R/NR): ";
//Will display Required and Not Required instead of R and NR
if ((requirement.at(0)=='R')||(requirement.at(0)=='r'))
cout << "Required" << endl;
else
cout << "Not Required" << endl;
cout << endl;
//Order Calculations
if ((new_used.at(0)=='N')||(new_used.at(0)=='n'))
if ((requirement.at(0)=='R')||(requirement.at(0)=='r'))
order = (int)(atof(enrolled.data())*.47);
else
order = (int)(atof(enrolled.data())*.26);
if ((new_used.at(0)=='U')||(new_used.at(0)=='u'))
if ((requirement.at(0)=='R')||(requirement.at(0)=='r'))
order = (int)(atof(enrolled.data())*.35);
else
order = (int)(atof(enrolled.data())*.1);
cout << setw(47) << "Books to Order: " << order << endl;
cout << setw(53) << "Press <Enter> To Continue" << endl;
getline(cin, resp);
}
// End User Functions