
- •Void print();
- •Include.H
- •Void Point::set_Point_x( double _x)
- •Void Point::set_Point_y( double _y)
- •Void print ();
- •Void Cube::Draw()
- •Void Cube::square(double r)
- •Int main()
- •Include "targetver.H"
- •If(!p1.InBounds() || !p2.InBounds())
- •If(!temp.UperLeftCorner.InBounds() || !temp.LowerRightConer.InBounds())
- •If(!temp.UperLeftCorner.InBounds() || !temp.LowerRightConer.InBounds())
- •If(!temp.LowerRightConer.InBounds())
- •If(!p2.InBounds())
- •If(!temp.LowerRightConer.InBounds())
Void Point::set_Point_x( double _x)
{
x=_x;
return;
}
Void Point::set_Point_y( double _y)
{
y=_y;
return;
}
double Point::get_Point_x() const
{
return x;
}
double Point::get_Point_y() const
{
return y;
}
Stdafx.h
#pragma once
#include <stdio.h>
#include <tchar.h>
#include <conio.h>
#include <iostream>
#include <ctime>
using namespace std;
class Point
{
private:
double x;
double y;
public:
Point(); //конструктор по умолчанию
Point(const double _x, const double _y); //конструктор с параметрами
Point(const Point& _P); //конструктор копирования
~Point(); //деструктор
void set_Point(const double _x, const double _y);
double get_Point_x()const;
double get_Point_y()const;
void set_Point_y(double _y);
void set_Point_x( double _y);
};
class Ellips
{
private:
Point a;
Point b;
char *name;
double S;
public:
static int created;
Ellips();
Ellips(Point , Point );
Ellips (const Ellips & );
~Ellips();
double square();
Void print ();
void extend_a(Point);
void extend_b(Point);
};
void initialize( double&,double&,double&,double&);
void func(Ellips* ell, Point& ext);
Вариант 4
7.1.1
Класс «Квадрат». Выяснить, можно ли вписать в объект-квадрат со стороной a окружность радиуса r. Если можно, то вычислить площадь квадрата и площадь круга, ограниченного вписанной окружностью.
Figure.cpp
#include "Figure.h"
int Cube::counter=0;
Cube::Cube() : A(0,0),B(1,0), a(1)
{
number=counter++;
}
Cube::Cube(const Point& P1, const Point& P2): A(P1), B(P2)
{
number=counter++;
double dx_AB = B.GetX()-A.GetX();
double dy_AB = B.GetY()-A.GetY();
a = sqrt(dx_AB*dx_AB+dy_AB*dy_AB);
}
Cube::Cube(const Cube& P): A(P.A),B(P.B), a(P.a)
{
number=counter++;
}
Void Cube::Draw()
{
double Dx, Dy, Cx, Cy;
cout << " Cube " << number << endl;
cout << " A = (" << A.GetX()<< ", " << A.GetY() << endl;
cout << " B = (" << B.GetX()<< ", " << B.GetY() << endl;
/*cout << " " << endl;
for(int i=0;i<int(Dx); i++)
cout << endl;
for(int i=0;i<int(D.GetX()); i++)
cout << ' ';
cout<<'*';
for(int i=0;i<int(C.GetX()); i++)
cout << ' ';
cout<<'*';
for(int i=0;i<int(A.GetY()); i++)
cout << endl;
for(int i=0;i<int(A.GetX()); i++)
cout << ' ';
cout<<'*';
for(int i=0;i<int(B.GetX()); i++)
cout << ' ';
cout<<'*';
*/
}
Void Cube::square(double r)
{
if (abs(r-a/2) < a*1e-6)
{
double c=3.14*(a/2)*(a/2);
double d=a*a;
S=d-c;
cout << "S(kruga)=" << c << endl << "S(kvadrata)="<< d << endl << "S(kvadrat-krug)=" << S << endl;
}
else cout << "Vpisat' okrujnost' s takim radiusom nel'zya "<< endl;
return;
}
Figure.h
#ifndef FIGURE_H
#define FIGURE_H
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
using namespace std;
class Point
{
private:
double x, y;
public:
Point(double x1 = 0, double y1 = 0) : x(x1), y(y1) {}
Point(const Point& P)
{
x = P.x;
y = P.y;
}
double GetX() const
{
return x;
}
double GetY() const
{
return y;
}
void SetX(double x)
{
this->x = x;
}
void SetY(double y)
{
this->y = y;
}
};
class Cube
{
private:
Point A, B;
double a;
double S;
static int counter;
int number;
public:
Cube();
Cube(const Point& P1, const Point& P2);
Cube(const Cube& C);
void square(double r);
void Draw();
};
void func(Cube* cub);
#endif
Main.cpp
#include <iostream>
#include <conio.h>
using namespace std;
#include "Figure.h"
int main()
{
Cube p;
Cube P1(Point(0,5), Point(5,5));
Cube p2(P1);
double r;
cout << "Risuyu Kub #1" << endl;
P1.Draw();
p2.Draw();
p.Draw();
cout << " Vvedite r" << endl;
cin >> r;
P1.square(r);
_getch();
//func(& P1);
_getch();
return 0;
}
Вариант 5
7.1.1
Класс «Ромб». Выполнить растяжение исходного объекта-ромба увеличением его стороны в два раза. Вычислить периметр исходного и растянутого ромбов-объектов.
Main.cpp
#include "stdafx.h"
#include "targetver.h"