-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex10.cpp
More file actions
88 lines (76 loc) · 2.32 KB
/
Copy pathex10.cpp
File metadata and controls
88 lines (76 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// По условию задания необходимо написать класс с именем ship, который будет
// содержать данные об учетном номере корабля и координатах его расположения,
// разработать метод, который будет сохранять в объекте данные о корабле,
// вводимые пользователем, и метод, выводящий данные о корабле на экран.
#include <iostream>
using namespace std;
class angle {
private:
int degrees;
float minutes;
char direction;
public:
void input();
void displayAngle()const;
};
class ship {
private:
angle latitude, longitude;
static int count;
unsigned int serialNumber;
public:
ship() {
++count;
serialNumber = count;
}
void getPosition();
void displayShip() const;
};
int ship::count = 0;
void angle::input() {
cout <<"\nВведите градусы: ";
cin >> degrees;
cout <<"Введите минуты: ";
cin >> minutes;
cout <<"Введите направление (N, S, E, W): ";
cin >> direction;
}
void angle::displayAngle()const {
cout << degrees << '\xF8' << minutes << "\' " << direction;
}
void ship::getPosition() {
cout << "Введите широту корабля:";
latitude.input();
cout << "Введите долготу корабля:";
longitude.input();
}
void ship::displayShip()const {
cout << "Номер корабля: " << serialNumber;
cout << endl;
latitude.displayAngle();
cout << " ";
longitude.displayAngle();
cout << endl;
}
int main() {
ship ship1, ship2, ship3;
cout << "Введите координаты первого корабля" << endl;
ship1.getPosition();
cout << endl;
cout << "Введите координаты второго корабля" << endl;
ship2.getPosition();
cout << endl;
cout << "Введите координаты третьего корабля" << endl;
ship3.getPosition();
cout << endl;
cout << "Корабль 1:" << endl;
ship1.displayShip();
cout << endl;
cout << "Корабль 2:" << endl;
ship2.displayShip();
cout << endl;
cout << "Корабль 3:" << endl;
ship3.displayShip();
cout << endl;
return 0;
}