Speaking to a (Geometric) Vector

• In the connection of geometry, a vector comprises of 2 focuses: a begin and a completion • Each point itself has a x and y coordinate

Speaking to a (Geometric) Vector

• Our representation in this way? Utilize 4 copies (startx, starty, endx, endy) • We have to pass every one of the 4 pairs to works

int principle() { twofold xStart = 1.2; twofold xEnd = 2.0; twofold yStart = 0.4; twofold yEnd = 1.6; }

void printVector(double x0, twofold x1, twofold y0, twofold y1) { cout << "(" << x0 << "," << y0 << ") - > (" << x1 << "," << y1 << ")" << endl; }

int fundamental() { twofold xStart = 1.2; twofold xEnd = 2.0; twofold yStart = 0.4; twofold yEnd = 1.6; printVector(xStart, xEnd, yStart, yEnd);/(1.2,2.0) - > (0.4,1.6) }

void offsetVector(double &x0, twofold &x1, twofold &y0, twofold &y1, twofold offsetX, twofold offsetY) { x0 += offsetX; x1 += offsetX; y0 += offsetY; y1 += offsetY; }

void printVector(double x0, twofold x1, twofold y0, twofold y1) { cout << "(" << x0 << "," << y0 << ") - > (" << x1 << "," << y1 << ")" << endl; }

int fundamental() { twofold xStart = 1.2; twofold xEnd = 2.0; twofold yStart = 0.4; twofold yEnd = 1.6; offsetVector(xStart, xEnd, yStart, yEnd, 1.0, 1.5); printVector(xStart, xEnd, yStart, yEnd);/(2.2,1.9) - > (3.8,4.3) } Many variables being gone to works

class

• A client characterized datatype which assembles together related bits of data

class definition language structure

name

class Vector { open: twofold xStart; twofold xEnd; twofold yStart; twofold yEnd; };

• This shows the new datatype we're characterizing is called Vector

class definition language structure

class Vector { open: twofold xStart; twofold xEnd; twofold yStart; twofold yEnd; };

fields

• Fields show what related bits of data our datatype comprises of – Another word for field is individuals

Fields can have diverse sorts

class MITStudent { open: burn *name; int studentID; };

Cases

• A case is an event of a class. Diverse occasions can have their own arrangement of qualities in their fields. • If you needed to speak to 2 unique understudies (who can have distinctive names and IDs), you would utilize 2 cases of MITStudent

Proclaiming an Instance • Defines 2 cases of MITStudent: one called student1, the other called student2

class MITStudent { open: roast *name; int studentID; };

int fundamental() { MITStudent student1; MITStudent student2; }

Getting to Fields • To get to fields of examples, use variable.fieldName

class MITStudent { open: roast *name; int studentID; };

int fundamental() { MITStudent student1; MITStudent student2; student1.name = "Geza"; }

Getting to Fields • To get to fields of examples, use variable.fieldName

class MITStudent { open: singe *name; int studentID; };

int principle() { MITStudent student1; MITStudent student2; student1.name = "Geza"; student1.studentID = 123456789; }

Getting to Fields • To get to fields of occasions, use variable.fieldName

class MITStudent { open: singe *name; int studentID; };

int principle() { MITStudent student1; MITStudent student2; student1.name = "Geza"; student1.studentID = 123456789; student2.name = "Jesse"; student2.studentID = 987654321; }

Getting to Fields • To get to fields of occasions, use variable.fieldName

class MITStudent { open: singe *name; int studentID; };

