2013-04-20 3 views
-1

현재 기타 극장 좌석 프로그램에서 작업 중입니다! 나는 C++을 통해 진전을 보이기 시작했지만 이러한 오류를 이해할 수는 없다. 나는 프로그램 스토어 사용자가 2 개의 벡터로 행 번호와 행 수를 입력 할 수있게하려고 노력하고있다 (다중 좌석 인 경우에만). 벡터 seat_row() 및 벡터 seat_number(). 나는 그 오류가 무엇을 말하고 있는지 알지만, 나는 그 상황에 어떻게 다르게 접근해야하는지 모른다. 죄송합니다. 제가 너무 불분명하지만 솔직히 말해서 무엇을 포함해야할지 모르겠습니다. 내 코드를보고, 내 프로그램에 대한 느낌을 갖도록하고, 어떤 아이디어라도 갖도록하십시오. 대답은 다소 단순하게하십시오. 다시, 나는 C + +의 주인이 아니다.C++ 프로그램의 벡터 오류

P.

전체 코드를 표시하는 데 죄송합니다 ... 포함 할 항목을 알지 못했습니다. 저는 사람들이 직접 테스트를 해봄으로써 프로그램에 대한 느낌을 갖기를 원했습니다 ... 다시 한번 감사드립니다!

/* 
* 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 picking_seats(); 
void display_seating(); 
void display_name(); 
void display_number_of_seats(); 
void display_correct1(string, int); 
void display_seats(); 
void display_correct2(string, int, int, int); 
void display_correct2_alt(string, int, vector<int>, vector<int>); 
void display_correct3(string); 
void multiple_seats(string, int, vector<int>, vector<int>); 
void display_rows_seats(string, int); 
void display_finished(string); 
void display_purchase_seats(string, int, int); 
void display_purchase_seats_alt(string, int, vector<int>, vector<int>); 

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 

vector<int> seat_row(); //For storing multiple seat rows 
vector<int> seat_number(); //For storing multiple seat numbers 



//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.\tSeating Chart" << endl; 
     cout << "3.\tPick Seating" << endl; 
     cout << "4.\tPurchase History" << endl; 
     cout << "5.\tQuit" << 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: 
        seating_prices(); 

      case 2: 
        seating_chart(); 

      case 3: 
        pick_seating(); 

      case 4: 
        purchase_history(); 

      case 5: 
        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 seating_chart function. Function for  * 
// displaying the seating chart by itself      * 
//************************************************************** 

void seating_chart(){ 

    system ("cls"); 
    int counter = 30; 
    int row_counter = 0; 


    cout << "The Current Seating Chart Is:" << endl << endl << endl << "   1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0" << endl << endl; 
    cout << "   ---------------------------------------------------------------" << endl; 
    cout << " Row " << (row_counter + 1) << "  "; 

    //Displaying Seating Chart 
    for (int index = 0; index < 270; index++){ 



     if (index == counter){ 
      row_counter = (row_counter + 1); 
      counter = (counter + 30); 
      cout << "" << endl << " Row " << (row_counter + 1) << "  "; 

      } 

     cout << seating[index] << " "; 
     }  



    for (int index = 270; index < seating.size(); index++){ 

     if (index == counter){ 
      row_counter = (row_counter + 1); 
      counter = (counter + 30); 
      cout << "" << endl << " Row " << (row_counter + 1) << " "; 

      } 

     cout << seating[index] << " "; 
     } 
    cout << endl << "   ---------------------------------------------------------------" << endl; 

     cout << endl << 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"); 
    display_seating(); 

} 




//************************************************************** 
// 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 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 read_Prices 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){ 


    //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 display_seating function. Function for * 
// simplifying the pick_seating function      * 
//************************************************************** 


void display_seating(){ 

    int counter = 30; 
    int row_counter = 0; 


    //Displaying Seating Chart 
    cout << "   1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0" << endl << endl; 
    cout << "   ---------------------------------------------------------------" << endl; 
    cout << " Row " << (row_counter + 1) << "  "; 

    //Displaying Seating Chart 
    for (int index = 0; index < 270; index++){ 



     if (index == counter){ 
      row_counter = (row_counter + 1); 
      counter = (counter + 30); 
      cout << "" << endl << " Row " << (row_counter + 1) << "  "; 

      } 

     cout << seating[index] << " "; 
     }  



    for (int index = 270; index < seating.size(); index++){ 

     if (index == counter){ 
      row_counter = (row_counter + 1); 
      counter = (counter + 30); 
      cout << "" << endl << " Row " << (row_counter + 1) << " "; 

      } 

     cout << seating[index] << " "; 
     } 
    cout << endl << "   ---------------------------------------------------------------" << endl << endl; 

    cout << "In the seating chart... All hashtags (#'s) are seats already taken" << endl; 
    cout << "and all stars (*'s) are available seats..." << endl << endl; 
    system ("pause"); 


    display_name(); //Continues the program, helps loop if necessary 
    } 



//************************************************************** 
// Definition of the display_name function. Function for  * 
// simplifying the pick_seating function      * 
//************************************************************** 


void display_name(){ 

    string name; 

    //Picking your seat 
    cout << endl << endl << "To pick your own seat(s), follow the instructions below:" << endl << endl; 
    cout << "What is the name of the recipient of the seat(s)? "; 
    cin >> name; 


    display_correct3(name); 
    } 



//************************************************************** 
// Definition of the display_number_of_seats function. Function* 
// for simplifying the pick_seating function     * 
//************************************************************** 


void display_number_of_seats(string name){ 

    int number_of_seats; 
    int available_seats = 450; //Amount of remaining seats out of 450 

    cout << "Alright " << name << "!" << endl; 
    cout << "How many seats are you purchasing today? "; 
    cin >> number_of_seats; 

     while (number_of_seats < 1 || number_of_seats > available_seats){ 
       cout << endl << endl << "You have entered an invalid number of seats!" << endl; 
       cout << "This might be because your number is zero or less," << endl; 
       cout << "or that the number you entered is more than the amount" << endl; 
       cout << "of remaining seats! Try again!" << endl << endl; 
       cout << "How many seats are you purchasing today? "; 
       cin >> number_of_seats; 
       } 

     display_correct1(name, number_of_seats); 
     } 


//************************************************************** 
// Definition of the display_correct1 function. Function for * 
// simplifying the pick_seating function      * 
//************************************************************** 


void display_correct1(string name, int number_of_seats){ 

    int correct; 

    cout << endl << "Alright " << name << ", you are purchasing " << number_of_seats << " seat(s)?" << endl; 
    cout << "Is this correct? Enter a '0' for 'no', or a '1' for yes: "; 
    cin >> correct; 

     while (correct < 0 || correct > 1){ 
     cout << "You have entered an invalid number!" << endl; 
     cout << "Enter a '0' for 'no', or a '1' for yes: "; 
     cin >> correct; 
     } 

     if (correct == 0){ 
      cout << endl << endl; 
      display_number_of_seats(name); 
      } 

     if (correct == 1){ 
      cout << endl << endl; 

      if (number_of_seats > 1) 
      multiple_seats(name, number_of_seats, seat_row, seat_number); 

      display_rows_seats(name, number_of_seats); 
      } 



    } 




//************************************************************** 
// Definition of the multiple_seats function. Function only * 
// used if user chooses to purchase multiple seats    * 
//************************************************************** 


void multiple_seats(string name, int number_of_seats, vector<int> vect, vector<int> vect2){ 

    for (int index = 1; index <= number_of_seats; index++){ 

    for (int count = 0; count < number_of_seats; count++){ 

    cout << "For Seat #" << index << "..." << endl; 

    cout << "Enter the row number you would like to be in: (1-15): ";    
    cin >> vect[count]; 

     while (vect[count] < 1 || vect[count] > 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 >> vect[count]; 
      } 

      cout << "Enter the seat number you would like to have (1-30): "; 
      cin >> vect2[count]; 

       while (vect2[count] < 1 || vect2[count] > 30){ 
       cout << endl << "You have entered an invalid seat number!" << endl; 
       cout << "Enter the seat number you would like to have (1-30): "; 
       cin >> vect2[count]; 
       } 
    cout << endl; 
    } 
    } 
    display_correct2_alt(name, number_of_seats, seat_row, seat_number); 
    } 




//************************************************************** 
// Definition of the display_rows_seats function. Function for * 
// simplifying the pick_seating function      * 
//************************************************************** 

void display_rows_seats(string name, int number_of_seats){ 

    int seat_choice; 
    int row_choice; 

    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; 
       } 

    display_correct2(name, number_of_seats, row_choice, seat_choice); //Helps looping if necessary 

    } 




//************************************************************** 
// Definition of the display_correct2_alt function. Alternate * 
// function if user enters multiple seats      * 
//************************************************************** 


void display_correct2_alt(string name, int number_of_seats, vector<int> vect, vector<int> vect2){ 

    int correct; 
    int counter = 1; 
    int counter_2 = 1; //For minor details for looks 

    for (int index = 1; index <= number_of_seats; index++){ 

    for (int count = 0; count < number_of_seats; count++){ 


    if (counter_2 != number_of_seats && counter_2 == 1){   //For first seat 

    cout << endl << endl << "Alright " << name << ";" << endl; 
    cout << "For Seat #" << index << "; you chose " << "Row #" << vect[count]; 
    cout << " and Seat #" << vect2[count] << "?" << endl; 
    cout << "Is this correct? Enter a '0' for 'no', or a '1' for yes: "; 
    cin >> correct; 

    } 


    if (counter_2 != number_of_seats && counter_2 > 1){   //For all seats after first, except last seat 

    cout << endl << endl; 
    cout << "Next, for Seat #" << index << "; you chose " << "Row #" << vect[count]; 
    cout << " and Seat #" << vect2[count] << "?" << endl; 
    cout << "Is this correct? Enter a '0' for 'no', or a '1' for yes: "; 
    cin >> correct; 

    } 


    if (counter_2 == number_of_seats){   //For last seat 

    cout << endl << endl; 
    cout << "And for your last seat, Seat #" << index << "; you chose " << "Row #" << vect[count]; 
    cout << " and Seat #" << vect2[count] << "?" << endl; 
    cout << "Is this correct? Enter a '0' for 'no', or a '1' for yes: "; 
    cin >> correct; 
    } 
    } 



     while (correct < 0 || correct > 1){ 
     cout << "You have entered an invalid number!" << endl; 
     cout << "Enter a '0' for 'no', or a '1' for yes: "; 
     cin >> correct; 
     } 


     if (correct == 0){ 
      cout << endl << endl; 

      if (number_of_seats > 1) 
      multiple_seats(name, number_of_seats, seat_row, seat_number); 

      display_rows_seats(name, number_of_seats); 
      } 

     if (correct == 1){ 
      if (counter == number_of_seats) 
      display_purchase_seats_alt(name, number_of_seats, seat_row, seat_number); 
      } 

     counter = (counter + 1); 
     counter_2 = (counter_2 + 1); 

    } 
    } 


//************************************************************** 
// Definition of the display_correct2 function. Function for * 
// simplifying the pick_seating function      * 
//************************************************************** 


void display_correct2(string name, int number_of_seats, int row_choice, int seat_choice){ 

    int correct; 

    cout << endl << endl << "Alright " << name << ", you chose " << "Row #" << row_choice; 
    cout << " and Seat #" << seat_choice << "?" << endl; 
    cout << "Is this correct? Enter a '0' for 'no', or a '1' for yes: "; 
    cin >> correct; 

     while (correct < 0 || correct > 1){ 
     cout << "You have entered an invalid number!" << endl; 
     cout << "Enter a '0' for 'no', or a '1' for yes: "; 
     cin >> correct; 
     } 

     if (correct == 0){ 
      cout << endl << endl; 

      if (number_of_seats > 1) 
      multiple_seats(name, number_of_seats, seat_row, seat_number); 

      display_rows_seats(name, number_of_seats); 
      } 

     if (correct == 1) 
      display_purchase_seats(name, row_choice, seat_choice); 



    } 




//************************************************************** 
// Definition of the display_purchase_seats function. Function * 
// user to purchase his chosen seats       * 
//************************************************************** 


void display_purchase_seats(string name, int row_choice, int seat_choice){ 

    int total_cost = 0; //Not set up yet; supposed to calculate the row price 

    system ("cls"); 
    cout << name << ", now it is time to pay for your chosen seats!" << endl; 
    cout << "Since you chose Row #" << row_choice << ", and Seat# " << seat_choice << "..." << endl; 
    cout << "Your total cost is: S" << total_cost << endl << endl; 

    system ("pause"); 
    display_finished(name); 
    } 




//************************************************************** 
// Definition of the display_purchase_seats_alt function.  * 
// Alternate function used for purchasing multiple seats  * 
//************************************************************** 


void display_purchase_seats_alt(string name, int number_of_seats, vector<int> vect, vector<int> vect2){ 

    int total_cost = 0; //Not set up yet; supposed to calculate the row price 

    system ("cls"); 
    cout << name << ", now it is time to pay for your chosen seats!" << endl; 
    cout << "Since you chose " << number_of_seats << " seats:" << endl << endl; 

    for (int index = 0; index <= number_of_seats; index++){ 

    cout << "Seat #" << index << " being in Row #" << seat_row[index] << ";" << endl; 
    } 

    cout << endl << "Your total cost is: $" << total_cost << endl << endl; 
    system ("pause"); 
    display_finished(name); 
    }  


//************************************************************** 
// Definition of the display_correct3 function. Function for * 
// simplifying the pick_seating function      * 
//************************************************************** 


void display_correct3(string name){ 

    int correct; 

    cout << endl << "Alright, you chose the name " << name << "?" << endl; 
    cout << "Is this correct? Enter a '0' for 'no', or a '1' for yes: "; 
    cin >> correct; 

     while (correct < 0 || correct > 1){ 
     cout << "You have entered an invalid number!" << endl; 
     cout << "Enter a '0' for 'no', or a '1' for yes: "; 
     cin >> correct; 
     } 

     if (correct == 0){ 
      system ("cls"); 
      display_seating(); 
      } 

     if (correct == 1){ 
      cout << endl; 
      display_number_of_seats(name); //Helps if looping is necessary 
      } 



    } 




//************************************************************** 
// Definition of the display_finished function. Function for * 
// simplifying the pick_seating function      * 
//************************************************************** 


void display_finished(string name){ 

    system ("cls"); 

    cout << "Congratulations " << name << "! You have picked your seat!" << endl; 
    cout << "The Seating Chart will update momentarily..." << endl << endl; 
    update_file(); 
    system ("pause"); 
    system ("cls"); 
    Show_Menu(); 

    } 



//************************************************************** 
// 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"); 
    } 
+1

입니다하지만 당신은 최소한하지만 여전히 완전한 예제가 아니라 전체 프로젝트에 줄 수 있다면 그것은 우리와 당신에게 많은 도움이됩니다. – Flexo

+0

여기에 아무도 800 줄의 코드를 살펴보고 싶지 않습니다. – chris

+0

코드가 실제로 완성되었을 때 (이 예에서와 같이) 잘라내어 붙여 넣기가 간단합니다. 그러나 OP가 오류 메시지를 인용했을 수 있습니다. – john

답변

0

귀하의 오류는 당신이 seat_row 및 seat_number라는 두 개의 벡터를 선언하는 매우 일반적인 오류하려고했던 것

vector<int> seat_row; //For storing multiple seat rows 
vector<int> seat_number; //For storing multiple seat numbers 

해야 여기

vector<int> seat_row(); //For storing multiple seat rows 
vector<int> seat_number(); //For storing multiple seat numbers 

,하지만 당신은 사용하기 때문에 빈 괄호 대신 벡터를 반환하는 두 개의 함수를 선언했습니다.

여기가 yiouve 코드를 공유 위대한 요약

vector<int> a(10); // vector, size 10 
vector<int> b(0); // vector, size 0 
vector<int> c;  // also vector size 0 
vector<int> d(); // FUNCTION!! taking no arguments and returning a vector 
+0

와우! 고마워요! 나는 그 순간 무지를 넘어선다고 느낍니다 ... 그러나 그것을 디버깅 해 주셔서 감사합니다! 매우 감사! – thatshytcrary