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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:59:33+00:00 2026-05-16T20:59:33+00:00

I am taking a quadratic expression, where y=ax^2 + bx + c with a

  • 0

I am taking a quadratic expression, where y=ax^2 + bx + c with a,b,c are constants and x is a variable. Here is my class:

class quadratic {
public:
double evaluate(const double x);
void getCoefficients (double &A, double &B, double &C);
void setCoefficients (const double A, const double B, const double C);

private:
double a;
double b;
double c;
};

I am to create TWO constructors for the class so that the following is legal

quadratic y1 = quadratic(1.0, -5.0, 7.0);
quadratic y2 = quadratic(-3.0, -2.0, 10.0);
quadratic y3;

The default constructor should be set to zero while the parameters in the second constructor indicate initial values for the coefficients.

Here is how I believe I should do that:

quadratic()   //default values
{
double A, double B, double C = 0.0;
}

quadratic(double A, double B, double C)   //initial values
{
double A = double a;
double B = double b;
double C = double c;
}

However I’m not fully understanding how to set this up and would appreciate any gurus help in figuring this out.

  • 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-05-16T20:59:34+00:00Added an answer on May 16, 2026 at 8:59 pm

    You should probably use the constructors’ initializer list instead:

    quadratic() : a(0), b(0), c(0)
    {
    }
    
    quadratic(double A, double B, double C) : a(A), b(B), c(C)
    {
    }
    

    The above uses a part of the C++ language to initialize member variables called an initializer list.


    What you did for the constructor with parameters:

    double A = double a;
    double B = double b;
    double C = double c;
    

    First of all won’t compile, but even if you simplify what you did to:

    double A = a;
    double B = b;
    double C = c;
    

    Then it is still won’t compile because A, B, and C are already defined. When you put a type name followed by a variable name like the above, it will try to create a new variable.

    So if we simplify again to:

    A = a;
    B = b;
    C = c;
    

    Then this is still wrong again but at least it will compile. It’s wrong because you are setting the parameters to the value of the uninitialized class variables.

    Instead you want:

    a = A;
    b = B;
    c = C;
    

    What you did for the constructor without parameters:

     double A, double B, double C = 0.0;
    

    This won’t compile. The right syntax to declare many variables in a single line is as follows:

     double A = 0, B = 0, C = 0;
    

    But this is still not correct, it will simply create 3 new variables A, B, and C and initialize them to 0. What you really want is to set your member variables a,b, and c.

    So you want:

    a = b = c = 0;

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

Sidebar

Related Questions

Taking my first steps with Rx I am stuck here: public class DisposableResourceDemo :
Taking the following object model: public abstract class Entity { public Guid Id {
Taking for example this method declaration: const Vector Vector::operator - ( const Vector& other
Taking a PHP array of terms with variable length (i.e. it could be 50
Taking a look at my question HERE , I now want to return the
Taking beginning Data Structures in C# class, trying to make a searchable arraylist of
taking the following html: <li> <p> <a href=# class=link ><img src=images/photo_cityguild_cropped.jpg alt=Education title=Education> <span
Taking this thread to the next level and now making a Main.as class to
I am reading on quadratic probing at following link: http://www.brpreiss.com/books/opus5/html/page241.html Here what does author
Taking Fabien Potencier's example : class User { function __construct($storage) { $this->storage = $storage;

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.