1

私は現在、さまざまなシアター シーティング プログラムに取り組んでいます。C++ を使い始めたばかりですが、コーディングで発生し続けるこのエラーを理解できません。私が現在コーディングしようとしているのは、「*」の文字を 1 文字ずつ入力する方法であり、最終的には映画館の座席表を表示する機能を構築するのに役立ちます。私は readSeating と呼ばれる機能を完成させることにかなり近づいています...ただし、いくつかの明確な問題があります。通常、プログラムをかなり効率的にデバッグできますが、これを理解することはできません。私のコードを見て、プログラムの感触を掴んでください。アイデアがあれば教えてください。答えはやや単純にしてください。繰り返しますが、私は C++ の達人ではありません

PS

コード全体を表示して申し訳ありません...これは私の最初の投稿です...何を含めるべきか、何を含めるべきでないかを本当に知りませんでした。そして、プログラムを自分でテストすることで、プログラムの感触をつかむことができるようにしたかったのです... ありがとうございました!

/* 
* This is a program built by a team of students
* to help local movie theaters sell tickets
* 
* File: main.cpp
* Author(s):
*
* 
* Created on April 15, 2013, 11:10 AM
*/


#include <cstdlib>
#include <vector>
#include <string>
#include <fstream>
#include <iostream>
#include <cctype>
#include <iomanip>

using namespace std;

//Function Prototypes
void Title_Card();
void seating_prices();
void seating_chart();
void pick_seating();
void purchase_history();
void quit();
void update_file();
void Show_Menu();
void is_digit(int&);
void Admin_Menu();
void edit_seating_prices();
void edit_seating();
void quit_to_original();
void purchase_history_admin();

int readSeating (char, vector<char>&); //Reads SeatingChart.txt
int readPrices(string, vector<double>&); //Reads SeatingPrices.txt
vector<double> prices(15); //For SeatPrices.txt
vector<char> seating(450); //For SeatingChart.txt



//Actual Program
int main() {
Title_Card(); //Calls Title Page

readSeating("SeatingChart.txt", seating); //Reads SeatingChart.txt
readPrices("SeatPrices.txt", prices); //Reads SeatPrices.txt
Show_Menu(); //Shows Introductory Menu

system ("pause");
return 0;
}




//**************************************************************
// Definition of the ShowMenu function. Shows introductory menu*
// and controls where user ends up in the program.             *
//**************************************************************


void Show_Menu() {
int choice;
string password;

  cout << "Welcome to the our theater program! Made for a person" << endl;
  cout << "who is looking for seating, purchasing a ticket, and" << endl;
  cout << "searching for other miscellaneous things... We hope" << endl;
  cout << "you enjoy the program!" << endl << endl;
  cout << "Below is a list of options the user can choose from:" << endl << endl;
  cout << "1.\tSeating Prices" << endl;
  cout << "2.\tPick Seating" << endl;
  cout << "3.\tPurchase History" << endl;
  cout << "4.\tQuit" << endl << endl;
  cout << "Enter a choice... (1-4): ";
  cin >> choice;

  //Secret Administrator Access
  if (choice == 219){
     system ("cls");
     cout << "Enter the administrator password: ";
     cin >> password;

     if (password == "sterilegorilla")
        Admin_Menu();
     else {
        system ("cls");
        Show_Menu();
          }
  } 

  is_digit(choice);//is_digit function doesn't work atm


  while (choice < 1 || choice > 4){
        cout << endl << "You have entered an invalid choice!" << endl;
        cout << "Enter a choice... (1-4): ";
        cin >> choice;
        is_digit(choice); //is_digit function doesn't work atm
            if (choice == 219){
               system ("cls");
               cout << "Enter the administrator password: ";
               cin >> password;

                   if (password == "sterilegorilla")
                      Admin_Menu(); 

                      else {
                           system ("cls");
                           Show_Menu();
                           }     
                           }
     }

  switch (choice) {
         case 1:
              seating_prices();

         case 2:
              pick_seating();

         case 3:
              purchase_history();

         case 4:
              quit();
              }

}





//**************************************************************
// Definition of the seating_prices function. Displays to the  *
// user, SeatPrices.txt                                        *
//**************************************************************


void seating_prices(){
system ("cls");
cout << "The Current Seating Prices Are:" << endl << endl;
for (int count = 0; count < 4; count++){
cout << " " << setprecision(4) << showpoint <<  prices[count] << " | Row " << (count + 1) <<                         endl;
}
for (int count = 4; count < prices.size(); count++){
cout << "  " << setprecision(3) << showpoint <<  prices[count] << " | Row " << (count + 1) << endl;
}
cout << endl;
system ("pause");
system ("cls");
Show_Menu();
}




