Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8130009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:31:54+00:00 2026-06-06T08:31:54+00:00

So I’m doing this project for my OO class. We need to create two

  • 0

So I’m doing this project for my OO class. We need to create two classes, Sale and Register. I’ve written Sale and most of Register. My only problem (at the moment) is that I cannot seem to access the private member data of a sale object from my register class.

Sale header:

enum ItemType {BOOK, DVD, SOFTWARE, CREDIT};

class Sale
{
public:
Sale();         // default constructor, 
            // sets numerical member data to 0

void MakeSale(ItemType x, double amt);  

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)

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 header:

class Register{
public:

Register(int ident, int amount);
~Register();
int GetID(){return identification;}
int GetAmount(){return amountMoney;}
void RingUpSale(ItemType item, int basePrice);
void ShowLast();
void ShowAll();
void Cancel();
int SalesTax(int n);

private:

int identification;
int amountMoney;
int listSize = 5;
int numSales;
Sale* sale;
};

So I’m trying to write the RingUpSale() function right now but I can’t seem to be able to access the private field. Here’s my code:

void Register::RingUpSale(ItemType item, int basePrice){
if(numSales == listSize){
        listSize += 5;
        Sale * tempArray = new Sale[listSize];
        memcpy(tempArray, sale, numSales * sizeof(Sale));
        delete [] sale;
        sale = tempArray;
    }
    sale[numSales]->item = item; //this works for some reason
    sale[numSales]->total = basePrice; // this doesn't
    if(item == 'CREDIT'){ 
            sale[numSales]->tax = 0; // and this doesn't
            sale[numSales]->total = basePrice; // and neither does this
            amountMoney -= basePrice;
    }
    ++numSales;
}

Trying to set the total and tax fields of the sale object are getting errors in Eclipse:

"Field 'total' cannot be resolved"

I’m not sure why this is or how to fix it. Any help would be appreciated. And yes I’ve added the #include "sale.h" and #include "register.h" where necessary.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T08:31:57+00:00Added an answer on June 6, 2026 at 8:31 am
    1. In your last snippet, you say if(item == 'CREDIT') but this is wrong for many reasons. Single quotes are used only for single characters. ‘item’ is of type ‘ItemType’ which is an enum. You should use if(item == CREDIT) because CREDIT is defined as an enum element. That statement otherwise results in behavior that has nothing to do with what you want it to do.

    2. I think it’s best to keep initialization to the constructor (see listSize).

    3. You cannot access private members from outside the class. You should either externalize some portions of the code to another class, make public functions available that will do that processing with parameters if needed or make friend classes (which I think is frowned upon in most cases since it’s a sign of bad design (aka “I don’t know how to do X so I resort to Y”).

    If you need more help maybe I can come up with some code for you tomorrow, it’s a bit late for today.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.