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

  • Home
  • SEARCH
  • 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 8149165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:47:40+00:00 2026-06-06T14:47:40+00:00

I am doing a homework assignment for my summer OO class and we need

  • 0

I am doing a homework assignment for my summer OO class and we need to write two classes. One is called Sale and the other is called Register. I’ve written my Sale class; here’s the .h file:

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 

private:
    double price;   // price of item or amount of credit
    double tax;     // amount of sales tax 
    double total;   // final price once tax is added in.
    ItemType item;  // transaction type
};

For the Register class we need to include a dynamic array of Sale objects in our member data.

So my two questions are:

  • Do I need to inherit from my Sale class into my Register class (and if so, how)?
  • Can I have a generic example of a dynamic array?

Edit: We cannot use vectors.

  • 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-06T14:47:40+00:00Added an answer on June 6, 2026 at 2:47 pm

    No, inheritance would not be appropriate in this case. You would want to keep track of the number of sales and the size of the array as fields in the Register class. The class definition would include this

    class Register{
        private:
            int numSales;
            int arraySize;
            Sale* sales;
        public:
            Register();
            ~Register();
            void MakeSale(Sale);        
    };
    
    Register::Register(){
        numSales = 0;
        arraySize = 5;
        sales = new Sale[arraySize];
    }
    void Register::MakeSale(Sale s){
        if(numSales == arraySize){
            arraySize += 5;
            Sale * tempArray = new Sale[arraySize];
            memcpy(tempArray, sales, numSales * sizeof(Sale));
            delete [] sales;
            sales = tempArray;
        }
        sales[numSales] = s;
        ++numSales;
    }
    
    Register::~Register()
    {
        delete [] sales;
    }
    

    This doesn’t include bounds checking or whatever other stuff you need to do when you make a sale, but hopefully this should help.

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

Sidebar

Related Questions

I am doing a homework assignment for my summer OO class and we need
I am doing a homework assignment that deals with classes and objects. In it,
I'm doing a homework assignment in which I need to print out to the
I've got a homework assignment where I have a base class Package, and two
I'm doing a homework assignment for my course in C (first programming course). Part
Doing some homework here (second assignment, still extremely green...). The object is to read
I'm doing a homework in MARS simulator (Assembly) and I'm stuck on one part.
I am doing a little homework assignment in which we are making a very
For a homework assignment, I have to write a MySQL query to calculate the
So I am doing homework and I am stuck on one spot. I have

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.