//**************************************************************
// Definition of the pick_seating function. Displays the       *
// current seating chart and allows the user to pick their seat*
//**************************************************************


void pick_seating(){  //Not Finished
system ("cls");
int row_choice;
int seat_choice;

cout << "The Current Seating Chart Is:" << endl;

 //Display Seating Chart



 //Picking your seat
cout << "Enter the row number you would like to be in (1-15): ";             
cin >> row_choice;
while (row_choice < 1 || row_choice > 15){
      cout << endl << "You have entered an invalid row number!" << endl;
      cout << "Enter the row number you would like to be in (1-15): ";
      cin >> row_choice;
      }

cout << "Enter the seat number you would like to have (1-30): ";
cin >> seat_choice;
while (seat_choice < 1 || seat_choice > 30){
      cout << endl << "You have entered an invalid seat number!" << endl;
      cout << "Enter the seat number you would like to have (1-30): ";
      cin >> seat_choice;
      }

cout << "Congratulations! You have picked your seat!" << endl << endl;
system ("pause");
system ("cls");
Show_Menu();
}




//**************************************************************
// Definition of the purchase_history function. Displays the   *
// current the total sum of all movie ticket purchases         *
//**************************************************************


void purchase_history(){         //Not finished
 system ("cls");
 system ("pause");
 system ("cls");
 Show_Menu();
}



//**************************************************************
// Definition of the quit function. Allows the user to quit the*
// program entirely                                            *
//**************************************************************


void quit(){
 update_file();
 exit(0);
 }



//**************************************************************
// Definition of the is_digit function. Designed to make it    *
// possible to enter only integers when asked for integers     *
//**************************************************************



void is_digit(int & input){      //Not working atm
 if (isdigit(input)){
     return;
     }
 if (isalpha(input)){
     cout << endl << "You have entered an invalid data type!" << endl;
     cout << "Enter a choice... (1-4): ";
     cin >> input;
     }
 if (isspace(input)){
     cout << endl << "You have entered an invalid data type!" << endl;
     cout << "Enter a choice... (1-4): ";
     cin >> input;
     }    
 }




//**************************************************************
// Definition of the update_file function. Designed to update  *
// the seating chart upon leaving the pick_seating function    *
//**************************************************************



void update_file(){  //Not finished

 //This function is supposed to
 //Update the seating chart
 //upon exit of the pick_seating function
 }




//**************************************************************
// Definition of the Admin_Menu function. Displays the         *
// administrator-based menu if user knows the code and password*
//**************************************************************


void Admin_Menu(){

  system ("cls");
  int choice = 0;

  cout << "Hello! This is the administrator version";
  cout << endl << "of the theatre program; mainly used for editing purposes." << endl << endl;
  cout << "Below is a list of options the administrator can choose from:" << endl << endl;
  cout << "1.\tEdit Seating Prices" << endl;
  cout << "2.\tEdit Seating" << endl;
  cout << "3.\tPurchase History" << endl;
  cout << "4.\tQuit to Original" << endl;
  cout << "5.\tQuit Program" << endl << endl;
  cout << "Enter a choice... (1-5): ";
  cin >> choice;

        while (choice < 1 || choice > 5){
        cout << endl << "You have entered an invalid choice!" << endl;
        cout << "Enter a choice... (1-5): ";
        cin >> choice;
        }

  switch (choice) {
         case 1:
              edit_seating_prices();

         case 2:
              edit_seating();

         case 3:
              purchase_history_admin();

         case 4:
              quit_to_original();

         case 5:
              quit();
         }
  }



//**************************************************************
// Definition of the edit_seating function. Administrator-only *
// function to edit the seating chart                          *
//**************************************************************



void edit_seating(){             //Not finished
 system ("cls");
 system ("pause");
 system ("cls");
 Admin_Menu();
 } 



//**************************************************************
// Definition of the edit_seating function. Administrator-only *
// function to edit the prices of the seats.                   *
// This will in turn, overwrite SeatPrices.txt                 *
//**************************************************************



void edit_seating_prices(){    //Not finished
 system ("cls");
 system ("pause");
 system ("cls");
 Admin_Menu();
 }



//**************************************************************
// Definition of the purchase_history_admin function.          *
// Administrator-only function designed to show admin the      *
// total sum of ticket sales... NOT EDITABLE                   *
//**************************************************************


