Частина тексту файла (без зображень, графіків і формул):
МІНІСТЕРСТВО ОСВІТИ І НАУКИ УКРАЇНИ
НАЦІОНАЛЬНИЙ УНІВЕРСИТЕТ “ЛЬВІВСЬКА ПОЛІТЕХНІКА”
ЗВІТ ДО ЛАБОРАТОРНОЇ РОБОТИ № 2
З КУРСУ “АЛГОРИТМІЧНІ МОВИ І ПРОГРАМУВАННЯ”
ЗАВДАННЯ
Написати програму алгоритмічною мовою С++ згідно із завданням, отриманим від викладача за табл. 1. Реалізувати заданий класовий тип із заданими методами, використовуючи механізм перевантаження функцій та операцій, а також значення параметрів за замовчуванням. Написати фрагмент програми з використанням класового типу та заданих методів.
Зміст звіту
Завдання.
Блок-схеми алгоритмів функцій.
Текст програми.
Результат виконання програми.
Таблиця 1
№ п/п
Класовий тип
Методи класу
6
Прямокутник зі сторонами a і b
Конструктор повинен дозволяти ініціалізацію прямокутника і спрощену ініціалізацію квадрата. Визначення площі. Перевантажити операції ==, <, >, виводу <<, вводу >>, а також дружню операцію *=<тип>.
Блок-схема алгоритму
ОСТАТОЧНА ВЕРСІЯ ПРОГРАМИ
#include <iostream>
#include <cstdlib>
class rectangle
{
public:
rectangle();
rectangle(double);
rectangle(double, double);
void print();
friend void operator*=(rectangle &, int);
bool operator==(rectangle &);
bool operator>(rectangle &);
bool operator<(rectangle &);
void operator<<(double);
void operator>>(rectangle &);
private:
double a;
double b;
double square;
};
using namespace std;
void operator *= (rectangle &, int);
int main(){
rectangle rec1(6),
rec2(9,5),
rec3(6,8);
if (rec1>rec2) //porivnyanya ploshch rec1 ta rec2
cout << "Rectangle 1 have more square than Rectangle 2" << endl;
if (rec1<rec2) //porivnyanya ploshch rec1 ta rec2
cout << "Rectangle 2 have more square than Rectangle 1" << endl;
rec3>>rec1; //storonu ta ploshcha rec1 prusvojujetsya rec3;
if (rec1==rec3) //porivnyanya ploshch rec1 ta rec3
cout << "Rectangle 1 = Rectangle 3" << endl;
rec2<<2; //mnozhut` ploshchu rec2 na 2 ta prusvojuje storoni a znachenya
//square/b
rec2.print(); //vuvid haracterustuk pryamokutnuka
rec2*=(int)8.5; //mnoshut` ploshchu rec2 na 8 ta prusvojuje
//storoni a znachenya square/b
rec2.print();
system("pause");
return 0;
}
rectangle::rectangle()
{
a = b = square;
}
rectangle::rectangle(double side){
a = b = side;
square = a*a;
}
rectangle::rectangle(double side1, double side2){
a = side1;
b = side2;
square = a*b;
}
bool rectangle::operator ==(rectangle& r){
if (r.a==this->a && r.b==this->b &&
r.square==this->square)
return true;
else
return false;
}
bool rectangle::operator <(rectangle& r){
if (this->square<r.square)
return true;
else
return false;
}
bool rectangle::operator>(rectangle& r){
if (this->square>r.square)
return true;
else
return false;
}
void rectangle::operator>>(rectangle& r){
this->a=r.a;
this->b=r.b;
this->square=r.square;
}
void rectangle::operator<<(double sqr){
this->square=sqr;
this->a=sqr/this->b;
}
void rectangle::print(){
cout << endl;
cout << "Rectangle:" << endl
<< "a = " << a << endl
<< "b = " << b << endl
<< "square = " << square << endl;
}
void operator*=(rectangle &r, int d){
r.square *= d;
r.a = r.square/r.b;
}
Результат роботи програми