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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:29:19+00:00 2026-06-14T11:29:19+00:00

class foo{ public: double v1, v2, v3; double x, y; foo(const double &a){ set_var();

  • 0
class foo{

public:
    double v1, v2, v3;
    double x, y;

    foo(const double &a){
        set_var();

        x = a;

        if(a == v1)
            y = 1;
        else if(a == v2)
            y = 0;
        else if(a == v3)
            y = 2;
    }

    void set_var(){
        // v1, v2 and v3 will always be the same values as the corresponding double values
        // that foo a,b and c are being set to in main()
        v1 = 1.4;
        v2 = 1.4;
        v3 = 1.4;
    }

};

And in the main function:

main(){
    foo a = 1.2, b = 1.2, c = 1.2;
}

Essentially, what I want this code to do when we are trying to set ‘foo a, b, c’ to the same double value (and hence ‘v1, v2, v3’ are the same value as well) is foo a=1.4 gives a.y=1,
foo b=1.4 gives b.y=0, and foo c=1.4 gives c.y=2

in short pseudocode. Basically, ‘foo a’ should always use the first if clause, ‘foo b’ should always use the second, and ‘foo c’ should always use the third.

As part of this assignment, I MUST implement the main function in that way. It cannot be changed.

My first thought was that even if I’m trying to set foo a,b,c to the same double, that double always takes up a different place in memory, no? So maybe I could somehow pass in the address of double &x in the constructor? Then set that address to represent v1, v2 and v3 instead of using those variables in the first place?

I just need to get the code to do what I outlined a couple of paragraphs above even when the double values are equal.

  • 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-14T11:29:20+00:00Added an answer on June 14, 2026 at 11:29 am

    Since it appears that your question is in regards to a homework assignment, I’m going to point you in the direction of static member variables which are, in short, class variables that are shared between all instances of a given class. You can use one or more of these variables to track the progress of the instantiation of your instances.

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

Sidebar

Related Questions

class foo { public: void say_type_name() { std::cout << typeid(this).name() << std::endl; } };
class Foo { public: void bar(); }; void Foo::bar() { static int n =
public class Foo { public static void main(String[] args) { float f; System.out.println(f); }
Consider the following template class class MyClassInterface { public: virtual double foo(double) = 0;
class Foo { public: explicit Foo(double item) : x(item) {} operator double() {return x*2.0;}
Consider the following setup: I am given an interface template<class T> void FooClass<T>::foo(boost::function<double (int)>
I would like to do something like this class foo{ private: double a,b; public:
class Foo(){ public List<string> SomeCollection; } I need to implement an event which can
class Foo { public static IEnumerable<int> Range(int start, int end) { return Enumerable.Range(start, end);
class Foo { public: Foo() { Foo(1)} Foo(int x, int y = 0):i(x) {}

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.