void purchase_history_admin(){
 system ("cls");
 system ("pause");
 system ("cls");
 Admin_Menu();
 }



//**************************************************************
// Definition of the quit_to_original function. Administrator- *
// only function designed to return admin to original program  *
//**************************************************************


void quit_to_original(){
 system ("cls");
 Show_Menu();
 }




//**************************************************************
// Definition of the read_file function. Reads SeatPrices.txt  *
// and stores the pre-determined prices into a vector named    *
// prices.                                                     *
//**************************************************************



int readPrices(string myFile, vector<double>& vect) {

//input file
ifstream SeatPrices;                   

SeatPrices.open(myFile.c_str());


//if file cannot be found
if (!SeatPrices) 
cout << "Cannot find the file!" << endl;


for (int index = 0; index < vect.size(); index++){
    SeatPrices >> vect[index];   //Reading the file "SeatPrices.txt"
    }

SeatPrices.close();  //Closes the file
return 0;
}




//**************************************************************
// Definition of the readSeating function. Reads a text file   *
// with a seating chart in it.                                 *
//**************************************************************



int readSeating(char myFile, vector<char>& vect){           //Not EVEN CLOSE TO FINISHING


//input file
ifstream SeatingChart;
SeatingChart.open(myFile);

//if file cannot be found
if (!SeatingChart)
cout << "Cannot find the file!" << endl;

for (int index = 0; index < vect.size(); index++){
    SeatingChart >> vect[index];  //Reading the file "SeatingChart.txt"
    }

SeatingChart.close(); //Closes the file
return 0;
}








//**************************************************************
// Definition of the Title_Card function. Starts the program   *
// with a title card, showing a little introductory title      *
//**************************************************************


void Title_Card(){
 cout << endl << endl << endl << endl;
 cout << "\t\t" << "************************************************\n";
 cout << "\t\t" << "*               THEATER SEATING!               *\n";
 cout << "\t\t" << "*                                              *\n";
 cout << "\t\t" << "*     A program created by a team of three     *\n";
 cout << "\t\t" << "*     students to help small theaters sell     *\n";
 cout << "\t\t" << "*                 more tickets                 *\n";
 cout << "\t\t" << "*                                              *\n";
 cout << "\t\t" << "*              Team of Students:               *\n";
 cout << "\t\t" << "*                                              *\n";
 cout << "\t\t" << "*                *************                 *\n";
 cout << "\t\t" << "*                 ***********                  *\n";
 cout << "\t\t" << "*                *************                 *\n";
 cout << "\t\t" << "*                                              *\n";
 cout << "\t\t" << "************************************************\n";
 cout << endl << endl;
 system ("pause");
 system ("cls");
 }
4

2 に答える 2

1

あなたのためにそれを修正しました。文字列リテラル (例: "somestring") は "char const *" 型です。char として扱うことはできません。

/* 
* This is a program built by a team of students
* to help local movie theaters sell tickets
* 
* File: main.cpp
* Author(s):
*
* 
* Created on April 15, 2013, 11:10 AM
*/


#include <cstdlib>
#include <vector>
#include <string>
#include <fstream>
#include <iostream>
#include <cctype>
#include <iomanip>

using namespace std;

//Function Prototypes
void Title_Card();
void seating_prices();
void seating_chart();
void pick_seating();
void purchase_history();
void quit();
void update_file();
void Show_Menu();
void is_digit(int&);
void Admin_Menu();
void edit_seating_prices();
void edit_seating();
void quit_to_original();
void purchase_history_admin();

int readSeating (const char*, vector<char>&); //Reads SeatingChart.txt
int readPrices(string, vector<double>&); //Reads SeatingPrices.txt
vector<double> prices(15); //For SeatPrices.txt
vector<char> seating(450); //For SeatingChart.txt



//Actual Program
int main() {
Title_Card(); //Calls Title Page

readSeating("SeatingChart.txt", seating); //Reads SeatingChart.txt
readPrices("SeatPrices.txt", prices); //Reads SeatPrices.txt
Show_Menu(); //Shows Introductory Menu

system ("pause");
return 0;
}




//**************************************************************
// Definition of the ShowMenu function. Shows introductory menu*
// and controls where user ends up in the program.             *
//**************************************************************


