Skip to content

Instantly share code, notes, and snippets.

@SPACE-DOGGO
Last active November 19, 2022 09:40
Show Gist options
  • Save SPACE-DOGGO/f5bf6de82f9fea7b282f2b9c944c0c94 to your computer and use it in GitHub Desktop.
Save SPACE-DOGGO/f5bf6de82f9fea7b282f2b9c944c0c94 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
//struct Car
//{
// char color[20];
// char model[20];
// char plate [8] ;
//};
//
//void PrintByIndex(const vector<Car>& b, const size_t index);
//
//int main()
//{
// setlocale(0, "UKR");
// const unsigned int NumberOfElements = 10;
// const string items[] =
// {
// "1. Редактировать",
// "2. Напечатать все",
// "3. Найти по номеру"
// };
//
// unsigned int key;
// unsigned int car_number;
//
// string plate;
//
// vector<Car> cars(NumberOfElements);
//
// for (auto& value : cars)
// {
// cout << "Цвет, модель, номер: ";
// gets_s(value.color);
// gets_s(value.model);
// gets_s(value.plate);
// }
//
//
// while (true)
// {
// for (const auto& value : items)
// {
// cout << value << "\n";
// }
//
// cout << ">> ";
// cin >> key;
//
// switch (key)
// {
// case 1:
// cout << "Номер машины: ";
// cin >> car_number;
// cout << "Новый цвет, модель, номер: ";
// gets_s(cars[car_number].color);
// gets_s(cars[car_number].model);
// gets_s(cars[car_number].plate);
// break;
// case 2:
// for (size_t i = 0; i < NumberOfElements; ++i)
// {
// PrintByIndex(cars, i);
// }
// break;
// case 3:
// cout << "Номер: ";
// cin >> plate;
// for (size_t i = 0; i < NumberOfElements; ++i)
// {
// if (cars[i].plate == plate)
// {
// PrintByIndex(cars, i);
// }
// }
// break;
//
// default:
// break;
// }
// }
//}
//
//void PrintByIndex(const vector<Car>& b, const size_t index)
//{
// cout << "[" << index << "] "
// << b[index].color << " " << b[index].model << " "
// << b[index].plate << " " << "\n";
//}
struct Entity
{
int type;
string color;
string speed;
string charact;
};
void PrintByIndex(const vector<Entity>& b, const size_t index);
int main()
{
setlocale(0, "UKR");
const unsigned int NumberOfElements = 4;
const string items[] =
{
"1. Редактировать",
"2. Напечатать все",
"3. Найти по номеру"
};
unsigned int key;
unsigned int charact;
unsigned int number;
string plate;
vector<Entity> entities(NumberOfElements);
for (auto& value : entities)
{
cout << "Укажите тип сущности (1 - птица, 2 - скот, 3 - человек): ";
cin >> value.type;
switch (value.type)
{
case 1:
{
cout << "Введите цвет, скорость полета: ";
cin >> value.color;
cin >> value.speed;
value.charact = value.speed;
break;
}
case 2:
{
cout << "Введите цвет, скорость: ";
cin >> value.color;
cin >> value.speed;
int temp;
cout << "Парнокопытное (1/0)?\n";
cin >> temp;
if (temp == 1)
{
value.charact = "Парнокопытное";
}
else
{
value.charact = "Непарнокопытное";
}
break;
}
case 3:
{
cout << "Введите цвет, скорость, IQ: ";
cin >> value.color;
cin >> value.speed;
cin >> value.charact;
}
}
}
while (true)
{
for (const auto& value : items)
{
cout << value << "\n";
}
cout << ">> ";
cin >> key;
switch (key)
{
case 1:
{
cout << "Номер сущности: ";
cin >> number;
cout << "Укажите тип сущности (1 - птица, 2 - скот, 3 - человек): ";
cin >> entities[number].type;
switch (entities[number].type)
{
case 1:
{
cout << "Введите цвет, скорость полета: ";
cin >> entities[number].color;
cin >> entities[number].speed;
entities[number].charact = entities[number].speed;
break;
}
case 2:
{
cout << "Введите цвет, скорость: ";
cin >> entities[number].color;
cin >> entities[number].speed;
int temp;
cout << "Парнокопытное (1/0)?\n";
cin >> temp;
if (temp == 1)
{
entities[number].charact = "Парнокопытное";
}
else
{
entities[number].charact = "Непарнокопытное";
}
break;
}
case 3:
{
cout << "Введите цвет, скорость, IQ: ";
cin >> entities[number].color;
cin >> entities[number].speed;
cin >> entities[number].charact;
}
}
break;
}
case 2:
{
for (size_t i = 0; i < NumberOfElements; ++i)
{
PrintByIndex(entities, i);
}
break;
}
case 3:
{
cout << "Характеристика: ";
cin >> plate;
for (size_t i = 0; i < NumberOfElements; ++i)
{
if (entities[i].charact == plate)
{
PrintByIndex(entities, i);
}
}
break;
}
default:
{
break;
}
}
}
}
void PrintByIndex(const vector<Entity>& b, const size_t index)
{
cout << "[" << index << "] "
<< b[index].color << " " << b[index].speed << " "
<< b[index].charact << " " << "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment