Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/155.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
二维数组座位图C++ 我正在学习C++,我需要制作一个座席图表程序。这不是我的代码,因为我正在研究它以了解每个部分是如何工作的。我对座位表感兴趣。我自己尝试了很多不同的方法来尝试和解决这个问题,我已经接近了,在右边的列中有了满分*但它从来没有在正确的行中。 如果我选择座位1和第1排,它会在图表上的座位和第2排做标记。 再说一次,我没有使用这段代码,我只是在测试东西并了解它们是如何工作的时候学习得更好。 这是密码 #include "stdafx.h" #include <iostream> #include <iomanip> using namespace std; int Show_Menu(); void Show_Chart(); const char FULL = '*'; const char EMPTY = '#'; const int rows = 11; const int columns = 10; char map[rows][columns]; double price; int total = 0; int seat = 90; int seat2 = 0; int Quit = 1; int main() { const int Num_Rows = 11; double price[Num_Rows]; int row2, column2, cost; int answer; //I have this blocked out as I am testing the chart only /* cout << "Please enter price for each row." << endl; for (int count = 0; count < rows; count++) { cout << "Row # " << (count + 1) << ": "; cin >> price[count]; } */ for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) map[i][j] = EMPTY; } int choice; do { choice = Show_Menu(); switch (choice) { case 1: cout << "View Seat Prices\n\n"; for (int count = 0; count < rows; count++) { cout << "The price for row " << (count + 1) << ": "; cout << price[count] << endl; } break; case 2: cout << "Purchase a Ticket\n\n"; do { cout << "Please select the row you would like to sit in: "; cin >> row2; cout << "Please select the seat you would like to sit in: "; cin >> column2; if (map[row2][column2] == FULL) { cout << "Sorry that seat is sold-out, Please select a new seat."; cout << endl; } else { cost = price[row2] + 0; total = total + cost; cout << "That ticket costs: " << cost << endl; cout << "Confirm Purchase? Enter (1 = YES / 2 = NO)"; cin >> answer; if (answer == 1) { cout << "Your ticket purchase has been confirmed." << endl; map[row2][column2] = FULL; } else if (answer == 2) { cout << "Would you like to look at another seat? (1 = YES / 2 = NO)"; cout << endl; cin >> Quit; } cout << "Would you like to look at another seat?(1 = YES / 2 = NO)"; cin >> Quit; } } while (Quit == 1); break; case 3: cout << "View Available Seats\n\n"; Show_Chart(); break; case 4: cout << "Total ticket sales: " << total << ".\n\n"; break; case 5: cout << "quit\n"; break; default: cout << "Error input\n"; } } while (choice != 5); return 0; } int Show_Menu() { int MenuChoice; cout << endl << endl; cout << " \tMAIN MENU\n"; cout << " 1. View Seat Prices.\n"; cout << " 2. Purchase a Ticket.\n"; cout << " 3. View Available Seats.\n"; cout << " 4. View Ticket Sales.\n"; cout << " 5. Quit the program.\n"; cout << "_____________________\n\n"; cout << "Please enter your choice: "; cin >> MenuChoice; cout << endl << endl; return MenuChoice; } void Show_Chart() { cout << "Seats 1 2 3 4 5 6 7 8 9 "; for (int row = 0; row < 10; row++)//rows { cout << endl << "Row " << (row + 1); for (int columns = 0; columns < 9; columns++) { cout << " " << map[row][columns]; } } cout << endl; }_C++ - Fatal编程技术网

