User Profile
Collapse
-
I'm trying to find out, thats why I am asking. Would you like RAII instead.... -
Resource Acquisition as Initialization Technique
Can anybody help me understand how to implement this technique on a sample question please?
thanks -
if I put it outside the block, it would reset it even if I don't want it to....Leave a comment:
-
I ve noticed that when I write an if statement, because I only want it it reset "if asked for a reset". It doesn't work. But without the if statement it works. Why is that? How do make it work? I want to make the declaration inside the if block to be global. How do I do that?...Leave a comment:
-
Resetting a class
Lets say I have a class, which creates object and variables. In main how do I reset that class to null, as if it was (the class run for the first time) first run, but without exitting the main? -
Assigning from a vector of objects to a variable
I am storing previously entered values of a,b,c in a vector as you can see below. Later the user has the option to use one the objects from the vector, and assigns the value to the variables, which therefore are entered using the old values. But the problem is the object assigned are meaningless numbers(i.e. 32252355). How can I get the value of one of the old 'a'(eg. a of that particular slot) and assigned to the new 'a'?
...Code:#include
-
Thanks for your reply Raghura, it compiles :)
However the function AFunc() has been removed, so as I understand, nothing is push_back() into the vector. I've tried to display the contents of the vector, but it doesn't work.
How can I call the print function of the AClass from main, also I want to be able to push values into the vector from main. To make things simpler for now I am trying to push the values 1,2,3. But since the...Leave a comment:
-
Template
Why is this code giving error? How do I fix it?
...Code:#include <iostream> #include <vector> using namespace std; template <class A, typename B> class AClass { private: vector<A> aVector; public: void AFunc(A t1) { aVector.push_back(t1); } }; class BClass { private: int a,b,c; public: -
Hi, finally I've managed to display the contents, but it seems wrong.
...Code:#include <iostream> #include <vector> using namespace std; template <typename avar, typename bvar, typename cvar> class AClass { public: avar var1; bvar var2; cvar var3; AClass (const avar& v1, const bvar& v2, const cvar& v3) : var1(v1),Leave a comment:
-
Thank you very much Laharl for so many of the responses, I really appreciate it. After so many questions I am embarassed to ask, how I can do what you said. Can you show the syntax or the necessary implementation to display the contents of the vector?
regards,
John...Leave a comment:
-
I've tried as you said, and now it compiles, thanks! :). But how do I get it to view the contents of the vector? Here what I've done:
...Code:#include <iostream> #include <vector> using namespace std; template <typename avar, typename bvar, typename cvar> class AClass { public: avar var1; bvar var2; cvar var3; AClass (const avar& v1, const bvar&Leave a comment:
-
...Code:#include <iostream> #include <vector> using namespace std; template <typename avar, typename bvar, typename cvar> class AClass { public: avar var1; bvar var2; cvar var3; AClass (const avar& var1, const bvar& var2, const cvar& var3): avar(var1), bvar(var2), cvar(var3) {} void forward(const AClassLeave a comment:
-
Thanks for your response dear friend. Here is my code:...Code:#include <iostream> #include <vector> using namespace std; template <typename avar, typename bvar, typename cvar> class AClass { public: avar var1; bvar var2; cvar var3; AClass (const avar& var1, const bvar& var2, const cvar& var3): avar(var1), bvar(var2), cvar(var3) {}Leave a comment:
-
I've tried to make the changes as you have suggested. But I don't know how to specialize the template as you have said.
Here is the code:...Code:template <typename avar, typename bvar, typename cvar> class AClass { public: avar var1; bvar var2; cvar var3; AClass (const avar& var1, const bvar& var2, const cvar& var3): avar(var1), bvar(var2), cvar(var3) {}Leave a comment:
-
thanks for your reply,
I have modified it now, but it still gets an error. I haven't been able to write the function to go back in the vector. Here is my code:...Code:template <typename avar, typename bvar, typename cvar> class AClass { public: avar var1; bvar var2; cvar var3; AClass (const avar& var1, const bvar& var2, const cvar& var3): avar(var1), bvar(var2),Leave a comment:
-
Vector Template of type Class
How do I write a template with three typename variables, so that from main I can use that template as a vector, to add and later go back or go forward in the vector and then view the content of the vector in that location?
Here what I've came up with
...Code:template <typename avar, typename bvar, typename cvar> class AClass { public: avar var1; bvar var2; cvar var3; -
Urgent Please Help
Hi, thanks for the replies. I've managed to fix somethings yet I still have a very minor problem, and I'm running out of time.
I have been able to display the value 0.5000001 as 0.5 using this:
Yet now even though I have done this, for some reason after certain additions it ends up as a number like 0.79. I thought of doing the math.round...Code:double x1= (int)((x* 100)) / 100.0;
Leave a comment:
-
Thanks for your reply. I've manage to display the money as I want now. One quick question:
since I'm using the values for calculations and I don't know the problem, can I use this to compare values with d:
My code is almost complete. But heres the last part.Code:double d = (int)((d1 * 100)) / 100.0;
*This is for giving change(money). The vending machine should not dispense the product if the...Leave a comment:
-
Adding and Displaying Double Values in Java
I'm trying to add two values. When adding money it very simple when its 50p+20p=70p. But if I add £1 then I face a problem because 70+1=71 wrong. So I tried to enter £1 as 100p so I have 170p. But here the problem I want to output it as £1.70 instead. So if I divide 170 by 100 I get 1.70
But here yet another problem. I divided the total by 100. So now when I enter 30p it adds to 1.70+30=31.70 (wrong again).
So my approach... -
Hi,
Thanks for helping get started guys. I guess I got a little panicked, but I've been able to make some progress. Now though I'm stuck and was wondering if you could help me out.
I'm using a multiple array for this vending machine program. Though I'm not sure. Should one dimensional array be enough. Also, with this program the user should be able to buy the drink by selecting its slot number. So how do I write the...Leave a comment:
No activity results to display
Show More
Leave a comment: