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 8588997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:56:17+00:00 2026-06-11T22:56:17+00:00

This is correct code from a classmate the professor bragged about and I cant

  • 0

This is correct code from a classmate the professor bragged about and I cant understand why it requires a double constructor i originally only had the first function and couldnt figure out it required two which lagged my progress as a professional

class Studentrecords
{
private:

    struct student
    {
        string name;
        string address;
        int ID;
        double gpa;
    };

    student *stackArray;
    int stackSize;
    int top;

public:
    Studentrecords();
    Studentrecords(int size);
    ~Studentrecords();
    void push(string name, string address, int id, double gpa);
    void pop();
    bool isFull() const;
    bool isEmpty() const;
    void display();
};

Studentrecords::Studentrecords(int size)
{
    stackArray = new student[size];
    top = 0;
}

Studentrecords::Studentrecords()
{
    stackSize = 25;
    stackArray = new student[stackSize];
    top = 0;
}

Studentrecords::~Studentrecords()
{
    delete [] stackArray;
}
  • 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-11T22:56:19+00:00Added an answer on June 11, 2026 at 10:56 pm

    It doesn’t require two constructors, that’s just how the class is defined. That way, you can create an object in two ways:

    Studentrecords s(15);
    

    which will create a Studentrecords object of size 15, or

    Studentrecords s;
    

    which will call the default constructor, and create an object of type Studentrecords and size 25.

    I must note that this is bad code though:

    • The default Studentrecords() constructor can be replaced with Studentrecords(int size = 25) to avoid code duplication.
    • no use of initializer lists
    • you’re managing memory in the class, which means you’d need a copy constructor and copy assignment operator
    • finally, you’re using a C-style array instead of a std::vector.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to prevent generated code from producing duplicate. Is this correct way to
Is this code correct? I'm trying to submit it and also I would like
Is this code correct? std::function<int(int)> f = [&f](int n) -> int { return n
Why is this code correct: try { } catch(ArrayOutOfBoundsException e) {} and this wrong:
this code is correct?? String note = text.txt; FileWriter file = new FileWriter(note); Scanner
When I execute this code the user is correct but the pass is not,
Is this piece of code where I lock a part of the function correct?
i use this code in my app. just found is not correct when compare
Could you please explain why this code is not syntactically correct? private void addEditor(final
I've got this really simple piece of code that I thought was the correct

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.