二维数组座位图C++ 我正在学习C++,我需要制作一个座席图表程序。这不是我的代码,因为我正在研究它以了解每个部分是如何工作的。我对座位表感兴趣。我自己尝试了很多不同的方法来尝试和解决这个问题,我已经接近了,在右边的列中有了满分*但它从来没有在正确的行中。 如果我选择座位1和第1排,它会在图表上的座位和第2排做标记。 再说一次,我没有使用这段代码,我只是在测试东西并了解它们是如何工作的时候学习得更好。 这是密码 #include "stdafx.h" #include <iostream> #include <iomanip> using namespace std; int Show_Menu(); void Show_Chart(); const char FULL = '*'; const char EMPTY = '#'; const int rows = 11; const int columns = 10; char map[rows][columns]; double price; int total = 0; int seat = 90; int seat2 = 0; int Quit = 1; int main() { const int Num_Rows = 11; double price[Num_Rows]; int row2, column2, cost; int answer; //I have this blocked out as I am testing the chart only /* cout << "Please enter price for each row." << endl; for (int count = 0; count < rows; count++) { cout << "Row # " << (count + 1) << ": "; cin >> price[count]; } */ for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) map[i][j] = EMPTY; } int choice; do { choice = Show_Menu(); switch (choice) { case 1: cout << "View Seat Prices\n\n"; for (int count = 0; count < rows; count++) { cout << "The price for row " << (count + 1) << ": "; cout << price[count] << endl; } break; case 2: cout << "Purchase a Ticket\n\n"; do { cout << "Please select the row you would like to sit in: "; cin >> row2; cout << "Please select the seat you would like to sit in: "; cin >> column2; if (map[row2][column2] == FULL) { cout << "Sorry that seat is sold-out, Please select a new seat."; cout << endl; } else { cost = price[row2] + 0; total = total + cost; cout << "That ticket costs: " << cost << endl; cout << "Confirm Purchase? Enter (1 = YES / 2 = NO)"; cin >> answer; if (answer == 1) { cout << "Your ticket purchase has been confirmed." << endl; map[row2][column2] = FULL; } else if (answer == 2) { cout << "Would you like to look at another seat? (1 = YES / 2 = NO)"; cout << endl; cin >> Quit; } cout << "Would you like to look at another seat?(1 = YES / 2 = NO)"; cin >> Quit; } } while (Quit == 1); break; case 3: cout << "View Available Seats\n\n"; Show_Chart(); break; case 4: cout << "Total ticket sales: " << total << ".\n\n"; break; case 5: cout << "quit\n"; break; default: cout << "Error input\n"; } } while (choice != 5); return 0; } int Show_Menu() { int MenuChoice; cout << endl << endl; cout << " \tMAIN MENU\n"; cout << " 1. View Seat Prices.\n"; cout << " 2. Purchase a Ticket.\n"; cout << " 3. View Available Seats.\n"; cout << " 4. View Ticket Sales.\n"; cout << " 5. Quit the program.\n"; cout << "_____________________\n\n"; cout << "Please enter your choice: "; cin >> MenuChoice; cout << endl << endl; return MenuChoice; } void Show_Chart() { cout << "Seats 1 2 3 4 5 6 7 8 9 "; for (int row = 0; row < 10; row++)//rows { cout << endl << "Row " << (row + 1); for (int columns = 0; columns < 9; columns++) { cout << " " << map[row][columns]; } } cout << endl; }

