...

View Full Version : vector subscript out of range



Chris Hick
09-28-2012, 11:57 PM
Alright, I am having trouble with my program. It is a pretty large program. When I go to debug it and build it, it throws a vector subscript out of range error window on the screen. I looked through all of my classes and could not find where the subscript could have gone out of range. I will post the classes that use the vector. I really need some help on this one.



#include "BillType.h"

BillType::BillType(vector<FeeType> f)
{
fees = f;
}
BillType::BillType(patientType patient, doctorType doctor, vector<FeeType> f)
{
patient = patient;
doctor = doctor;
fees = f;
}
void BillType::addFee(string name, double amount)
{
FeeType fee(name, amount);
fees.push_back(fee);
}
void BillType::addPatient(patientType p)
{
patient = p;
}
void BillType::addDoctor(doctorType d)
{
doctor = d;
}
void BillType::chargeBill(int feeId)
{
fId.push_back(feeId);
if(feeId < fees.size()){
total = fees[feeId].getAmount();
}
}
void BillType::printBill()
{
for(unsigned int i=0; i<fId.size(); i++)
{
if(fId[i] == true)
{
if(fId[i] <fees.size()){
fees[fId[i]].printFee();
cout<<endl;
}
}
}
cout<<"___________"<<endl;
cout<<total;
}



#include "hospital.h"

Hospital::Hospital()
{
name = "Default Hospital Name";
addMenuOption("View All Patients");
addMenuOption("View All Doctors");
addMenuOption("View All Bills");
addMenuOption("Exit");
addFee("Room Charge", 300.00);
addFee("Surgery", 5000.00);
addFee("Pharmacy Charge", 800.00);
doctorType doc1("James", "Brown","Anesthesiologist");
insertDoctor(doc1);
doctorType doc2("Jennifer", "Walker","Cardiothoracic Surgeon");
insertDoctor(doc2);
dateType pat1DOB(12,25,1977);
dateType pat1DOA(9,3,2012);
dateType pat1DOD(9,20,2012);
patientType pat1("John", "Holmes", "A001",44,pat1DOB,doc1,pat1DOA, pat1DOD);
dateType pat2DOB(5,4,1990);
dateType pat2DOA(8,5,2000);
dateType pat2DOD(8,8,2010);
patientType pat2("Julie", "Teeger", "A002",22, pat2DOB, doc2, pat2DOA, pat2DOD);
insertBill(fees,pat1);
insertBillCharge(1,1);
insertBillCharge(1,2);
insertBill(fees,pat2);
insertBillCharge(2,1);
insertBillCharge(2,2);
insertBillCharge(2,3);

}
Hospital::Hospital(string n)
{
name = n;
addMenuOption("View All Patients");
addMenuOption("View All Doctors");
addMenuOption("View All Bills");
addMenuOption("Exit");
addFee("Room Charge", 300.00);
addFee("Surgery", 5000.00);
addFee("Pharmacy Charge", 800.00);
doctorType doc1("James", "Brown","Anesthesiologist");
insertDoctor(doc1);
doctorType doc2("Jennifer", "Walker","Cardiothoracic Surgeon");
insertDoctor(doc2);
dateType pat1DOB(12,25,1977);
dateType pat1DOA(9,3,2012);
dateType pat1DOD(9,20,2012);
patientType pat1("John", "Holmes", "A001",44,pat1DOB,doc1,pat1DOA, pat1DOD);
dateType pat2DOB(5,4,1990);
dateType pat2DOA(8,5,2000);
dateType pat2DOD(8,8,2010);
patientType pat2("Julie", "Teeger", "A002",22, pat2DOB, doc2, pat2DOA, pat2DOD);
insertBill(fees,pat1);
insertBillCharge(1,1);
insertBillCharge(1,2);
insertBill(fees,pat2);
insertBillCharge(2,1);
insertBillCharge(2,2);
insertBillCharge(2,3);

}
void Hospital::insertDoctor(doctorType doc)
{
doctors.push_back(doc);
}
void Hospital::insertPatient(patientType pat)
{
patients.push_back(pat);
}
void Hospital::insertBill(vector<FeeType> fees, patientType p)
{
BillType bill(p, p.getDoc(), fees);
bills.push_back(bill);
}
void Hospital::insertBillCharge(int billId, int charge)
{
bills[billId].chargeBill(charge);
}
void Hospital::addFee(string des, double amount)
{
FeeType fee(des, amount);
fees.push_back(fee);
}
int Hospital::menuActionCalls(int call)
{
int i =0;
switch(call)
{
case 0:
//printPatients();
cout<<endl;
cout<<endl;
i = 1;
break;
case 1:
//printDoctors();
cout<<endl;
cout<<endl;
i=1;
break;
case 2:
//printBills();
cout<<endl;
cout<<endl;
i = 1;
break;
case 3:
i=0;
break;
default:
i=0;
break;
}
return i;
}
//void Hospital::printPatients()
//{
// for(int i=0; i<patients.size();i++)
// {
// patients[i].print();
// }
//}
//void Hospital::printDoctors()
//{
// for(int i=0; i<patients.size(); i++)
// {
// doctors[i].print();
// }
//}
//void Hospital::printBills()
//{
// for(int i=0; i<bills.size(); i++)
// {
// bills[i].printBill();
// }
//}
int Hospital::getpatientsize()
{
return patients.size();
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum