User Profile

Collapse

Profile Sidebar

Collapse
JohnSmith70
JohnSmith70
Last Activity: May 19 '08, 12:33 AM
Joined: Oct 30 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • I'm trying to find out, thats why I am asking. Would you like RAII instead....
    See more | Go to post

    Leave a comment:


  • JohnSmith70
    started a topic Resource Acquisition as Initialization Technique
    in C

    Resource Acquisition as Initialization Technique

    Can anybody help me understand how to implement this technique on a sample question please?

    thanks
    See more | Go to post

  • JohnSmith70
    replied to Resetting a class
    in C
    if I put it outside the block, it would reset it even if I don't want it to....
    See more | Go to post

    Leave a comment:


  • JohnSmith70
    replied to Resetting a class
    in C
    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?...
    See more | Go to post

    Leave a comment:


  • JohnSmith70
    started a topic Resetting a class
    in C

    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?
    See more | Go to post

  • JohnSmith70
    started a topic Assigning from a vector of objects to a variable
    in C

    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
    ...
    See more | Go to post

  • JohnSmith70
    replied to Template
    in C
    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...
    See more | Go to post

    Leave a comment:


  • JohnSmith70
    started a topic Template
    in C

    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:
    ...
    See more | Go to post

  • JohnSmith70
    replied to Vector Template of type Class
    in C
    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),
    ...
    See more | Go to post

    Leave a comment:


  • JohnSmith70
    replied to Vector Template of type Class
    in C
    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...
    See more | Go to post

    Leave a comment:


  • JohnSmith70
    replied to Vector Template of type Class
    in C
    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&
    ...
    See more | Go to post

    Leave a comment:


  • JohnSmith70
    replied to Vector Template of type Class
    in C
    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 AClass
    ...
    See more | Go to post

    Leave a comment:


  • JohnSmith70
    replied to Vector Template of type Class
    in C
    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) {}
    ...
    See more | Go to post

    Leave a comment:


  • JohnSmith70
    replied to Vector Template of type Class
    in C
    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) {}
    ...
    See more | Go to post

    Leave a comment:


  • JohnSmith70
    replied to Vector Template of type Class
    in C
    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),
    ...
    See more | Go to post

    Leave a comment:


  • JohnSmith70
    started a topic Vector Template of type Class
    in C

    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;
    ...
    See more | Go to post

  • 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:

    Code:
    double x1= (int)((x* 100)) / 100.0;
    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...
    See more | Go to post

    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:

    Code:
    double d = (int)((d1 * 100)) / 100.0;
    My code is almost complete. But heres the last part.

    *This is for giving change(money). The vending machine should not dispense the product if the...
    See more | Go to post

    Leave a comment:


  • JohnSmith70
    started a topic Adding and Displaying Double Values in Java
    in Java

    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...
    See more | Go to post

  • JohnSmith70
    replied to Vending machine program
    in Java
    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...
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...