二维数组座位图C++ 我正在学习C++,我需要制作一个座席图表程序。这不是我的代码,因为我正在研究它以了解每个部分是如何工作的。我对座位表感兴趣。我自己尝试了很多不同的方法来尝试和解决这个问题,我已经接近了,在右边的列中有了满分*但它从来没有在正确的行中。 如果我选择座位1和第1排,它会在图表上的座位和第2排做标记。 再说一次,我没有使用这段代码,我只是在测试东西并了解它们是如何工作的时候学习得更好。 这是密码 #include "stdafx.h" #include <iostream> #include <iomanip> using namespace std; int Show_Menu(); void Show_Chart(); const char FULL = '*'; const char EMPTY = '#'; const int rows = 11; const int columns = 10; char map[rows][columns]; double price; int total = 0; int seat = 90; int seat2 = 0; int Quit = 1; int main() { const int Num_Rows = 11; double price[Num_Rows]; int row2, column2, cost; int answer; //I have this blocked out as I am testing the chart only /* cout << "Please enter price for each row." << endl; for (int count = 0; count < rows; count++) { cout << "Row # " << (count + 1) << ": "; cin >> price[count]; } */ for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) map[i][j] = EMPTY; } int choice; do { choice = Show_Menu(); switch (choice) { case 1: cout << "View Seat Prices\n\n"; for (int count = 0; count < rows; count++) { cout << "The price for row " << (count + 1) << ": "; cout << price[count] << endl; } break; case 2: cout << "Purchase a Ticket\n\n"; do { cout << "Please select the row you would like to sit in: "; cin >> row2; cout << "Please select the seat you would like to sit in: "; cin >> column2; if (map[row2][column2] == FULL) { cout << "Sorry that seat is sold-out, Please select a new seat."; cout << endl; } else { cost = price[row2] + 0; total = total + cost; cout << "That ticket costs: " << cost << endl; cout << "Confirm Purchase? Enter (1 = YES / 2 = NO)"; cin >> answer; if (answer == 1) { cout << "Your ticket purchase has been confirmed." << endl; map[row2][column2] = FULL; } else if (answer == 2) { cout << "Would you like to look at another seat? (1 = YES / 2 = NO)"; cout << endl; cin >> Quit; } cout << "Would you like to look at another seat?(1 = YES / 2 = NO)"; cin >> Quit; } } while (Quit == 1); break; case 3: cout << "View Available Seats\n\n"; Show_Chart(); break; case 4: cout << "Total ticket sales: " << total << ".\n\n"; break; case 5: cout << "quit\n"; break; default: cout << "Error input\n"; } } while (choice != 5); return 0; } int Show_Menu() { int MenuChoice; cout << endl << endl; cout << " \tMAIN MENU\n"; cout << " 1. View Seat Prices.\n"; cout << " 2. Purchase a Ticket.\n"; cout << " 3. View Available Seats.\n"; cout << " 4. View Ticket Sales.\n"; cout << " 5. Quit the program.\n"; cout << "_____________________\n\n"; cout << "Please enter your choice: "; cin >> MenuChoice; cout << endl << endl; return MenuChoice; } void Show_Chart() { cout << "Seats 1 2 3 4 5 6 7 8 9 "; for (int row = 0; row < 10; row++)//rows { cout << endl << "Row " << (row + 1); for (int columns = 0; columns < 9; columns++) { cout << " " << map[row][columns]; } } cout << endl; },c++,C++,如果我选择1号座位和1号排,它在图表上的标记为 第二排座位 问题是C中的数组以索引0开始,所以最左边的位置的索引是0,而不是1。因此,如果在第2行中输入1,并将map[row2][column2]=FULL写入,则实际上第二个座位被标记 一个简单的修复方法是编写map[row2-1][column2-1];但请确保用户不能输入值0。您的问题是什么?请回答这个问题,使之更清楚。此外,请尝试将代码缩减为a,这样您可能不需要所有提示和输入—只需硬编码一些值。我的问题是如何在正确的列中获得完整的*标记,

如果我选择1号座位和1号排,它在图表上的标记为 第二排座位

问题是C中的数组以索引0开始,所以最左边的位置的索引是0,而不是1。因此,如果在第2行中输入1,并将map[row2][column2]=FULL写入,则实际上第二个座位被标记


一个简单的修复方法是编写map[row2-1][column2-1];但请确保用户不能输入值0。

您的问题是什么?请回答这个问题,使之更清楚。此外,请尝试将代码缩减为a,这样您可能不需要所有提示和输入—只需硬编码一些值。我的问题是如何在正确的列中获得完整的*标记,因为在购买票证时,它将标记放置在错误的列中。这不是我要减少的代码,我只是运行它来看看不同部分是如何工作的,作为我需要创建的座位表的类似任务的参考。不过,问题得到了回答,谢谢。这是你的问题。你必须尽可能地简单。谢谢!成功了!