• Предмет: Информатика
  • Автор: anastasiyafomina353
  • Вопрос задан 5 месяцев назад

С++ Перетворіть код функції так, щоб було редагування запису за окремими полями.

void EditInput(const char* fn){
Handmade a;
int amount = AmountTovar(fn);
char otv;
int num;
regex string_1("([A-Z]{2})([0-9]{2})([_]{1})([0-9]{4})([_]{1})([0-9]{3})");
regex string_2("[A-Za-zА-Яа-я -]+");
regex string_3("[A-Za-zА-Яа-я ]*");
do {
do {
cout << "Введiть номер запису: ";
cin >> num;
if (num > 0 && num <= amount) {
break;
}
else {
cout << "Некоректне введення! Будь ласка, введiть iснуючий номер запису." << endl;
}
} while (true);

fopen_s(&handmade_store, fn, "rb");
fseek(handmade_store, (num - 1) * sizeof(Handmade), SEEK_SET);
fread(&a, sizeof(Handmade), 1, handmade_store);
fclose(handmade_store);
Hat();
cout << "| " << setw(3) << right << num << " "
<< "| " << setw(14) << left << a.code << " "
<< "| " << setw(26) << left << a.tovar << " "
<< "| " << setw(13) << left << a.category << " "
<< "| " << setw(17) << left << a.oznaka << " "
<< "| " << setw(8) << right << a.len << " "
<< "| " << setw(9) << right << a.num << " "
<< "| " << setw(17) << left << a.country << " "
<< "| " << setw(9) << right << a.cost << " "
<< " |" << endl;
Line();
cout << "Бажаєте редагувати цей запис? (т/н): ";
cin >> otv;
cin.ignore();
if (otv == 'т')
{
do {
cout << endl << "Введiть код товару (за схемою ЛЛЦЦ_ЦЦЦЦ_ЦЦЦ, де Л - лiтера, Ц - цифра): ";
cin.getline(a.code, 15);
if (regex_match(a.code, string_1)) {
break;
}
else
cout << "Некоректне введення!" << endl;
} while (true);

do {
cout << "Введiть назву товару: ";
cin.getline(a.tovar, 27);
if (regex_match(a.tovar, string_2)) {
break;
}
else cout << "Некоректне введення! Введіть рядок, що містить літери!" << endl;
} while (true);

do {
cout << "Введiть категорiю товару: ";
cin.getline(a.category, 14);
if (regex_match(a.category, string_3)) {
break;
}
else cout << "Введіть рядок, що містить тільки літери!" << endl;
} while (true);

do {
cout << "Введiть колір: ";
cin.getline(a.oznaka, 18);
if (regex_match(a.oznaka, string_2)) {
break;
}
else cout << "Некоректне введення! Введіть рядок, що містить літери!" << endl;
} while (true);

do {
cout << "Введiть довжину в метрах: ";
cin >> a.len;
if (a.len <= 0 a.len > 1000) {
cout << "Некоректне введення! Значення довжини має бути бiльше 0 та до 1 000 метрів." << endl;
}
else break;
} while (true);

do {
cout << "Введiть кiлькiсть товару: ";
cin >> a.num;
if (a.num <= 0 a.num > 10000) {
cout << "Введiть коректне значення! Значення кiлькостi має бути бiльше 0 та до 10 000." << endl;
}
else break;
} while (true);
cin.ignore();
do {
cout << "Введіть країну-виробника: ";
cin.getline(a.country, 18);
if (regex_match(a.country, string_3)) {
break;
}
else cout << "Некоректне введення! Введіть рядок, що містить тільки літери!" << endl;
} while (true);

do {
cout << "Введiть цiну товару (грн.): ";
cin >> a.cost;
if (a.cost <= 0 || a.cost > 100000) {
cout << "Введiть коректне значення! Значення цiни має бути бiльше 0 та до 100 000 грн." << endl;
}
else break;
} while (true);

if (!SameRecords(a, fn))
{
fopen_s(&handmade_store, fn, "r+b");
fseek(handmade_store, (num - 1) * sizeof(Handmade), SEEK_SET);
fwrite(&a, sizeof(Handmade), 1, handmade_store);
fclose(handmade_store);
}
}
cout << "Бажаєте продовжити(т/н): ";
cin >> otv;
} while (otv == 'т');
}​

Ответы

Ответ дал: ov34
0

Ответ:

void EditInput(const char* fn){

Handmade a;

int amount = AmountTovar(fn);

char otv;

int num;

regex string_1("([A-Z]{2})([0-9]{2})([]{1})([0-9]{4})([]{1})([0-9]{3})");

regex string_2("[A-Za-zА-Яа-я -]+");

regex string_3("[A-Za-zА-Яа-я ]*");

do {

do {

cout << "Enter the record number: ";

cin >> num;

if (num > 0 && num <= amount) {

break;

}

else {

cout << "Incorrect input! Please enter an existing record number." << endl;

}

} while (true); fopen_s(&handmade_store, fn, "rb");

fseek(handmade_store, (num - 1) * sizeof(Handmade), SEEK_SET);

fread(&a, sizeof(Handmade), 1, handmade_store);

fclose(handmade_store);

Hat();

cout << "| " << setw(3) << right << num << " "

<< "| " << setw(14) << left << a.code << " "

<< "| " << setw(26) << left << a.tovar << " "

<< "| " << setw(13) << left << a.category << " "

<< "| " << setw(17) << left << a.oznaka << " "

<< "| " << setw(8) << right << a.len << " "

<< "| " << setw(9) << right << a.num << " "

<< "| " << setw(17) << left << a.country << " "

<< "| " << setw(9) << right << a.cost << " "

<< " |" << endl;

Line();

cout << "Do you want to edit this record? (y/n): ";

cin >> otv;

cin.ignore();

if (otv == 'y') {

do {

cout << endl << "Enter the product code (in the format LLCC_CCCC_CCC, where L - letter, C - digit): ";

cin.getline(a.code, 15);

if (regex_match(a.code, string_1)) {

break;

}

else

cout << "Incorrect input!" << endl;

} while (true);

do {

cout << "Enter the product name: ";

cin.getline(a.tovar, 27);

if (regex_match(a.tovar, string_2)) {

break;

}

else cout << "Incorrect input! Enter a string containing letters!" << endl;

} while (true);

do {

cout << "Enter the product category: ";

cin.getline(a.category, 14);

if (regex_match(a.category, string_3)) {

break;

}

else cout << "Enter a string containing only letters!" << endl;

} while (true);

do {

cout << "Enter the color: ";

cin.getline(a.oznaka, 18);

if (regex_match(a.oznaka, string_2)) {

break;

}

else cout << "Incorrect input! Enter a string containing letters!" << endl;

} while (true);

do {

cout << "Enter the length in meters: ";

cin >> a.len;

if (a.len <= 0 || a


anastasiyafomina353: Вы просто перевели мой код?
Вас заинтересует