- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在研究一个杂项剧院座位计划!我刚刚开始通过 C++ 取得进展,但我无法弄清楚我在编码中不断遇到的这个错误。我目前正在尝试编码的是一种逐字符输入“*”的方法,最终帮助我构建一个函数来显示电影院的座位表。我非常接近完成名为 readSeating 的函数......尽管它存在一些明显的问题。通常我可以非常有效地调试我的程序,但我就是想不通这个。请看看我的代码,感受一下我的程序,让我有任何想法。请让答案简单一些;再一次,我不是 C++ 的高手
附言
抱歉显示了整个代码...这是我的第一篇文章...我真的不知道该包含什么,不该包含什么;我希望人们能够通过自己测试来感受该程序...再次感谢!
/*
* 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");
}
最佳答案
首先(我认为这是你打算写的)
int readSeating (char, vector<char>&);
应该是
int readSeating (char*, vector<char>&);
^^^
第一个参数需要一个左值
。这意味着它可以简单地分配给某些东西。
不管你怎么调用它
readSeating("SeatingChart.txt", seating);
通过为第一个参数传递一个临时变量。编译器想知道你不会修改它是为了让你通过一个临时的。您可以通过声明函数来告诉它您不会修改它。
int readSeating (const char*, vector<char>&);
^^^^
同样适用
int readSeating(char myFile, vector<char>& vect)
到
int readSeating(const char* myFile, vector<char>& vect)
我建议您继续将它们更改为字符串
。
int readSeating (string, vector<char>&);
int readSeating(string myFile, vector<char>& vect)
关于c++ - 从 'const char*' 到 'char' 的无效转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16099731/
这个问题在这里已经有了答案: Why don't Java's +=, -=, *=, /= compound assignment operators require casting? (11 个
当我尝试运行以下代码时,List(.of) 无法编译并给出主题错误。 package collections; import java.util.LinkedHashSet; import java.
我正在尝试编译使用 ChatScript 库的程序。这是我在名为 main.cpp 的文件中的代码: #include #include "common.h" using namespace std
我想在我的程序中外部使用 ChatScript。在documents它说: Embedding Step #1 First, you will need to modify `common.h and
假设我有一个 char,我想用一行代码将其 strcat() 转换为 char 数组。对于 [一个非实用的] 示例: strcat("ljsdflusdfg",getchar()); 或者我想做相反的
我有以下类型签名: *Main Lib> let f :: a -> a -> a -> a; f = undefined *Main Lib> let x :: Char; x = undefin
我正在学习如何在 C 中使用指针(使用 malloc 和 free),但我在这个练习中遇到了一些麻烦。我只想制作一个指针数组,我想在其中保存每个单词的方向。然后我想为一个特定的词做一个 free(),
我有一个字符*: char* version = "10.5.108"; 我想通过字符分隔符获取两个新的 char*。 char delimiter = '.'; 执行以下代码后: printf("|
最近在学习Cpp,今天在学习使用Clion做测试的时候,发生了奇怪的事情。 这是我的代码 int main() { char c = 'b'; char carr[1]{'a'};
我对 c 很陌生,我正在审查一些代码。我遇到了这个: static char * fromDataType; static char * toDataType; static char * fromR
我有一个像这样的动态结构: struct network { int count; char** ips; } 如果我知道每个字符串数组都是 16 个字节(即 INET_ADDRSTR
我有一个旧程序,其中使用了一些库函数,但我没有那个库。 所以我正在使用 C++ 库编写该程序。在那个旧代码中有一些函数是这样调用的 *string = newstrdup("这里有一些字符串"); 字
我正在编写一个函数,该函数接受 ArrayList,然后将每个 char[] 复制到另一个增加长度的 char[] 中,然后将新的 char[] 添加到新的 ArrayList 中。当我尝试复制数组时
我正在寻找 map >并生成每个可能的 map从它。 我知道这可能会占用大量内存并需要一些时间。 每个map需要包含每个字母 a-z,并映射到唯一的 a-z 字符。 IE。啊bjcp迪EVfh嘎血红蛋
#define NAME_LEN 20 #include "stdio.h" #include "stdlib.h" #include "string.h" #pragma warning(disab
所以我必须创建一个函数来找到一对带有第一个字母并返回第二个字母的函数。 我实际上找到了一个答案,但是使用 map 功能却找不到。 lookUp :: Char -> [(Char, Cha
我最近接受采访并要求写mystrcat(*s1, *s2, *s3) 其中s1 和s2 是源字符串连接结果由 s3 给出。有人告诉我,不要担心 s3 的内存分配,并假设 s1 和 s2 不是空/无效字
今天我与一位同事讨论了他(对我来说)不寻常的“main”函数签名。他喜欢这样声明: int main(int argc, char* (*argv)[]) { printf("at index
这个问题在这里已经有了答案: 关闭 12 年前。 Possible Duplicate: What's the difference between new char[10] and new cha
通常字符串文字是 const char[] 类型。但是当我把它当作其他类型时,我得到了奇怪的结果。 unsigned char *a = "\355\1\23"; 使用此编译器会抛出警告“初始化中的指
我是一名优秀的程序员,十分优秀!