我一直是這個網站的潛伏者,現在我需要在這個代碼中實現數組的幫助。我不知道如何將代碼添加到這裏,所以這裏的我將如何實現數組到這個代碼
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
//Named constants – residential customers
const double RES_BILL_PROC_FEES = 4.50;
const double RES_BASIC_SERV_COST = 20.50;
const double RES_COST_PREM_CHANNEL = 7.50;
//Named constants – business customers
const double BUS_BILL_PROC_FEES = 15.00;
const double BUS_BASIC_SERV_COST = 75.00;
const double BUS_BASIC_CONN_COST = 5.00;
const double BUS_COST_PREM_CHANNEL = 50.00;
int main()
{
//Variable declaration
int accountNumber;
char customerType;
int numOfPremChannels;
int numOfBasicServConn;
double amountDue;
int rescount = 0, buscount = 0;
double ressum = 0.00, bussum = 0.00;
double resavg, busavg;
ifstream fin;
ofstream fout;
//open input file
fin.open("custin.txt", ios::in);
if (fin.fail()) {
cout << "Unable to open file " << endl;
exit(0);
}
//open ouput file
fout.open("custout.txt", ios::out);
fout << fixed << showpoint;
fout << setprecision(2);
fout << "This program computes a cable "
<< "bill." << endl;
//read from input file
while (!fin.eof()) {
//read customer type from file
fin >> customerType;
//read account number from file
fin >> accountNumber;
//If customer type is residential
if (customerType == 'r' || customerType == 'R') {
//read number of prem channels from file
fin >> numOfPremChannels;
amountDue = RES_BILL_PROC_FEES + RES_BASIC_SERV_COST + numOfPremChannels * RES_COST_PREM_CHANNEL;
//write into output file
fout << "Account number: " << accountNumber << endl;
fout << "Amount due: $" << amountDue << endl
<< endl;
//compute running average of residential cusomer's amount due
rescount += 1;
ressum += amountDue;
resavg = ressum/rescount;
}
//If customer type is business
else if (customerType == 'b' || customerType == 'B') {
//read number of service connection from file
fin >> numOfBasicSevConn;
//read number of prem channels from file
fin >> numOfPremChannels;
if (numOfBasicServConn <= 10)
amountDue = BUS_BILL_PROC_FEES + BUS_BASIC_SERV_COST + numOfPremChannels * BUS_COST_PREM_CHANNEL;
else
amountDue = BUS_BILL_PROC_FEES + BUS_BASIC_SERV_COST + (numOfBasicServConn - 10) * BUS_BASIC_CONN_COST + numOfPremChannels * BUS_COST_PREM_CHANNEL;
fout << "Account number: " << accountNumber << endl; //Step 7f
fout << "Amount due: $" << amountDue << endl
<< endl; //Step 7f
//compute running average of business cusomer's amount due
buscount += 1;
bussum += amountDue;
busavg = bussum/buscount;
}
else
fout << "Invalid customer type.in " << accountNumber << endl; //Step 8
}
fout << endl
<< "Average Due for residential Customer " << resavg << endl;
fout << endl
<< "Average Due for Business Customer " << busavg << endl;
fin.close();
fout.close();
return 0;
}
如果你是這個網站的潛伏者,你會知道你需要提供[mcve],具有確切的問題描述,而不是鏈接到外部網站。 –
代碼進入問題,而不是一些非現場文本文件託管服務。 – tadman
你需要在哪裏添加數組?出於什麼目的? –