Работы по программированию

This commit is contained in:
IgorVolochay
2026-07-28 09:56:54 +03:00
parent b85155ff95
commit 8602b7e845
73 changed files with 4090 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
+58
View File
@@ -0,0 +1,58 @@
{
"files.associations": {
"iosfwd": "cpp",
"iostream": "cpp",
"atomic": "cpp",
"bit": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"exception": "cpp",
"format": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"ios": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"locale": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"ratio": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"system_error": "cpp",
"thread": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"utility": "cpp",
"xfacet": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xutility": "cpp",
"vector": "cpp"
}
}
+28
View File
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "D:\\mingw\\MinGW\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
+81
View File
@@ -0,0 +1,81 @@
/*
1.Постоянный ввод целых чисел. «0» – конец ввода, или пока не закончится файл. Найти:
- количество чисел;
- минимальное, максимальное и среднее значения;
- количество положительных и отрицательных чисел.
результат вывести на экран/в файл
*/
#include <iostream>
#include <fstream>
class Task {
private:
struct Statistic {
int count = 0;
int minimum = INT_MAX;
int maximum = INT_MIN;
int summary = 0;
int positive = 0;
int negative = 0;
double average = 0;
} _statistic;
int _number;
std::ifstream _file_in;
std::ofstream _file_out;
void _setStatistic() {
while (_file_in >> _number) {
if (_number == 0)
break;
_statistic.count++;
_statistic.summary += _number;
if (_number < _statistic.minimum)
_statistic.minimum = _number;
if (_number > _statistic.maximum)
_statistic.maximum = _number;
if (_number > 0)
_statistic.positive++;
if (_number < 0)
_statistic.negative++;
}
_statistic.average = static_cast<double>(_statistic.summary) / _statistic.count;
}
public:
Task(const std::string filename_input = "input.txt", const std::string filename_output = "output.txt") {
_file_in.open(filename_input);
_file_out.open(filename_output);
if (!_file_in.is_open() || !_file_out.is_open()) {
std::cerr << "Ошибка открытия файла" << std::endl;
exit(1);
}
_setStatistic();
}
~Task() {
_file_in.close();
_file_out.close();
}
void writeData() {
_file_out << "Количество чисел: " << _statistic.count << std::endl;
_file_out << "Минимальное значение: " << _statistic.minimum << std::endl;
_file_out << "Максимальное значение: " << _statistic.maximum << std::endl;
_file_out << "Среднее значение: " << _statistic.average << std::endl;
_file_out << "Количество положительных чисел: " << _statistic.positive << std::endl;
_file_out << "Количество отрицательных чисел: " << _statistic.negative << std::endl;
}
};
int main() {
Task task;
task.writeData();
return 0;
}
+108
View File
@@ -0,0 +1,108 @@
/*
2.Разработать класс Rectangle, обладающий следующим функционалом:
- задание сторон вручную/ из файла
- задание сторон координатами вручную/ из файла
- вычисление площади – вывод на экран / в файл
- вычисление периметра – вывод на экран / в файл
- вывод на экран / в файл:
a = …, b = …., P =…, S = …
или
(x1, y1) = …, (x2, y2) = …, P = …, S = …
*/
#include <cmath>
#include <fstream>
#include <iostream>
#include <vector>
class Rectangle {
private:
std::ifstream _file_in;
std::ofstream _file_out;
struct RectangleData {
int width, height;
int perimetr, area;
int x1, y1;
int x2, y2;
} _rectangleData;
bool _isCoordinate;
void _init(const std::string filename_input,
const std::string filename_output) {
_file_in.open(filename_input);
_file_out.open(filename_output);
if (!_file_in.is_open() || !_file_out.is_open()) {
std::cerr << "Ошибка открытия файла" << std::endl;
exit(1);
}
}
void _setWidthHeightfromXY() {
_rectangleData.width = abs(_rectangleData.y2 - _rectangleData.y1);
_rectangleData.height = abs(_rectangleData.x2 - _rectangleData.x1);
}
void _setPerimetr() {
_rectangleData.perimetr =
(_rectangleData.width + _rectangleData.height) * 2;
}
void _setArea() {
_rectangleData.area = _rectangleData.width * _rectangleData.height;
}
public:
Rectangle(const std::string filename_input = "input.txt",
const std::string filename_output = "output.txt") {
_init(filename_input, filename_output);
std::vector<int> buffer;
int number;
while (_file_in >> number) {
buffer.push_back(number);
}
const int length = buffer.size();
_isCoordinate = (length == 4) ? true : false;
if (_isCoordinate) {
_rectangleData.x1 = buffer[0];
_rectangleData.y1 = buffer[1];
_rectangleData.x2 = buffer[2];
_rectangleData.y2 = buffer[3];
_setWidthHeightfromXY();
} else {
_rectangleData.width = buffer[0];
_rectangleData.height = buffer[1];
}
_setPerimetr();
_setArea();
}
void writeData() {
if (_isCoordinate) {
_file_out << "(x1, y1) = (" << _rectangleData.x1 << ", "
<< _rectangleData.y1 << "), (x2, y2) = ("
<< _rectangleData.x2 << ", " << _rectangleData.y2 << ")";
} else {
_file_out << "a = " << _rectangleData.width
<< ", b = " << _rectangleData.height;
}
_file_out << ", "
<< "P = " << _rectangleData.perimetr << ", "
<< "S = " << _rectangleData.area;
}
};
int main() {
Rectangle rect;
rect.writeData();
return 0;
}
Binary file not shown.
+2
View File
@@ -0,0 +1,2 @@
0 0
5 2
+1
View File
@@ -0,0 +1 @@
(x1, y1) = (0, 0), (x2, y2) = (5, 2), P = 14, S = 10