void Show_Menu() {
int choice;
string password;

  cout << "Welcome to the our theater program! Made for a person" << endl;
  cout << "who is looking for seating, purchasing a ticket, and" << endl;
  cout << "searching for other miscellaneous things... We hope" << endl;
  cout << "you enjoy the program!" << endl << endl;
  cout << "Below is a list of options the user can choose from:" << endl << endl;
  cout << "1.\tSeating Prices" << endl;
  cout << "2.\tPick Seating" << endl;
  cout << "3.\tPurchase History" << endl;
  cout << "4.\tQuit" << endl << endl;
  cout << "Enter a choice... (1-4): ";
  cin >> choice;

  //Secret Administrator Access
  if (choice == 219){
     system ("cls");
     cout << "Enter the administrator password: ";
     cin >> password;

     if (password == "sterilegorilla")
        Admin_Menu();
     else {
        system ("cls");
        Show_Menu();
          }
  } 

  is_digit(choice);//is_digit function doesn't work atm


  while (choice < 1 || choice > 4){
        cout << endl << "You have entered an invalid choice!" << endl;
        cout << "Enter a choice... (1-4): ";
        cin >> choice;
        is_digit(choice); //is_digit function doesn't work atm
            if (choice == 219){
               system ("cls");
               cout << "Enter the administrator password: ";
               cin >> password;

                   if (password == "sterilegorilla")
                      Admin_Menu(); 

                      else {
                           system ("cls");
                           Show_Menu();
                           }     
                           }
     }

  switch (choice) {
         case 1:
              seating_prices();

         case 2:
              pick_seating();

         case 3:
              purchase_history();

         case 4:
              quit();
              }

}





//**************************************************************
// Definition of the seating_prices function. Displays to the  *
// user, SeatPrices.txt                                        *
//**************************************************************


void seating_prices(){
system ("cls");
cout << "The Current Seating Prices Are:" << endl << endl;
for (int count = 0; count < 4; count++){
cout << " " << setprecision(4) << showpoint <<  prices[count] << " | Row " << (count + 1) <<                         endl;
}
for (int count = 4; count < prices.size(); count++){
cout << "  " << setprecision(3) << showpoint <<  prices[count] << " | Row " << (count + 1) << endl;
}
cout << endl;
system ("pause");
system ("cls");
Show_Menu();
}




//**************************************************************
// Definition of the pick_seating function. Displays the       *
// current seating chart and allows the user to pick their seat*
//**************************************************************


void pick_seating(){  //Not Finished
system ("cls");
int row_choice;
int seat_choice;

cout << "The Current Seating Chart Is:" << endl;

 //Display Seating Chart



 //Picking your seat
cout << "Enter the row number you would like to be in (1-15): ";             
cin >> row_choice;
while (row_choice < 1 || row_choice > 15){
      cout << endl << "You have entered an invalid row number!" << endl;
      cout << "Enter the row number you would like to be in (1-15): ";
      cin >> row_choice;
      }

cout << "Enter the seat number you would like to have (1-30): ";
cin >> seat_choice;
while (seat_choice < 1 || seat_choice > 30){
      cout << endl << "You have entered an invalid seat number!" << endl;
      cout << "Enter the seat number you would like to have (1-30): ";
      cin >> seat_choice;
      }

cout << "Congratulations! You have picked your seat!" << endl << endl;
system ("pause");
system ("cls");
Show_Menu();
}




//**************************************************************
// Definition of the purchase_history function. Displays the   *
// current the total sum of all movie ticket purchases         *
//**************************************************************


void purchase_history(){         //Not finished
 system ("cls");
 system ("pause");
 system ("cls");
 Show_Menu();
}



//**************************************************************
// Definition of the quit function. Allows the user to quit the*
// program entirely                                            *
//**************************************************************


void quit(){
 update_file();
 exit(0);
 }



//**************************************************************
// Definition of the is_digit function. Designed to make it    *
// possible to enter only integers when asked for integers     *
//**************************************************************



void is_digit(int & input){      //Not working atm
 if (isdigit(input)){
     return;
     }
 if (isalpha(input)){
     cout << endl << "You have entered an invalid data type!" << endl;
     cout << "Enter a choice... (1-4): ";
     cin >> input;
     }
 if (isspace(input)){
     cout << endl << "You have entered an invalid data type!" << endl;
     cout << "Enter a choice... (1-4): ";
     cin >> input;
     }    
 }




//**************************************************************
// Definition of the update_file function. Designed to update  *
// the seating chart upon leaving the pick_seating function    *
//**************************************************************



void update_file(){  //Not finished

 //This function is supposed to
 //Update the seating chart
 //upon exit of the pick_seating function
 }




//**************************************************************
// Definition of the Admin_Menu function. Displays the         *
// administrator-based menu if user knows the code and password*
//**************************************************************


