问题描述
我是 C++ 编程的初学者。我需要为电影预订系统创建一个程序。我已经做到了一半,但我一直在选择座位。我需要像用户必须选择座位一样对其进行编程。用户可以循环选择座位约10次。选择它后,所有数据都应存储在文本文件中,并存储在我存储有关特定电影的信息的行中。我真的希望对这个问题有一个好的建议。这是我安排文本文件的方式:
Avengers|1600|40|16
LoST World|3200|40|16
Titanic|6897|87|16
Avengers|1600|40|16
#include<iostream>
#include<cmath>
#include<fstream>
using namespace std;
display_all()
{
char name [25];
char hours[25];
char seats[25];
fstream movie;
movie.open("Movies.txt",ios::in);
int count = 0;
string line;
ifstream file("Movies.txt");
while (getline(file,line))
count++;
int i = 0;
while(!movie.eof(),i++,i<= count)
{
movie.getline(name,25,'|');
movie.getline(seats,'|');
movie.getline(hours,25);
cout<< "(" << i << ") " << name << "\n ";
}
return 0;
}
main()
{
char name [25];
char hours[25];
char seats[25];
char price[25];
char seats1[25];
char seats2[25];
char seats3[25];
char seats4[25];
char seats5[25];
char response = 'Y';
string customer,phone_number;
fstream movie;
movie.open("Movies.txt",ios::in);
char selection_role ;
int selection_movie ;
cout << " *************************************************************** " << endl;
cout << " MOVIE TICKET RESERVATION SYstem (MTRS) " << endl;
cout << " *************************************************************** " << endl;
cout << endl << endl ;
cout << " Please specify the selection : (1) CUSTOMER" << endl;
cout << " (2) MANAGEMENT" << endl;
cout << endl;
cout << " INPUT : ";
cin >> selection_role;
if (selection_role == 1);
cout << endl;
cout << "MOVIES AVAILABLE : ";
display_all();
cout << endl;
cout << "Please select a movie: ";
cin >> selection_movie ;
int i = 0;
while(i++,i <= selection_movie)
{
movie.getline(name,'|');
movie.getline(seats,'|');
movie.getline(hours,'|');
movie.getline(price,'|');
}
cout << endl;
cout << "======You have selected " << name <<".=========" <<endl;
cout << endl;
cout << "Movie hours: " << seats << endl;
cout << "Number of seats available: " << hours << endl;
cout << " SCREEN "<<endl << endl;
cout << "1 2 3 4 5 6 7 8" <<endl << endl;
cout << "9 10 11 12 13 14 15 16"<<endl << endl;
cout << "17 18 19 20 21 22 23 24"<<endl << endl;;
cout << "25 26 27 28 29 30 31 32"<<endl << endl;
cout << "Enter the number of seat you would like to book for: ";
cin >> seats1 ;
cout << endl;
cout << "Price for the ticket: RM " << price << endl << endl;
cout << "Enter you name: " ;
cin >> customer ;
cout << "Enter your phone number: ";
cin >> phone_number;
cout << endl;
cout << " MOVIE TICKET " << endl;
cout << "============================" << endl;
cout << "Name :" << customer << endl;
cout << "Handphone number :" << phone_number <<endl;
cout << "Movie selected :" << name << endl;
cout << "Seat selected :" << seats1 <<"," << seats2 << endl;
cout << "Price for the movie(RM):" << price << endl;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)