0 / 0 / 0
Регистрация: 18.06.2021
Сообщений: 2
|
|
1
|
Как сделать красивую таблицу в консоли .С ++
18.06.2021, 14:42. Показов 584. Ответов 1
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
| #include <stdlib.h>
#include <Windows.h>
#include <iostream>
#include <cstdlib>
#include <string.h>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int n;
struct izdat {
int year;
char* name;
char* city;
};
struct book {
char* name;
double cost;
int col_str;
char* avtor;
izdat izdatelstvo;
};
cin >> n;
char* a = new char[101];
book* b = new book[n];
cin.ignore(); // очень важная строка, используется при последовательном вводе чисел после строк
// иначе будет пропускать ввод чисел.
for (int i = 0; i < n; i++) {
cout << "КНИГА " << i + 1 << endl;
cin.getline(a, 100);
b[i].name = a;
cout << "--------------------------------------------------------------------------------------\n";
cout << "|" << setw(20) << "Название" << setw(20) << "|" << setw(20) << b[i].name << setw(20) << "|" << endl;
cout << "--------------------------------------------------------------------------------------\n";
a = nullptr;
a = new char[101];
cin >> b[i].cost;
cout << "--------------------------------------------------------------------------------------\n";
cout << "|" << setw(20) << "Цена" << setw(20) << "|" << setw(20) << b[i].cost << setw(20) << "|" << endl;
cout << "--------------------------------------------------------------------------------------\n";
cin >> b[i].col_str;
cout << "--------------------------------------------------------------------------------------\n";
cout << "|" << setw(20) << "Число страниц" << setw(20) << "|" << setw(20) << b[i].col_str << setw(20) << "|" << endl;
cout << "--------------------------------------------------------------------------------------\n";
cin.ignore();
cin.getline(a, 100);
b[i].avtor = a;
cout << "--------------------------------------------------------------------------------------\n";
cout << "|" << setw(20) << "Автор" << setw(20) << "|" << setw(20) << b[i].avtor << setw(20) << "|" << endl;
cout << "--------------------------------------------------------------------------------------\n";
a = nullptr;
a = new char[101];
cout << "Издательство:" << endl;
cin >> b[i].izdatelstvo.year;
cout << "--------------------------------------------------------------------------------------\n";
cout << "|" << setw(20) << "Год издания" << setw(20) << "|" << setw(20) << b[i].izdatelstvo.year << setw(20) << "|" << endl;
cout << "--------------------------------------------------------------------------------------\n";
cin.ignore();
cin.getline(a, 100);
b[i].izdatelstvo.name = a;
cout << "--------------------------------------------------------------------------------------\n";
cout << "|" << setw(20) << "Название" << setw(20) << "|" << setw(20) << b[i].izdatelstvo.name << setw(20) << "|" << endl;
cout << "--------------------------------------------------------------------------------------\n";
a = nullptr;
a = new char[101];
cout << " Город ";
cin.getline(a, 100);
b[i].izdatelstvo.name = a;
cout << "--------------------------------------------------------------------------------------\n";
cout << "|" << setw(20) << "Год издания" << setw(20) << "|" << setw(20) << b[i].izdatelstvo.name << setw(20) << "|" << endl;
cout << "--------------------------------------------------------------------------------------\n";
a = nullptr;
a = new char[101];
}
cout << "Результат:" << endl;
for (int i = 0; i < n; i++) {
if (b[i].cost > 100) {
cout << b[i].avtor << endl;
}
}
return 0;
} |
|
0
|