Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
#include "stdafx.h" #include "StoreInfo.h" #include <stdio.h> #include <iostream> #include <fstream> #include <algorithm> #include <vector> #include <iomanip> #include <map> using namespace std; // Tax rate catagories const double alcoholTax = 0.08; const double foodTax = 0.05; const double genMerchandiseTax = 0.07; const double medicineTax = 0.04; struct cost { double alcTax = 0.0, food = 0.0, genMerch = 0.0, meds = 0.0;// Total taxes collected for each tax bracket double totalTax = alcTax + food + genMerch + meds;// Total Taxes to be accessed later // Variables used in the accessor functions at the bottom double costBeforeTax = 0.0, costAfterTax = 0.0, custSaving = 0.0, totRegPrice = 0.0, totSalePrice = 0.0; }; // Constructor GrItem::GrItem(string name, int quantity, float regPrice, float salePrice, bool onSale, TaxCategory taxCategory){ name = name; quantity = quantity; regPrice = regPrice; salePrice = salePrice; onSale = onSale; taxCategory = taxCategory; }; // Default constructor GrItem::GrItem() { } // Get the total cost before the tax void getTotBeforeTax(double regPrice, double salePrice, bool onSale){ cost itemTotalCost; if (onSale == 1){ itemTotalCost.costBeforeTax += salePrice; itemTotalCost.totSalePrice += salePrice; } else{ itemTotalCost.costBeforeTax += regPrice; itemTotalCost.totRegPrice += regPrice; } } // Get the total after tax void getTotAfterTax(float costBeforeTax, float totalTax){ cost itemTotalCost; itemTotalCost.costAfterTax = costBeforeTax + totalTax; } // Get the total amount of tax for each category void getTotTaxCategory(double regPrice, double salePrice, bool onSale, TaxCategory taxCategory){// These different values are determined by what enum tax category they are cost itemTotalCost; // Adds values to the total alcohol tax gathered if (taxCategory = TaxCategory::alcohol){ if (onSale = true) itemTotalCost.alcTax += salePrice * alcoholTax; itemTotalCost.alcTax += regPrice * alcoholTax; } if (taxCategory = TaxCategory::food){ if (onSale = true) itemTotalCost.alcTax += salePrice * foodTax; itemTotalCost.alcTax += regPrice * foodTax; } if (taxCategory = TaxCategory::genMerchandise){ if (onSale = true) itemTotalCost.alcTax += salePrice * genMerchandiseTax; itemTotalCost.alcTax += regPrice * genMerchandiseTax; } if (taxCategory = TaxCategory::medicine){ if (onSale = true) itemTotalCost.alcTax += salePrice * medicineTax; itemTotalCost.alcTax += regPrice * medicineTax; } } // Get customer savings (total of all differences between regular price and sale price for items that are currently on sale) void getCustSave(double totRegPrice, double totSalePrice, bool onSale){ cost itemTotalCost; if (onSale == 1){ itemTotalCost.custSaving = totRegPrice - totSalePrice; } } // Function that is called to sort by name bool sortByName(const GrListItem &lhs, const GrListItem &rhs){ return lhs.name < rhs.name; } // Function that is called to sort by quantity bool sortByQuantity(const GrListItem &lhs, const GrListItem &rhs){ return lhs.quantity < rhs.quantity; } // Function that is called to sort by regular price bool sortByRegPrice(const GrListItem &lhs, const GrListItem &rhs){ return lhs.regPrice < rhs.regPrice; } // Function that is called to sort by sale price bool sortBySalePrice(const GrListItem &lhs, const GrListItem &rhs){ return lhs.salePrice < rhs.salePrice; } const int listSize = 20; // Main method int main() { string input;// Holds each line from the imported textfile temporarily string fileName;// Name of grocery list user wishes to use fstream nameFile;// File stream object GrListItem itemList[listSize];// Creates a list of objects. These objects are each item on the list and hold related information std::vector<GrListItem> vectorList(itemList, itemList + listSize); cost itemTotalCost; // Requests data from user cout << "What is the name of the grocery list you wish to use? " << endl; getline(cin, fileName);// Retrieves filename from user and applies string to grListName // Tests to see if file can be opened fstream testFile(fileName, ios::out); if (testFile.fail()){ cout << "ERROR: Cannot open indicated file.\n"; return 0; } // Open data file nameFile.open(fileName, ios::in); // Read data and apply variables to an object if (nameFile){ int count = 0; while (nameFile && count < listSize){ // Read the name getline(nameFile, input, '#'); vectorList[count].name = input;// Assigns item name to the object inside itemList.name // Read quantity getline(nameFile, input, '$'); vectorList[count].quantity = atoi(input.c_str());// Casts string to an int // Read regular price getline(nameFile, input, '$'); vectorList[count].regPrice = stof(input.c_str());// Casts string to a float // Read sale price getline(nameFile, input, '#'); vectorList[count].salePrice = stof(input.c_str()); // Read on sale bool getline(nameFile, input, '#'); if (input == "Y")// If the item is on sale, the onSale var returns true vectorList[count].onSale = true; else vectorList[count].onSale = false; // Read tax category getline(nameFile, input, '#'); if (input == "alcohol") { vectorList[count].taxCategory = TaxCategory::alcohol;; } else if (input == "general merchanise") { vectorList[count].taxCategory = TaxCategory::genMerchandise; } else if (input == "food") { vectorList[count].taxCategory = TaxCategory::food;; } else if (input == "medicine") { vectorList[count].taxCategory = TaxCategory::medicine;; } else { std::cout << "BAD TAX CATEGORY" << std::endl; } // These functions are called as many times as there are objects in the array. getTotBeforeTax(vectorList[count].regPrice, vectorList[count].salePrice, vectorList[count].onSale); getTotTaxCategory(vectorList[count].regPrice, vectorList[count].salePrice, vectorList[count].onSale, vectorList[count].taxCategory); getTotAfterTax(itemTotalCost.costBeforeTax, itemTotalCost.totalTax); count++; } // Close file nameFile.close(); } else cout << "ERROR: Cannot open file.\n"; // Sort array // OFFER USER TO CHOOSE HOW THEY WOULD LIKE TO SORT THEIR LIST!!! For extra points // Maybe std::sort(vectorList.begin(), vectorList.end(), sortByName); // For loop that creates a receipt on the screen // Formatting may or may not be correct for (int i = 0; i != listSize; ++i){ std::cout << vectorList[i].name << endl;// Print item name std::cout << std::setfill(' ') << std::setw(20); std::cout.fill(' '); std::cout << std::setfill(' ') << std::setw(5);// Print item quantity std::cout << vectorList[i].quantity << endl; std::cout.fill(' '); std::cout << std::setfill(' ') << std::setw(5);// Print regular price of item std::cout << vectorList[i].regPrice << endl;// Adjust preci std::cout.fill(' '); std::cout << std::setfill(' ') << std::setw(5);// Print sale price of item std::cout << vectorList[i].salePrice << endl; std::cout.fill(' '); if (vectorList[i].onSale == 1){ std::cout << 'Y' << endl;// Print 'Y' if vectorList[i] is on sale std::cout.width(3); std::cout.fill(' '); } else { std::cout << 'N' << endl;// Print 'N' if vectorList[i] is not on sale std::cout.width(3); std::cout.fill(' '); } std::cout << vectorList[i].taxCategory << endl;// Print tax category std::cout.width(20); std::cout.fill(' '); } // Print details of purchase below list of bought items // NOTE: THESE VALUES ARE STORED IN THE STRUCT ABOVE main() // Display total before tax // Display total after tax // Display customer Savings }
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Untitled
15 hours ago | 2.28 KB
GSA NS
19 hours ago | 1.37 KB
WaterFul.m
MatLab | 21 hours ago | 0.42 KB
WaterEmpty.m
MatLab | 21 hours ago | 0.54 KB
Spinning.m
MatLab | 21 hours ago | 0.53 KB
Drying.m
MatLab | 21 hours ago | 0.48 KB
DoorCls.m
MatLab | 21 hours ago | 0.55 KB
Washing.m
MatLab | 21 hours ago | 0.45 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!