我在分配时遇到了一些麻烦,我需要生成一个由数组中的结构组成的数据库文件。 Currently when the selection is made to print the table no noticeable error occurs, but no file is produced by the code. (如果这很乱,我们深表歉意,该网站还是新手)
这是我当前的代码
原型:
void ordertable_disp( item s[], int size);
void print_ordertable_disp(item s[], int size);
表格功能:
void ordertable_disp(item s[], int size)
{
int counter = 0;
int BookOrder = 0;
int enroll = 0;
double AllOrders = 0.0;
double OrderFactor = 0.0;
double total_value = 0.0;
double bprice = 0.0;
string resp = "XXX";
system("cls");
cout << endl;
cout << " COLLEGE BOOK ORDERING SYSTEM" << endl;
cout << endl;
cout << " Book Order Table" << endl;
cout << endl;
cout << endl;
cout << setw(40) << "Book Title" << " " << setw(15) << "ISBN" << " " << setw(20) << "Author" << " " << setw(19) << "Expected Enrollment" << " " << setw(17) << "Book Cost (Price)" << " " << setw(9) << "Required" << " " << setw(7) << "Unused" << endl;
cout << setw(40) << "----------" << " " << setw(15) << "----" << " " << setw(20) << "------" << " " << setw(19) << "-------------------" << " " << setw(17) << "-----------------" << " " << setw(9) << "--------" << " " << setw(7) << "------" << endl;
for(counter = 0; counter < size; counter++)
{
cout << setw(40) << s[counter].BookTitle << " " << setw(15) << s[counter].ISBN << " " << setw(20) << s[counter].Author << " " << setw(19) << s[counter].EXPenroll << " " << setw(17) << s[counter].price << " " << setw(9) << s[counter].reqNreq << " " << setw(7) << s[counter].UsedUnused << endl;
if((s[counter].reqNreq== "Y") || (s[counter].reqNreq== "y"))
{
if((s[counter].UsedUnused== "Y") || (s[counter].UsedUnused== "y"))
{
OrderFactor= 1.0; // Book is new and required
}
else
{
OrderFactor= 0.60; // Book is used and required
}
}
else // Order factor calculation
{
if((s[counter].UsedUnused== "Y") || (s[counter].UsedUnused== "y"))
{
OrderFactor= 0.35; // Book is new and not required
}
else
{
OrderFactor= 0.10; // Book is used and not required
}
}
enroll = atoi(s[counter].EXPenroll.data());
BookOrder= OrderFactor * enroll;
bprice = atof(s[counter].price.data());
total_value = total_value +(total_value = bprice * BookOrder);
} cout << " Total Order Value: " << total_value << endl;
cout << " Would You Like To Print This Table(Y/N): "; getline(cin, resp);
if(toupper(resp.at(0))=='Y')
void print_ordertable_disp(item s[], int size);
system("cls");
}
打印功能:
void print_ordertable_disp(item s[], int size)
{
ofstream ofile;
ofile.open("Sample2.prn");
int counter = 0;
int BookOrder = 0;
int enroll = 0;
double AllOrders = 0.0;
double OrderFactor = 0.0;
double total_value = 0.0;
double bprice = 0.0;
system("cls");
ofile << endl;
ofile << " COLLEGE BOOK ORDERING SYSTEM" << endl;
ofile << endl;
ofile << " Book Order Table" << endl;
ofile << endl;
ofile << endl;
ofile << setw(40) << "Book Title" << " " << setw(15) << "ISBN" << " " << setw(20) << "Author" << " " << setw(19) << "Expected Enrollment" << " " << setw(17) << "Book Cost (Price)" << " " << setw(9) << "Required" << " " << setw(7) << "Unused" << endl;
ofile << setw(40) << "----------" << " " << setw(15) << "----" << " " << setw(20) << "------" << " " << setw(19) << "-------------------" << " " << setw(17) << "-----------------" << " " << setw(9) << "--------" << " " << setw(7) << "------" << endl;
for(counter = 0; counter < size; counter++)
{
ofile << setw(40) << s[counter].BookTitle << " " << setw(15) << s[counter].ISBN << " " << setw(20) << s[counter].Author << " " << setw(19) << s[counter].EXPenroll << " " << setw(17) << s[counter].price << " " << setw(9) << s[counter].reqNreq << " " << setw(7) << s[counter].UsedUnused << endl;
if((s[counter].reqNreq== "Y") || (s[counter].reqNreq== "y"))
{
if((s[counter].UsedUnused== "Y") || (s[counter].UsedUnused== "y"))
{
OrderFactor= 1.0; // Book is new and required
}
else
{
OrderFactor= 0.60; // Book is used and required
}
}
else // Order factor calculation
{
if((s[counter].UsedUnused== "Y") || (s[counter].UsedUnused== "y"))
{
OrderFactor= 0.35; // Book is new and not required
}
else
{
OrderFactor= 0.10; // Book is used and not required
}
}
enroll = atoi(s[counter].EXPenroll.data());
BookOrder= OrderFactor * enroll;
bprice = atof(s[counter].price.data());
total_value = total_value +(total_value = bprice * BookOrder);
} ofile << " Total Order Value: " << total_value << endl;
ofile.close();
}
在这段代码中:
cout << " Would You Like To Print This Table(Y/N): "; getline(cin, resp);
if(toupper(resp.at(0))=='Y')
void print_ordertable_disp(item s[], int size);
你似乎是在重新声明函数签名而不是调用函数。
这应该看起来像:
cout << " Would You Like To Print This Table(Y/N): "; getline(cin, resp);
if(toupper(resp.at(0))=='Y')
print_ordertable_disp(s, size);
注意我已经删除了关键字
void
并传递了s
和size
而不是重新定义它们。
我认为这很可能是您的问题开始的地方。