int principle() { MITStudent student1; MITStudent student2; student1.name = "Geza"; student1.studentID = 123456789; student2.name = "Jesse"; student2.studentID = 987654321; cout << "student1 name is" << student1.name << endl; cout << "student1 id is" << student1.studentID << endl; cout << "student2 name is" << student2.name << endl; cout << "student2 id is" << student2.studentID << endl;

• A point comprises of a x and y coordinate • A vector comprises of 2 focuses: a begin and a completion

• A point comprises of a x and y coordinate • A vector comprises of 2 focuses: a begin and a completion

class Vector { open: twofold xStart; twofold xEnd; twofold yStart; twofold yEnd; };

• A point comprises of a x and y coordinate • A vector comprises of 2 focuses: a begin and a completion

class Vector { open: twofold xStart; twofold xEnd; twofold yStart; twofold yEnd; }; Doesn't demonstrate that organizes can be assembled into focuses

• A point comprises of a x and y coordinate • A vector comprises of 2 focuses: a begin and a completion

class Point { open: twofold x; twofold y; };

• A point comprises of a x and y coordinate • A vector comprises of 2 focuses: a begin and a completion

class Point { open: twofold x; twofold y; };

• A point comprises of a x and y coordinate • A vector comprises of 2 focuses: a begin and a completion

class Point { open: twofold x; twofold y; };

class Vector { open: Point begin; Point end; };

Fields can be classes

class Point { open: twofold x, y; };

class Vector { open: Point begin, end; };

int principle() { Vector vec1; }

class Point { open: twofold x, y; };

class Vector { open: Point begin, end; };

int principle() { Vector vec1; vec1.start.x = 3.0; }

class Point { open: twofold x, y; };

class Vector { open: Point begin, end; };

int principle() { Vector vec1; vec1.start.x = 3.0; vec1.start.y = 4.0; vec1.end.x = 5.0; vec1.end.y = 6.0; }

class Point { open: twofold x, y; };

class Vector { open: Point begin, end; };

int principle() { Vector vec1; vec1.start.x = 3.0; vec1.start.y = 4.0; vec1.end.x = 5.0; vec1.end.y = 6.0; Vector vec2; }

class Point { open: twofold x, y; };

class Vector { open: Point begin, end; };

int principle() { Vector vec1; vec1.start.x = 3.0; vec1.start.y = 4.0; vec1.end.x = 5.0; vec1.end.y = 6.0; Vector vec2; vec2.start = vec1.start; } • Assigning one occasion to another duplicates all fields

class Point { open: twofold x, y; };

class Vector { open: Point begin, end; };

int principle() { Vector vec1; vec1.start.x = 3.0; vec1.start.y = 4.0; vec1.end.x = 5.0; vec1.end.y = 6.0; Vector vec2; vec2.start = vec1.start; vec2.start.x = 7.0; } • Assigning one occasion to another duplicates all fields

Passing classes to works

• Passing by quality passes a duplicate of the class occasion to the capacity; changes aren't safeguarded

class Point { open: twofold x, y; };

void offsetPoint(Point p, twofold x, twofold y) {/does nothing p.x += x; p.y += y; }

int principle() { Point p; p.x = 3.0; p.y = 4.0; offsetPoint(p, 1.0, 2.0);/does nothing cout << "(" << p.x << "," << p.y << ")";/(3.0,4.0) }

Passing classes to works

• When a class occasion is gone by reference, changes are reflected in the first

class Point { open: twofold x, y; };

void offsetPoint(Point &p, twofold x, twofold y) {/works p.x += x; p.y += y; }

int principle() { Point p; p.x = 3.0; p.y = 4.0; offsetPoint(p, 1.0, 2.0);/works cout << "(" << p.x << "," << p.y << ")";/(4.0,6.0) }

Gone by reference

class Point { open: twofold x, y; };

Point class, with fields x and y

class Point { open: twofold x, y; }; class Vector { open: Point begin, end; };

Fields can be classes

class Point { open: twofold x, y; }; class Vector { open: Point begin, end; };

int principle() { Vector vec; }

vec is an occasion of Vector

class Point { open: twofold x, y; }; class Vector { open: Point begin, end; };

int principle() { Vector vec; vec.start.x = 1.2; }

Getting to fields

class Point { open: twofold x, y; }; class Vector { open: Point begin, end; };

int principle() { Vector vec; vec.start.x = 1.2; vec.end.x = 2.0; vec.start.y = 0.4; vec.end.y = 1.6; }

class Point { open: twofold x, y; }; class Vector { open: Point begin, end; };

void printVector(Vector v) { cout << "(" << v.start.x << "," << v.start.y << ") - > (" << v.end.x << "," << v.end.y << ")" << endl; }

int fundamental() { Vector vec; vec.start.x = 1.2; vec.end.x = 2.0; vec.start.y = 0.4; vec.end.y = 1.6; printVector(vec);/(1.2,0.4) - > (2.0,1.6) } classes can be gone to works

class Point { open: twofold x, y; }; class Vector { open: Point begin, end; };

void printVector(Vector v) { cout << "(" << v.start.x << "," << v.start.y << ") - > (" << v.end.x << "," << v.end.y << ")" << endl; }

int fundamental() { Vector vec; vec.start.x = 1.2; vec.end.x = 2.0; vec.start.y = 0.4; vec.end.y = 1.6; printVector(vec);/(1.2,0.4) - > (2.0,1.6) }

Can go to esteem on the off chance that you don't have to change the class

class Point { open: twofold x, y; }; class Vector { open: Point begin, end; };

void offsetVector(Vector &v, twofold offsetX, twofold offsetY) { v.start.x += offsetX; v.end.x += offsetX; v.start.y += offsetY; v.end.y += offsetY; } void printVector(Vector v) { cout << "(" << v.start.x << "," << v.start.y << ") - > (" << v.end.x << "," << v.end.y << ")" << endl; }

int primary() { Vector vec; vec.start.x = 1.2; vec.end.x = 2.0; vec.start.y = 0.4; vec.end.y = 1.6; offsetVector(vec, 1.0, 1.5); printVector(vec);/(2.2,1.9) - > (3.8,4.3) }

Pass classes by reference in the event that they should be altered

• Observe how a few capacities are nearly connected with a specific class

void offsetVector(Vector &v, twofold offsetX, twofold offsetY); void printVector(Vector v);

int primary() { Vector vec; vec.start.x = 1.2; vec.end.x = 2.0; vec.start.y = 0.4; vec.end.y = 1.6; offsetVector(vec, 1.0, 1.5); printVector(vec); }

Vector vec; vec.start.x = 1.2; vec.end.x = 2.0; vec.start.y = 0.4; vec.end.y = 1.6; vec.print();

Strategy name

• Observe how a few capacities are nearly connected with a specific
 
Top