Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-28-2012, 11:57 PM   PM User | #1
Chris Hick
Regular Coder

 
Join Date: Oct 2010
Location: Florence, MS
Posts: 476
Thanks: 10
Thanked 33 Times in 32 Posts
Chris Hick is an unknown quantity at this point
vector subscript out of range

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.

Code:
#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;
}
Code:
#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();
}
__________________
Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
I always recommend the HEAD First series of books for learning a new coding language. ^_^
Chris Hick is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:25 PM.


Advertisement
Log in to turn off these ads.