Без проблем.
Файл Computer_control.cpp
| C++ | 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
| #define _CRT_SECURE_NO_WARNINGS
#pragma warning(suppress : 4996)
#include "Computer_control.h"
#include <iostream>
#include"Controller.h"
#include <string>
Computer_control::Computer_control()
{
strcpy(name, "No name");
int price = 0;
bool wired = true;
controller type = mouse;
}
Computer_control::Computer_control(Computer_control& seed)
{
set_name(seed.get_name());
price = seed.get_price();
wired = seed.get_wired();
type = seed.get_type();
}
Computer_control::~Computer_control()
{
delete[]name;
}
char * Computer_control::get_name() const
{
return name;
}
int Computer_control::get_price() const
{
return price;
}
bool Computer_control::get_wired() const
{
return wired;
}
controller Computer_control::get_type() const
{
return type;
}
void Computer_control::set_name(char * seed)
{
if (name)
delete[]name;
int size=0;
name = new char[size];
for (int i = 0; seed[i]!='\0'; i++)
name[i] = seed[i];
}
void Computer_control::set_price(int seed)
{
price = seed;
}
void Computer_control::set_wired(bool seed)
{
wired = seed;
}
void Computer_control::set_type(controller seed)
{
type = seed;
}
void Computer_control::input()
{
std::cout << "Enter is wired (Yes/No)";
std::cin >> name;
if (name == "Yes")
wired = true;
else wired = false;
std::cout << "Enter type (mouse/keyboatd/joystic/touchscreen: ";
std::string tmp;
std::cin >> tmp;
if (tmp == "mouse") type = mouse;
else if (tmp == "keyboatd") type = keyoard;
else if (tmp == "joystic") type = joystic;
else if (tmp == "touchscreen") type = tochscreen;
std::cout << "Enter price: ";
std::cin >> price;
std::cout << "Enter name: ";
std::cin >> name;
std::cout << std::endl;
}
void Computer_control::show()const
{
std::cout << "Controlling device. \n";
std::cout << "name: " << name << ", price = " << price << ", type: ";
switch (type)
{
case controller::mouse:
std::cout << "mouse";
break;
case controller::keyoard:
std::cout << "keybord";
break;
case controller::joystic:
std::cout << "joystic";
break;
case controller::gamepad:
std::cout << "gamepad";
break;
case controller::tochscreen:
std::cout << "touchscreen";
break;
default:
std::cout << "unknow";
break;
}
if (wired) std::cout << ", wired";
else std::cout << ", wireless";
std::cout << std::endl;
} |
|
Keyboard.cpp
| C++ | 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
| #define _CRT_SECURE_NO_WARNINGS
#pragma warning(suppress : 4996)
#include "Keyboard.h"
#include <iostream>
Keyboard::Keyboard()
{
strcpy(name, "No name");
int price = 0;
bool wired = true;
controller type = keyoard;
fullsized = true;
}
Keyboard::Keyboard(Keyboard& seed)
{
strcpy(name, seed.name);
int price = seed.price;
bool wired = seed.wired;
controller type = seed.type;
fullsized = seed.fullsized;
}
Keyboard::~Keyboard()
{
}
bool Keyboard::get_fullsized() const
{
return fullsized;
}
void Keyboard::set_fullsized(bool seed)
{
fullsized = seed;
}
void Keyboard::input()
{
std::cout << "Enter is wired (Yes/No)";
std::cin >> name;
if (name == "Yes")
wired = true;
else wired = false;
std::cout << "Enter price: ";
std::cin >> price;
std::cout << "Enter is fullsized (Yes/No)";
std::cin >> name;
if (name == "Yes")
fullsized = true;
else fullsized = false;
std::cout << "Enter name: ";
std::cin >> name;
std::cout << std::endl;
}
void Keyboard::show() const
{
std::cout << "Keyboard. \n";
std::cout << "name: " << name << ", price = " << price << ", type: keyboard";
if (wired) std::cout << ", wired";
else std::cout << ", wireless";
if (fullsized) std::cout << ", fullsized";
else std::cout << ", shorted";
std::cout << std::endl;
} |
|
Mechanical_keyboard.cpp
| C++ | 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
| #include "Mechanical_keyboard.h"
#include <iostream>
Mechanical_keyboard::Mechanical_keyboard()
{
strcpy(name, "No name");
int price = 0;
bool wired = true;
controller type = keyoard;
fullsized = true;
color_switch = Red;
}
Mechanical_keyboard::Mechanical_keyboard(Mechanical_keyboard& seed)
{
strcpy(name, seed.name);
int price = seed.price;
bool wired = seed.wired;
controller type = seed.type;
fullsized = seed.fullsized;
color_switch = seed.color_switch;
}
Mechanical_keyboard::~Mechanical_keyboard()
{
delete[] name;
}
void Mechanical_keyboard::set_switch(switch_type seed)
{
color_switch = seed;
}
void Mechanical_keyboard::input()
{
std::cout << "Enter is wired (Yes/No)";
std::cin >> name;
if (name == "Yes")
wired = true;
else wired = false;
std::cout << "Enter price: ";
std::cin >> price;
std::cout << "Enter is fullsized (Yes/No)";
std::cin >> name;
if (name == "Yes")
fullsized = true;
else fullsized = false;
std::cout << "Enter sype of switch: ";
std::cin >> name;
if (name == "Black") color_switch = Black;
else if (name == "Red") color_switch = Red;
else if (name == "Silent Red") color_switch = Silent_Red;
else if (name == "Silent Black") color_switch = Silent_Black;
else if (name == "Speed Silver") color_switch = Speed_Silver;
else if (name == "Blue") color_switch = Blue;
else if (name == "Green") color_switch = Green;
else if (name == "Brown") color_switch = Brown;
else if (name == "Clear") color_switch = Clear;
else if (name == "Grey") color_switch = Grey;
std::cout << "Enter name: ";
std::cin >> name;
std::cout << std::endl;
}
void Mechanical_keyboard::show() const
{
std::cout << "Mechanical keyboard. \n";
std::cout << "name: " << name << ", price = " << price << ", type: keyboard";
if (wired) std::cout << ", wired";
else std::cout << ", wireless";
if (fullsized) std::cout << ", fullsized";
else std::cout << ", shorted";
std::cout << ", type of switch: ";
switch (color_switch)
{
case Black:
std::cout << "Black";
break;
case Red:
std::cout << "Black";
break;
case Silent_Red:
std::cout << "Black";
break;
case Silent_Black:
std::cout << "Black";
break;
case Speed_Silver:
std::cout << "Red";
break;
case Blue:
std::cout << "Silent_Red";
break;
case Green:
std::cout << "Silent_Black";
break;
case Brown:
std::cout << "Brown";
break;
case Clear:
std::cout << "Clear";
break;
case Grey:
std::cout << "Grey";
break;
default:
std::cout << "Error";
break;
}
std::cout << std::endl;
}
switch_type Mechanical_keyboard::get_switch() const
{
return color_switch;
} |
|
Mouse.cpp
| C++ | 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
| #include "Mouse.h"
#include <iostream>
Mouse::Mouse()
{
strcpy(name, "No name");
int price = 0;
bool wired = true;
controller type = keyoard;
dpi = 0;
}
Mouse::Mouse(Mouse& seed)
{
strcpy(name, seed.name);
int price = seed.price;
bool wired = seed.wired;
controller type = seed.type;
dpi = seed.dpi;
}
Mouse::~Mouse()
{
delete[]name;
}
int Mouse::get_dpi() const
{
return dpi;
}
void Mouse::set_dpi(int seed)
{
dpi = seed;
}
void Mouse::input()
{
std::cout << "Enter is wired (Yes/No)";
std::cin >> name;
if (name == "Yes")
wired = true;
else wired = false;
std::cout << "Enter price: ";
std::cin >> price;
std::cout << "Enter DPI: ";
std::cin >> dpi;
std::cout << "Enter name: ";
std::cin >> name;
std::cout << std::endl;
}
void Mouse::show() const
{
std::cout << "Mouse. \n";
std::cout << "name: " << name << ", price = " << price << ", type: ";
switch (type)
{
case controller::mouse:
std::cout << "mouse";
break;
case controller::keyoard:
std::cout << "keybord";
break;
case controller::joystic:
std::cout << "joystic";
break;
case controller::gamepad:
std::cout << "gamepad";
break;
case controller::tochscreen:
std::cout << "touchscreen";
break;
default:
std::cout << "unknow";
break;
}
if (wired) std::cout << ", wired";
else std::cout << ", wireless";
std::cout << "DPI = " << dpi;
std::cout << std::endl;
} |
|
Source.cpp
| C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| #include <iostream>
#include "I_Computer_control.h"
#include "Static_vector.h"
#include "Keyboard.h"
#include "Mouse.h"
using namespace std;
void main() {
Static_vector arr(5);
for (int i = 0; i < 5; i += 2) {
Keyboard tmp();
arr.set(i, *tmp);
}
system("pause");
} |
|
Static_vector.cpp
| C++ | 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
| #include "Static_vector.h"
#include <iostream>
Static_vector::Static_vector() {
}
Static_vector::Static_vector(int size)
{
this->size = size;
first = new Node;
Node* tmp = first;
tmp->prew = nullptr;
tmp->data = nullptr;
for (int i = 1; !out_of_range(i); i++) {
tmp->next = new Node;
tmp->next->prew = tmp;
tmp->next->data = nullptr;
tmp = tmp->next;
}
tmp->next = nullptr;
}
Static_vector::~Static_vector() {
if (empty()) return;
Node* tmp = first->next;
while (tmp) {
delete[]tmp->prew->data;
delete[]tmp->prew;
tmp = tmp->next;
}
}
bool Static_vector::empty()const {
if (first == nullptr || first == NULL)
return true;
else return false;
}
void Static_vector::set(int number, void*data) {
int i;
if (out_of_range(number)) {
std::cout << "Error! Out of range"; //проверка, не слишком ли большое число
return;
}
Node* tmp = first;
for (i = 0; i < number; i++) { //нахождение нужного нода
tmp = tmp->next;
}
tmp->data = data;
tmp->number = i;
}
void* Static_vector::get(int number)const {
if (out_of_range(number)) {
std::cout << "Error! Out of range"; //проверка, не слишком ли большое число
return nullptr;
}
Node* tmp = first;
for (int i = 0; i < number; i++) { //нахождение нужного нода
tmp = tmp->next;
}
return tmp->data;
}
void Static_vector::show()const {
Node* tmp = first;
std::cout << "\nall of vector: ";
while (tmp) {
std::cout << tmp->data << ' ';
tmp = tmp->next;
}
}
bool Static_vector::out_of_range(int x)const {
if (x >= size) {
return 1;
}
else return 0;
}
int Static_vector::search(void* searched)const {
Node* tmp = first;
for (int i = 0; !out_of_range(i); i++)
if (tmp->data == searched)
return i;
else tmp = tmp->next;
return -1;
}
void Static_vector::swap(Node* x, Node* y) {
Node* z = new Node;
z->data = x->data;
x->data = y->data;
y->data = z->data;
delete[]z;
}
void Static_vector::sort(increase direction) {
Node* tmp1 = first, *tmp2 = first->next;
while (tmp1->next) {
while (tmp2) {
if (tmp1->data < tmp2->data ^ direction) {
swap(tmp1, tmp2);
tmp2 = tmp2->next;
}
else tmp2 = tmp2->next;
}
tmp1 = tmp1->next;
tmp2 = tmp1->next;
}
} |
|
I_Computer_control.h
| C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
| #include "Controller.h"
class I_Computer_control
{
public:
virtual char* get_name() = 0;
virtual int get_price()const = 0;
virtual bool get_wired()const = 0;
virtual controller get_type()const = 0;
virtual void input() = 0;
virtual void show()const = 0;
}; |
|
Computer_control.h
| C++ | 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
| #pragma once
#include "I_Computer_control.h"
#include "Controller.h"
class Computer_control:public I_Computer_control
{
private:
char* name;
int price;
bool wired;
controller type;
public:
Computer_control();
Computer_control(Computer_control& seed);
~Computer_control();
char* get_name()const;
int get_price()const;
bool get_wired()const;
controller get_type()const;
void set_name(char* seed);
void set_price(int seed);
void set_wired(bool seed);
void set_type(controller seed);
virtual void input();
virtual void show()const;
}; |
|
Controller.h
| C++ | 1
2
3
4
5
6
7
8
9
| #pragma once
enum controller {
mouse,
keyoard,
joystic,
gamepad,
tochscreen
}; |
|
Keyboard.h
| C++ | 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
| #pragma once
#include "Computer_control.h"
class Keyboard : public Computer_control
{
private:
char* name;
int price;
bool wired;
controller type;
bool fullsized;
public:
Keyboard();
Keyboard(Keyboard& seed);
~Keyboard();
char* get_name()const;
int get_price()const;
bool get_wired()const;
controller get_type()const;
bool get_fullsized()const;
void set_name(char* seed);
void set_price(int seed);
void set_wired(bool seed);
void set_type(controller seed);
void set_fullsized(bool seed);
virtual void input();
virtual void show()const;
}; |
|
Mechanical_keyboard.h
| C++ | 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
| #pragma once
#include "Keyboard.h"
#include "switch_type.h"
class Mechanical_keyboard : public Keyboard
{
private:
char* name;
int price;
bool wired;
controller type;
bool fullsized;
switch_type color_switch;
public:
Mechanical_keyboard();
Mechanical_keyboard(Mechanical_keyboard &seed);
~Mechanical_keyboard();
char* get_name()const;
int get_price()const;
bool get_wired()const;
controller get_type()const;
bool get_fullsized()const;
switch_type get_switch()const;
void set_name(char* seed);
void set_price(int seed);
void set_wired(bool seed);
void set_type(controller seed);
void set_fullsized(bool seed);
void set_switch(switch_type seed);
virtual void input();
virtual void show()const;
}; |
|
Mouse.h
| C++ | 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
| #pragma once
#include "Computer_control.h"
class Mouse : public Computer_control
{
private:
char* name;
int price;
bool wired;
controller type;
int dpi;
public:
Mouse();
Mouse(Mouse& seed);
~Mouse();
char* get_name()const;
int get_price()const;
bool get_wired()const;
controller get_type()const;
int get_dpi()const;
void set_name(char* seed);
void set_price(int seed);
void set_wired(bool seed);
void set_type(controller seed);
void set_dpi(int seed);
virtual void input();
virtual void show()const;
}; |
|
Static_vector.h
| C++ | 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
| #pragma once
#include "I_Computer_control.h"
class Static_vector
{
private:
struct Node
{
Node* next, *prew;
int number = 0;
void* data;
};
Node* first = nullptr;
int size;
public:
enum increase { down, up };
Static_vector();
Static_vector(int size);
~Static_vector();
bool empty()const;
void set(int number, void* data);
void* get(int number)const;
int get_size()const;
void show()const;
bool out_of_range(int x)const;
void swap(Node* x, Node* y);
int search(void* searched)const;
void sort(increase direction = up);
}; |
|
switch_type.h
| C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| #pragma once
enum switch_type
{
Black,
Red,
Silent_Red,
Silent_Black,
Speed_Silver,
Blue,
Green,
Brown,
Clear,
Grey
}; |
|
0
|