Thread: multi file project error part 2

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    61

    Need Help Please!

    I am now dissecting each file piece by piece. The project consists of 2 header files and 2 definition files plus a main program utilizing both classes. One of the definition files (sales.cpp) compiles fine, the other one (register.cpp) is the one that produces 2 errors. I am going to provide the 2 header files that are needed to be included in the register.cpp, as well as the register.cpp file. Any help that can be given I will appreciate immensely.

    sale.h
    Code:
        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
    };
    register.h
    Code:
       //register header file
    
    #include "sale.h"
    
    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;
    };
    register.cpp
    Code:
        //definitions for register class
    
    #include <iomanip>
    #include <iostream>
    
    #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;
                                      }
    Compiler errors:
    Code:
        sale.h(14) : error C2011: 'ItemType' : 'enum' type redefinition
        sale.h(17) : error C2011: 'Sale' : 'class' type redefinition
    Last edited by dantestwin; 07-21-2004 at 06:14 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well since you're determined to ignore me, I'll reciprocate
    http://cboard.cprogramming.com/showthread.php?t=54998
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    61
    I wasn't trying to ignore you, please read the response i posted on the other thread.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Don't cross post, and stop spamming!

  5. #5
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    Holy crap!? I just realized there's like, 3 different versions of this post

    ........*brain short circuits*

  6. #6
    Registered User
    Join Date
    Jul 2004
    Posts
    61
    Quote Originally Posted by sean_mackrory
    Don't cross post, and stop spamming!
    Don't have a cow. My intention was not to spam. I've posted several times on here in the past. Tonight I made a mistake and created a couple of threads when I shouldn't have but it will not happen again.

    You want to call my mom and tell on me?? Jeez, i just need help.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  5. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM