Ребята, помогите программу переделать, нужно char везде сделать динамическим. Уже битый час бьюсь, догадаться не могу, как все перелопатить. #include #include #include #include
void main(void) { setlocale(LC_ALL, "Russian"); #define kol 4 int choice; char menu[kol][100]={"1. Добавить информацию о рейсе", "2. Время вылета самолетов в город X", "3. Наличие свободных мест в город X с временем Y", "4. Выход"}; do { system("cls"); for(int i = 0; i < kol; i++) cout << menu[ i ] << endl; cout << "Ваш выбор: "; cin >> choice; system("cls"); switch(choice) { case 1: add_Info(); break; case 2: show_Plane(); break; case 3: show_numFreeSits(); break; default: ; } } while(choice != 4); }
#include
#include
#include
#include
using namespace std;
struct staff
{
char id[100];
char city[100];
char startTime[100];
char endTime[100];
int sits;
};
void add_Info()
{
staff buf;
ofstream f("lab.dat", ios::app);
char s[100];
memset(&buf, 0, sizeof(staff));
cout << "Введите информацию: "<<endl;
cout << "tномер рейса: ";
cin.getline(s, sizeof(s));
cin.getline(s, sizeof(s));
strcpy(buf.id, s);
cout << "tгород: ";
cin.getline(s, sizeof(s));
strcpy(buf.city, s);
cout << "tвремя вылета: ";
cin.getline(s, sizeof(s));
strcpy(buf.startTime, s);
cout << "tвремя прибытия: ";
cin.getline(s, sizeof(s));
strcpy(buf.endTime, s);
cout<<"tКоличество мест : ";
cin>>buf.sits;
f.write((char *)&buf, sizeof(staff));
f.close();
}
void show_numFreeSits()
{
staff buf;
char city[100], startTime[100];
cout << "Введите город: ";
cin.getline(city, sizeof(city));
cin.getline(city, sizeof(city));
cout << "Введите время вылета: ";
cin.getline(startTime, sizeof(startTime));
ifstream f("lab.dat");
for(;;)
{
memset(&buf, 0, sizeof(staff));
f.read((char *)&buf, sizeof(staff));
if (f.eof())
break;
if((*buf.city == *city) && (*buf.startTime == *startTime))
cout << "Город: " << buf.city << endl << "Вылет: " << buf.startTime << endl << "Места: " << buf.sits;
}
f.close();
cout << "nnPress any key to continue...";
getch();
}
void show_Plane()
{
staff buf;
char city[100];
ifstream f("lab.dat");
cout << "Введите город: ";
cin.getline(city, sizeof(city));
cin.getline(city, sizeof(city));
system("cls");
for(;;)
{
memset(&buf, 0, sizeof(staff));
f.read((char *)&buf, sizeof(staff));
if(f.eof())
break;
if(*buf.city == *city)
cout << "Город: " << buf.city << endl << "Вылет: " << buf.startTime << endl;
}
f.close();
cout << "nnPress any key to continue...";
getch();
}
void main(void)
{
setlocale(LC_ALL, "Russian");
#define kol 4
int choice;
char menu[kol][100]={"1. Добавить информацию о рейсе",
"2. Время вылета самолетов в город X",
"3. Наличие свободных мест в город X с временем Y",
"4. Выход"};
do
{
system("cls");
for(int i = 0; i < kol; i++)
cout << menu[ i ] << endl;
cout << "Ваш выбор: ";
cin >> choice;
system("cls");
switch(choice)
{
case 1:
add_Info();
break;
case 2:
show_Plane();
break;
case 3:
show_numFreeSits();
break;
default: ;
}
}
while(choice != 4);
}