Results 1 to 5 of 5

Thread: C++

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date: Jun:2005
    Location: Sofia
    Posts: 12

    C++

    , , , ( , ) : , - . .

  2. #2
    Pesho's Avatar
    Join Date: Nov:2001
    Location: Sofia
    Posts: 5,169
    Code:
    struct Vector 
    {
        double x, y;
    
        Vector(double x = 0, double y = 0) : x(x), y(y) { }
    };
    
    Vector operator+(const Vector& lhs, const Vector& rhs) 
    {
        return Vector(lhs.x + rhs.x, lhs.y + rhs.y);
    }
    [bg] [/bg]

    ... -:

    Code:
        Vector a(5, 10);
        Vector b(15, 20);
    
        Vector c = a + b;

  3. #3
    ɐ-əpoɔᴉu⋂ ɐ ə anrieff's Avatar
    Join Date: Apr:2004
    Location: Sofia
    Posts: 8,448
    - : :
    Code:
    #include <iostream>
    #include <sstream>
    using namespace std;
    
    template <int _size>
    class GenericVector {
    	double v[_size];
    public:
    	GenericVector(const char *init = "")
    	{
    		int i = 0;
    		double t;
    		stringstream ss(init);
    		while (i < _size && ss >> t) {
    			v[i++] = t;
    		}
    		while (i < _size)
    			v[i++] = 0.0;
    	}
    
    	GenericVector operator + (const GenericVector & r)
    	{
    		GenericVector bla;
    		for (int i = 0; i < _size; i++) {
    			bla.v[i] = v[i] + r.v[i];
    		}
    		return bla;
    	}
    	void print() const
    	{
    		cout << "(";
    		for (int i = 0; i < _size; i++)
    			cout  << v[i] << (i < _size-1?", ":"");
    		cout << ")" << endl;
    	}
    };
    , GenericVector<3>. :
    Code:
    	GenericVector<3> a("5 -3 10");
    	GenericVector<3> b("6 0 -12");
    	GenericVector<3> c = a + b;
    	c.print();

    Code:
    (11, -3, -2)
    , . .
    "640K ught to be enough for anybody" - Bill Gates, 1981
    ::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel

  4. #4
    Registered User
    Join Date: Jun:2005
    Location: Sofia
    Posts: 12
    ?

  5. #5
    Registered User singularity's Avatar
    Join Date: Apr:2003
    Location:
    Posts: 3,382
    .
    Last edited by singularity; 12th April 2007 at 14:05. Reason:
    ignore list:Java,velio,jaredharet,gochev.george,Nit rogenium
    Quis custodiet ipsos custodes?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |