我一直是这个网站的潜伏者,现在我需要在这个代码中实现数组的帮助。我不知道如何将代码添加到这里,所以这里的我将如何实现数组到这个代码
#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
你需要在哪里添加数组?出于什么目的? –