void Admin_Menu(){

  system ("cls");
  int choice = 0;

  cout << "Hello! This is the administrator version";
  cout << endl << "of the theatre program; mainly used for editing purposes." << endl << endl;
  cout << "Below is a list of options the administrator can choose from:" << endl << endl;
  cout << "1.\tEdit Seating Prices" << endl;
  cout << "2.\tEdit Seating" << endl;
  cout << "3.\tPurchase History" << endl;
  cout << "4.\tQuit to Original" << endl;
  cout << "5.\tQuit Program" << endl << endl;
  cout << "Enter a choice... (1-5): ";
  cin >> choice;

        while (choice < 1 || choice > 5){
        cout << endl << "You have entered an invalid choice!" << endl;
        cout << "Enter a choice... (1-5): ";
        cin >> choice;
        }

  switch (choice) {
         case 1:
              edit_seating_prices();

         case 2:
              edit_seating();

         case 3:
              purchase_history_admin();

         case 4:
              quit_to_original();

         case 5:
              quit();
         }
  }



//**************************************************************
// Definition of the edit_seating function. Administrator-only *
// function to edit the seating chart                          *
//**************************************************************



void edit_seating(){             //Not finished
 system ("cls");
 system ("pause");
 system ("cls");
 Admin_Menu();
 } 



//**************************************************************
// Definition of the edit_seating function. Administrator-only *
// function to edit the prices of the seats.                   *
// This will in turn, overwrite SeatPrices.txt                 *
//**************************************************************



void edit_seating_prices(){    //Not finished
 system ("cls");
 system ("pause");
 system ("cls");
 Admin_Menu();
 }



//**************************************************************
// Definition of the purchase_history_admin function.          *
// Administrator-only function designed to show admin the      *
// total sum of ticket sales... NOT EDITABLE                   *
//**************************************************************


void purchase_history_admin(){
 system ("cls");
 system ("pause");
 system ("cls");
 Admin_Menu();
 }



//**************************************************************
// Definition of the quit_to_original function. Administrator- *
// only function designed to return admin to original program  *
//**************************************************************


void quit_to_original(){
 system ("cls");
 Show_Menu();
 }




//**************************************************************
// Definition of the read_file function. Reads SeatPrices.txt  *
// and stores the pre-determined prices into a vector named    *
// prices.                                                     *
//**************************************************************



int readPrices(string myFile, vector<double>& vect) {

//input file
ifstream SeatPrices;                   

SeatPrices.open(myFile.c_str());


//if file cannot be found
if (!SeatPrices) 
cout << "Cannot find the file!" << endl;


for (int index = 0; index < vect.size(); index++){
    SeatPrices >> vect[index];   //Reading the file "SeatPrices.txt"
    }

SeatPrices.close();  //Closes the file
return 0;
}




//**************************************************************
// Definition of the readSeating function. Reads a text file   *
// with a seating chart in it.                                 *
//**************************************************************



int readSeating(const char* myFile, vector<char>& vect){           //Not EVEN CLOSE TO FINISHING


//input file
ifstream SeatingChart;
SeatingChart.open(myFile);

//if file cannot be found
if (!SeatingChart)
cout << "Cannot find the file!" << endl;

for (int index = 0; index < vect.size(); index++){
    SeatingChart >> vect[index];  //Reading the file "SeatingChart.txt"
    }

SeatingChart.close(); //Closes the file
return 0;
}








//**************************************************************
// Definition of the Title_Card function. Starts the program   *
// with a title card, showing a little introductory title      *
//**************************************************************


void Title_Card(){
 cout << endl << endl << endl << endl;
 cout << "\t\t" << "************************************************\n";
 cout << "\t\t" << "*               THEATER SEATING!               *\n";
 cout << "\t\t" << "*                                              *\n";
 cout << "\t\t" << "*     A program created by a team of three     *\n";
 cout << "\t\t" << "*     students to help small theaters sell     *\n";
 cout << "\t\t" << "*                 more tickets                 *\n";
 cout << "\t\t" << "*                                              *\n";
 cout << "\t\t" << "*              Team of Students:               *\n";
 cout << "\t\t" << "*                                              *\n";
 cout << "\t\t" << "*                *************                 *\n";
 cout << "\t\t" << "*                 ***********                  *\n";
 cout << "\t\t" << "*                *************                 *\n";
 cout << "\t\t" << "*                                              *\n";
 cout << "\t\t" << "************************************************\n";
 cout << endl << endl;
 system ("pause");
 system ("cls");
 }  
于 2013-04-19T07:49:57.097 に答える