我目前正在制作一个杂项剧场座位计划!我刚刚开始通过C ++,但我无法弄清楚这些错误。我试图让程序存储用户在两个向量中输入行号和行座位(仅当它是多个席位时);矢量seat_row()和矢量seat_number()。我知道错误是什么,但我不知道如何处理这种情况。对不起,如果我太不清楚,但说实话,我不知道还包括什么。请查看我的代码,了解我的程序,让我有任何想法。请保持答案有点简单;再说一遍,我不是C ++的高手
P.S。
很抱歉显示整个代码......我真的不知道要包括什么,什么不包括;我希望人们能够通过自己测试来感受程序......再次感谢!
/*
* 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");
}
答案 0 :(得分:0)
您的错误在这里
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
这是一个非常常见的错误,你试图声明两个名为seat_row和seat_number的向量,但是因为你使用了空的parens而你声明了两个返回向量的函数。
这是一个摘要
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