C++ 复杂的C++;作业
所以我正在研究剧院的座位问题。程序的输出没有按应有的方式排列。我需要帮助将#和*与适当的列对齐。按Q键退出也不起作用。此外,我还需要弄清楚如何从文件中读取座位表信息。如果包含座位信息的文件尚不存在,则意味着所有座位都已关闭 空的。每当程序结束时,座位表信息应存储在此文件中。任何其他提示也会有所帮助。以下是我目前的代码:C++ 复杂的C++;作业,c++,C++,所以我正在研究剧院的座位问题。程序的输出没有按应有的方式排列。我需要帮助将#和*与适当的列对齐。按Q键退出也不起作用。此外,我还需要弄清楚如何从文件中读取座位表信息。如果包含座位信息的文件尚不存在,则意味着所有座位都已关闭 空的。每当程序结束时,座位表信息应存储在此文件中。任何其他提示也会有所帮助。以下是我目前的代码: #include "stdafx.h" # include <iostream> # include <iomanip> using namespace
#include "stdafx.h"
# include <iostream>
# include <iomanip>
using namespace std;
void seats( double [] , int);
void mapSeats();
char movieMenu(char);
int main()
{
const int rowNum = (15.0);
double rowValue[rowNum]; //array to hold row pices
char selection;
int row2, col2;
const char TAKEN = '#';//seats taken
const char EMPTY = '*';//seats free
const int row = 15;//number of rows
const int col = 20;//number of col
char map[row][col];//array to hold seat chart
for(int i= 0;i<row;i++)//initiating array
{
for (int j=0;j<col;j++)
{
map[i][j]=EMPTY;
}
}
mapSeats();
seats(rowValue, rowNum);//ask user to enter price of each row
cout << endl;
do
{
cout << "MOVIE THEATER MENU" << endl;
cout << "------------------" << endl;
cout << "1) Sell a ticket" << endl;
cout << "Q) Quit program" << endl;
cout << "Please make a selection: ";
cin >> selection;
if(selection =='1')
{
cout << "Please enter a row number and a seat number for the ticket: " ;
cout << "Row # :" ;
cin >> row2;
cout << endl;
cout << "Seat # :" ;
cin >> col2;
cout << endl;
// Check if seat is free
if(map[row2][col2] == TAKEN) {
cout << "This seat is taken! Try another one. \n";
continue; // start the loop again
}
else // and if it is - sell the ticket
map[row2][col2]=TAKEN;
// Add the next loop to immediately see the effects:
for (int i = 0; i < row; i++){
for(int j = 0; j < col; j++){
cout << map[i][j];
}
cout << endl;
}
}
else if(selection =='q'||selection=='Q')
{
cout << "Thank you for using the program." << endl;
}
else if(selection != '1' || selection !='q' || selection !='Q')
{
cout << "Invalid selection." << endl;
}
}while(selection != '1' || selection !='q' || selection !='Q');
system("pause");
return 0;
}
void seats(double rowPrice[], int row)
{
cout << "Please enter a ticket price for each row." << endl;
for(int i = 0 ; i < row; i++)
{
cout << "Row # " << i+1 << ": " ;
cin >> rowPrice[i];
}
}
void mapSeats()
{
const char TAKEN = '#';//seats taken
const char EMPTY = '*';//seats free
const int rw=20;
const int cl=15;
cout << "Seats " ;
for(int k = 0 ; k <20;k++) //loop to display nums 0 to 19
{
cout << fixed<< setw(2) << " " << k ;
}
for(int i=0;i<rw;i++)//making array display what's in it
{
cout << endl<< "Row " << i;
for(int j=0;j<cl;j++)
{
cout << fixed<< setw(2) << "" << EMPTY;
}
}
cout << endl;
}
#包括“stdafx.h”
#包括
#包括
使用名称空间std;
空座位(双[],国际);
void mapSeats();
char电影菜单(char);
int main()
{
const int rowNum=(15.0);
double rowValue[rowNum];//用于保存行图片的数组
字符选择;
int row2,col2;
const char taked='#';//已就座
const char EMPTY='*';//座位空闲
const int row=15;//行数
const int col=20;//列数
char map[row][col];//用于保存座位图的数组
for(int i=0;iQ退出不起作用。您的逻辑是错误的
do
{
...
} while (selection !='q' && selection !='Q');
当选择不是“q”和而选择不是“q”时,您可以继续。新手很容易混淆“或”和“与”和“混合”。堆栈溢出不是调试器或代码生成器。欢迎使用。当问问题时,提供关于什么不起作用以及如何不起作用的具体信息非常有用。问题应sk了解修复问题的尝试,并详细描述问题。有关更多信息,请参阅。谢谢!无论如何,您可能希望了解的基础知识。我可以获得有关如何使用库编写此文件的帮助吗?您要求提供提示:清除名称:seats(rowValue,rowNum);//要求用户输入每行的价格
表明seats不是函数的清晰名称。其他大多数名称也是如此。名称应显示变量/function/type/…的意图,太长比太晦涩+1好,但“您的逻辑错误”然后,一些代码使您听起来像是在提取损坏的代码,而不是呈现固定的代码…:-)