그래서 프로그램은 4-5 줄의 정보가있는 파일에서 읽어야합니다. 프로그램의 첫 번째 줄을 읽고 다양한 알고리즘을 통해 처리 할 수 있지만 파일 끝에 다음 줄을 반복하여 처리하는 방법을 잘 모릅니다. 독서에 대단히 감사 드리며 모든 의견을 환영합니다. 다음은 전체 프로그램입니다. 하단의 파일에서 텍스트를 읽어들입니다.파일에서 다음 줄을 읽음
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream inputFile;
ofstream invoicefile;
string name, author, isbn, customerid, filename, fictionoutput, genreoutput;
char booktype, genre;
bool fictionvalue;
double initial_total, tax_price, subtotal, totalprice, price;
int fee, quantity;
const double tax(0.07);
cout << "Enter name of file.\n";
cin >> filename;
cout << "Opening file \n";
inputFile.open(filename);
if (inputFile.is_open()) {
inputFile >> customerid >> name >> author >> isbn >> price >> quantity >> booktype >> genre;
//QUANTITY FEE CODING BLOCK
if (quantity > 50) {
fee = 50;
}
else if (quantity >= 15 && quantity <= 19) {
fee = 40;
}
else if (quantity >= 10 && quantity <= 14) {
fee = 30;
}
else if (quantity >= 5 && quantity <= 10) {
fee = 20;
}
else if (quantity < 5) {
fee = 10;
}
//BOOKTYPE CODING BLOCK (FICTION or NON-F)
if (booktype == 'F') {
fictionvalue = true;
}
else if (booktype == 'N') {
fictionvalue = false;
}
else {
cout << "INVALID";
}
//BOOKTYPE INTO STRING OUTPUT
if (fictionvalue = true) {
fictionoutput = "Fiction";
}
else if (fictionvalue = false) {
fictionoutput = "Non-Fiction";
}
//GENRE TYPE INTO STRING OUTPUT
if (genre == 'R') {
genreoutput = "Romance";
}
else if (genre == 'D') {
genreoutput = "Drama";
}
else if (genre = 'M') {
genreoutput = 'M';
}
else {
cout << "Invalid entry\n";
}
//NO FEE EXCEPTION
if (booktype == 'N' && genre == 'R') {
fee = 0;
}
//CALCULATION OF PRICE + TAX CODING BLOCK
initial_total = (price*quantity);
tax_price = (initial_total * tax);
subtotal = (initial_total + tax_price);
totalprice = (subtotal + fee);
//OUTPUT TO FILE/CONSOLE CODING BLOCK
cout << "-----------------------------------------" << endl;
cout << "Order Invoice" << endl;
cout << "Customer ID: " << customerid << endl;
cout << name << " " << author << " " << fictionoutput << " " << genreoutput << " " << quantity << "@" << price << "Subtotal: " << endl; //add subtotal price
//cout << "Total book sales: " <<
cout << "Tax: " << tax_price << endl;
cout << "Subtotal: " << subtotal << endl;
cout << "Fee: " << fee << endl;
cout << "Total Price: " << totalprice << endl;
cout << "-----------------------------------------" << endl;
system("pause");
}
}
텍스트 SAMPLE
1234 Dog_Strategy Henry_Moreno 3-598-21500-2 12.99 5 N M
6789 Companion_Kicked_Me_Out Lorraine_Johnson 3-598-21599-1 24.99 3 F R
3444 Mime_On_My Journey Kristy_Wahl 3-699-21500-8 6.75 10 N D
4455 Damaged_By_The_Joke Henry_Christopher 3-598-21500-2 12.99 4 N R
스택 오버플로에 오신 것을 환영합니다. 제목에 태그 정보를 반복 할 필요는 없습니다. 또한 도움이 필요하지 않은 경우 여기에 게시하지 않기 때문에 도움말을 외칠 필요가 없습니다. 대신, 더 나은 제목을 쓰는 노력을하십시오. 기존 게시물에 대한 검색은 C++에서 한 줄씩 파일을 읽는 것에 대해 수십 가지가 있으므로 여기에서 검색하는 것이 좋습니다. –