vendredi 1 janvier 2021

How to add data to the end of a line in text file in C++?

I am a beginner for C++ programming. I need to a create a program for movie reservation system. I have done it until halfway through but I stuck at selecting he seats. I need to program it like the user must select a seat. The user can select seats for about 10 times in loop. After selecting it, all the data should be stored in the text file and in the line which I have stored the information about the particular movie. I am really hoping for a good suggestion to this problem. This is how I arranged in text file.

Avengers|1600|40|16

LoST World|3200|40|16

Titanic|6897|87|16

Avengers|1600|40|16

#include

#include

#include

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,25,'|');
    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,25,'|');
  movie.getline(seats,25,'|');
  movie.getline(hours,25,'|');
  movie.getline(price,25,'|');
}

  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;

}

Aucun commentaire:

Enregistrer un commentaire