Ugg, I do not know why I keep getting errors when I run this project. It ran perfectly before. If anyone can take a look and tell me why I get these errors, I would really appreciate it. Thanks.
I'm going to post the files one by one, then the errors at the very bottom. This is a long multiple file project so anyone who is willing
to help me, you rock and thank you so much.
Code:// sale.h -- header file for the Sale class // // An object of type Sale will store information about a single sale. // The variable "item" stores the type of item being sold (one of the four // items in the enumerated type ItemType). Books, music, and software are // the types of items sold. CREDIT stands for store credit, which incurs // a negative monetary charge. // The variable "price" stores the base price of the item // The variable "tax" is used to store the 7% sales tax // The variable "total" is used to store the final charge (price + tax) enum ItemType {BOOK, DVD, SOFTWARE, CREDIT}; class Sale { public: Sale(); // default constructor, // sets numerical member data to 0 void MakeSale(ItemType x, double amt); // the MakeSale function loads data into the Sale object. The // item and price are passed in. Compute tax and total. // (For store credits, tax is 0). ItemType Item(); // Returns the type of item in the sale double Price(); // Returns the price of the sale double Tax(); // Returns the amount of tax on the sale double Total(); // Returns the total price of the sale void Display(); // outputs sale info (described below) // for the Display function, output the sale item, the price, the tax, // and the total (all on one line). For store credit, the amounts // should be enclosed in < > symbols, to indicate a negative charge. // All monetary output should be in dollars and cents format, to two // decimal places. // Examples: Book $ 20.00 Tax: $ 1.40 Total: $ 21.40 // Credit <$ 15.00> Tax: $ 0.00 Total: <$ 15.00> private: double price; // price of item or amount of credit double tax; // amount of sales tax (does not apply to credit) double total; // final price once tax is added in. ItemType item; // transaction type };Code://definitions for Sales.h #include <iostream> #include "sale.h" #include <iomanip> #include <cctype> using namespace std; Sale::Sale() { price=0.0; tax=0.0; total=0.0; } void Sale::MakeSale(ItemType x, double amt) { item=x; price=amt; if (item==CREDIT) { tax=0.0; total=price; return; } tax= price *.07; total= price +tax; } ItemType Sale::Item() { return item; } double Sale::Price() { return price; } double Sale::Tax() { return tax; } double Sale::Total() { return total; } void Sale::Display() { //return everything else, simply displays if (item==BOOK) cout<<"Book \t"<<price<<"\tTax:\t"<<tax<<"\tTotal:\t"<<total<<endl; if (item==DVD) cout<<"DVD \t"<<price<<"\tTax:\t"<<tax<<"\tTotal:\t"<<total<<endl; if (item==SOFTWARE) cout<<"Software\t"<<price<<"\tTax:\t"<<tax<<"\tTotal:\t"<<total<<endl; if (item==CREDIT) cout<<"Credit \t"<<"<"<<price<<">"<<"\tTax:\t"<<tax<<"\tTotal:\t"<<"<"<<total<<">"<<endl; }Code://header file for Register class #include "sale.h" //register header file class Register { public: Register(int i, double amt);//allows ID number and starting amount //in register to be initialized when //object is created int GetID();//returns current ID number in the register to the //caller, accessor function double GetAmount();//return current amount in the register to //caller, accessor function void RingUpSale(ItemType c, double amt);//stores sale in sale list //also updates money amount //in register. //allows item type and sale //base price to be passed in void ShowLast();//displays only the info about last sale made void ShowAll();//Shows all of sales currently in sale list, one per line void Cancel();//cancels last sale in list double SalesTax(int n);//calculates and returns total amount of sales tax //for last n sales (i.e. most recent ones) private: int ID; double Amount; double sales_taxxx; double base_price; int numsales; Sale *sales; };Code://definitions for register class #include <iomanip> #include <iostream.h> #include "Register.h" #include "sale.h" using namespace std; //Register definitions Register::Register(int i, double amt) { ID=i; Amount=amt; numsales=0; //parameters in register are intialized to 0 } int Register::GetID() { return ID;//returning current ID in register } double Register::GetAmount() { return Amount;//returning current amount in refrigerator } void Register::RingUpSale(ItemType c, double amt) { Sale *s; //create a new array //memcpy the old array into the new array byte by byte //set the old array to the new array. numsales++; s = new Sale[numsales]; memcpy(s, sales, sizeof(Sale)*(numsales-1)); s[numsales-1].MakeSale(c, amt); sales=s; if (c==CREDIT) { Amount-=amt; } else { Amount+=amt; } } void Register::ShowAll(void) { if (numsales==0) { cout<<"No Sales Have Been Made Silly...."; return; } for (int i=0;i<numsales;i++) { sales[i].Display(); } } void Register::ShowLast(void) { if (numsales==0) { cout<<"No Sales Have Been Made Silly...."; return; } sales[numsales-1].Display(); } void Register::Cancel(void) { { Sale *s; if (numsales==0) { cout<<"No Sales Have Been Made Silly...."; return; } //create a new array //memcpy the old array into the new array byte by byte //set the old array to the new array. if (s[numsales].Item()==CREDIT) { Amount+=s[numsales].Price(); } else { Amount-=s[numsales].Price(); } numsales--; s = new Sale[numsales]; memcpy(s, sales, sizeof(Sale)*(numsales)); sales=s; } } double Register::SalesTax(int n) { int t_n=0; double tax_total=0; if (n<0) { cout<<"Invalid Number..."<<endl; return 0; } //figure out how many to count if (n > numsales) { t_n=numsales; } else { t_n=n; } //count t_n recent items for (int i=(numsales-1);i>=(numsales-t_n);i--) tax_total+=sales[i].Tax(); return tax_total; }
These are the errors I get. I'm using visual c++.Code://main file that tests both Sales and Register class #include "sale.h" #include "Register.h" #include <iostream> void main(void) { using namespace std; char command; char stype; ItemType saletype; double bprice; int pastitemstotax; Register r(1234, 10.00); r.RingUpSale(SOFTWARE, 1.00);//passing in item type and sale base price r.RingUpSale(DVD, 2.00); r.RingUpSale(BOOK, 3.00); cout<<"Jessica's Register: Enter Command: "; cin>>command; if (command<97) {command+=32;}//character setting while (command != 'x') {//error checking if (command=='s') { cout<<"Current ID : "<<r.GetID()<<endl;//requesting current id cout<<"Current Balance: "<<r.GetAmount()<<endl<<endl;//requesting current //amount in register } if (command=='l') { r.ShowAll();//requesting all current sales in register } if (command=='d') { r.ShowLast();//requesting info about last sale made } if (command=='m') { //requesting menu cout<<"----------------------Menu-------------------------"<<endl; cout<<" S: Show Current Amount in Register"<<endl; cout<<" R: Ring Up A Sale "<<endl; cout<<" D: Display the Last Sale "<<endl; cout<<" L: Display the Entire Sale List "<<endl; cout<<" C: Cancel the Last Stored Sale "<<endl; cout<<" T: Find the Total Sales Tax for Recent Sales"<<endl; cout<<" M: Show This Menu "<<endl; cout<<" X: Exit the Program "<<endl; cout<<"---------------------------------------------------"<<endl; . } if (command=='r') { //ringing up a sale stype='0';//sale type while (stype!='b' && stype!='d' && stype!='s' && stype!='c') { cout<<"Enter Sale Type: (B - Book, D - DVD, S - Software, C - Credit)"; cin>>stype; if (stype<97) {stype+=32;}//character setting if ((stype!='b' && stype!='d' && stype!='s' && stype!='c')) { cout<<"Invalid Sale Type. Please ReEnter."<<endl; } } bprice=0; cout<<endl<<"Enter Base Price: $"; cin>>bprice; while (bprice<0) { cout<<"Error: Base Price < 0 "<<endl<<endl<<"ReEnter Base Price: $"; cin>>bprice; } if (stype=='s') { saletype=SOFTWARE; } if (stype=='b') { saletype=BOOK; } if (stype=='d') { saletype=DVD; } if (stype=='c') { saletype=CREDIT; } r.RingUpSale(saletype, bprice); //asking for storage of sale //and update of money in register r.ShowLast();//requesting info on last sale } if (command=='c') { r.Cancel();//voids out last transaction cout<<"Last Sale Cancelled..."<<endl<<endl; } if (command=='t') { cout<<"Enter Past Items to Calculate Tax:"; cin>>pastitemstotax; while ((pastitemstotax)<0) { cout<<"Invalid Number..."<<endl; cin>>pastitemstotax; } r.ShowAll(); cout<<endl<<endl; cout<<r.SalesTax(pastitemstotax); } cout<<endl<<endl; cout<<"Jessica's Register: Enter Command: "; cin>>command; if (command<97) {command+=32;}//character setting }//end while }//end main
Code:sale.h(14) error C2011: 'ItemType' : 'enum' type redefinition sale.h(17) : error C2011: 'Sale' : 'class' type redefinition main.cpp sale.h(14) : error C2011: 'ItemType' : 'enum' type redefinition sale.h(17) : error C2011: 'Sale' : 'class' type redefinition main.cpp(74) : error C2143: syntax error : missing ';' before '.' Error executing cl.exe.



LinkBack URL
About LinkBacks


