You are on page 1of 4

LAB 8

Example 7.1 no output


Example 7.2

Example 7.3

Example 7.4

TASK 1: Create a class Point with two data members x, y. Provide appropriate
constructors, get, set and display methods.Create a class Triangle with three Points as its
data members. Provide appropriate constructors for this class and a display method which
calls the display methods of the three Points.In the main function, declare three points and
pass them to the constructor of the class Triangle. Call the display method of Triangle to
verify the coordinates of the triangle.
#include "stdafx.h"
#include<iostream> using
namespace std;
class point
{ private:
int x,y; public:
point():x(0),y(0){} point(int
a, int b):x(a),y(b){} int get_x()
{ return x; }
void set_x(int a) {
x=a; } int get_y()
{ return y; }
void set_y(int b) {
y=b; } void display()
{ cout<<x<<" "<<y<<endl; }};
class triangle { public:
point p1,p2,p3;
triangle():p1(0,0),p2(0,0),p3(0,0){}
triangle(point a,point b,point c)
{ p1=a;
p2=b;
p3=c; }
void display()
{ p1.display();
p2.display();
p3.display(); }};
int _tmain(int argc, _TCHAR* argv[])
{ point s,t,r;
s.set_x(5);
s.set_y(3);
s.get_x();
s.get_y();
t.set_x(1);
t.set_y(2);
t.get_x();
t.get_y();
r.set_x(7);
r.set_y(7);
r.get_x();
r.get_y();
class triangle t1(s,t,r);
t1.display(); system("pause");
return 0; } TASK 2:
MAIN TRIANGLE.h
#include "stdafx.h" #ifndef TRIANGLE_H
#include<iostream> using #define TRIANGLE_H
namespace std; #include #include "point.h" class
"point.h" #include triangle
"triangle.h" { private:
int _tmain(int argc, _TCHAR* argv[]) point p1,p2,p3;
{ class point s,t,r; public:
s.set_x(5); triangle();
s.set_y(3); triangle(point a,point b,point c);
s.get_x();
s.get_y(); void display();
t.set_x(1); };
t.set_y(2); #endif
t.get_x();
t.get_y();
r.set_x(7);
r.set_y(7);
r.get_x();
r.get_y();
class triangle t1(s,t,r);
t1.display();
system("pause");
return 0; }
TRIANGLE.CPP POINT.h
#include "stdafx.h" #ifndef POINT_H #define
#include "triangle.h" #include "point.h" POINT_H
triangle::triangle():p1(0,0),p2(0,0),p3(0,0){} class point {
triangle::triangle(point a,point b,point c) private:
{ this->p1=a; int x,y; public:
this->p2=b; point();
this->p3=c; } point(int a, int b);
void triangle::display() int get_x();
{ p1.display(); void set_x(int a);
p2.display(); int get_y();
p3.display(); } void set_y(int b);
void display(); };
#endif
POINT.cpp
#include "stdafx.h"
#include<iostream>
#include "point.h"
using namespace std;
point::point():x(0),y(0){}
point::point(int a, int b):x(a),y(b){}
int point::get_x()
{ return x; }
void point:: set_x(int a)
{ this->x=a; }
int point::get_y()
{ return y; }
void point::set_y(int b)
{ this->y=b; }
void point::display()
{ cout<<x<<" "<<y<<endl; }

You might also like