Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //№1 на семинар по информатике и программированию. Написать перегрузку функции distance()
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- struct Point_flat {
- double x, y;
- Point_flat(double x, double y) {
- this->x = x;
- this->y = y;
- }
- void print_flat() {
- cout << "x = " << x << "; y = " << y << endl;
- }
- };
- struct Point_izohor {
- double x, y, z;
- Point_izohor(double x, double y, double z) {
- this->x = x;
- this->y = y;
- this->z = z;
- }
- void print_izohor() {
- cout << "x = " << x << "; y = " << y << "; z = " << z << endl;
- }
- };
- double distance(double x, double y) {
- return sqrt(x * x + y * y);
- }
- double distance(double x, double y, double z) {
- return sqrt(x * x + y * y + z * z);
- }
- double distance(double x1, double y1, double x2, double y2) {
- return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
- }
- double distance(double x1, double y1, double z1, double x2, double y2, double z2) {
- return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2) + pow(z1 - z2, 2));
- }
- double distance(Point_flat p) {
- return sqrt(p.x * p.x + p.y * p.y);
- }
- double distance(Point_izohor p) {
- return sqrt(p.x * p.x + p.y * p.y + p.z * p.z);
- }
- int main() {
- double x, y, z;
- cout << "Enter coordinates for the point from struct Point_flat: ";
- cin >> x >> y;
- Point_flat p1(x, y);
- cout << "Enter coordinates for the point from struct Point_izohor: ";
- cin >> x >> y >> z;
- Point_izohor p2(x, y, z);
- cout << "Enter coordinates for distance(x, y): ";
- cin >> x >> y;
- cout << "Current distance is " << distance(x, y) << endl;
- cout << "Enter coordinates for distance(x, y, z): ";
- cin >> x >> y >> z;
- cout << "Current distance is " << distance(x, y, z) << endl;
- double x2, y2, z2;
- cout << "Enter coordinates for distance(x1, y1, x2, y2): ";
- cin >> x >> y >> x2 >> y2;
- cout << "Current distance is " << distance(x, y, x2, y2) << endl;
- cout << "Enter coordinates for distance(x1, y1, z1, x2, y2, z2): ";
- cin >> x >> y >> z >> x2 >> y2 >> z2;
- cout << "Current distance is " << distance(x, y, z, x2, y2, z2) << endl;
- cout << "Coordinates of the point from struct Point_flat: ";
- p1.print_flat();
- cout << "Current distance is " << distance(p1) << endl;
- cout << "Coordinates of the point from struct Point_izohor: ";
- p2.print_izohor();
- cout << "Current distance is " << distance(p2) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement