0

Hello, I am writing a program about gas pump.
Here is my code

class GasPump{
public:
	GasPump();// loads all pumps w/ 50 gallons, price is 2.00, 2.25, 2.50
	GasPump(int l, int m = 100, int h = 100);
	//price is 2.00, 2.25, 2.50
	GasPump(double pl, double pm, double ph);
	// loads all pumps w/ 50 gallons
	
	void setHighGal(int gallons);
	void setMedGal(int gallons);
	void setLow(int gallons);

	void setHighPrice(double price);
	void setMedPrice(double price);
	void setLowPrice(double price);

	int getHigh();
	int getMed();
	int getLow();

	double getPriceHigh();
	double getPriceMed();
	double getPriceLow();
	
	bool emptyHigh();
	bool emptyMed();
	bool emptyLow();

	double salePriceHigh(int gal);
	double salePriceMed(int gal);
	double salePriceLow(int gal);

	double earnedHigh();
	double earnedMed();
	double earnedLow();

	void display(ostream& out) const;

private:
	int highOctane;
	int medOctane;
	int lowOctane;
	double pricehigh;
	double pricemed;
	double pricelow;
	double totalHigh;
	double totalMed;
	double totalLow;
};
GasPump::GasPump(int l, int m, int h){

    emptyHigh();
	emptyMed();
	emptyLow();    
}
	int main()
	{
        int ql, qm, qh, choice;		
	    double plow, pmed, phigh;
		cout << "Welcome to Chevron" << endl;
		cout << "Please enter the quantities of "
		     << "each grade(Regular, Plus, and Premium)" << endl;
        cin  >> ql >> qm >> qh;


        cout << "Now enter the price of each grade"
             << " (Regular, Plus, and Premium)" << endl;
        cin >> plow >> pmed >> phigh;
        cout << "Regular: " << ql << " gallons" << endl;
        cout << "Cost per gallon: $" << plow << endl << endl;;
        cout << "Plus: " << qm << " gallons" << endl;
        cout << "Cost per gallon: $" << pmed << endl << endl;
        cout << "Premium: " << qh << " gallons" << endl;
        cout << "Cost per gallon: $" << phigh << endl << endl;       	
		GasPump pump(ql, qm, qh);
		pump.setLowPrice(plow);
		pump.setMedPrice(pmed);
		pump.setHighPrice(phigh);
		
  do{
			cout << "Which gas type would you want like to buy?\n";
			cout << "\n" << "\n" << "1)Regular\n" << "2)Plus\n"
				 << "3)Premium\n" << "4)Exit\n";  
			cin >> choice;
			switch(choice){
                int gal, gal2;
				case 1: 
                    cout << "How many gallons would you like to buy? " << endl;
                    cin >> gal;
                    pump.salePriceLow(gal);
                    pump.display(cout);
                    break;
				case 2:
                    cout << "How many gallons would you like to buy? " << endl;
                    cin >> gal;
                    pump.salePriceMed(gal);
                    pump.display(cout);
                    break;
				case 3:
                    cout << "How many gallons would you like to buy? " << endl;
                    cin >> gal;
                    pump.salePriceHigh(gal2);
                    pump.display(cout); 
					break;
				default:
					break;
			}

		}while (choice != 4);
		system("PAUSE");
		return 0;
	}

void GasPump::setHighGal(int gallons){
// sets the quantity of gas in the indicated tank to parameter value
//resets total cash for that type of gas to 0     
	highOctane = gallons;
	totalHigh - 0;
}
void GasPump::setMedGal(int gallons){
// sets the quantity of gas in the indicated tank to parameter value
//resets total cash for that type of gas to 0	
	medOctane = gallons;
	totalMed = 0;
}
void GasPump::setLow(int gallons){	
// sets the quantity of gas in the indicated tank to parameter value
//resets total cash for that type of gas to 0
	lowOctane = gallons;
	totalLow = 0;
}
void GasPump::setHighPrice(double price){
//sets the price of gas in the indicated tank to parameter value
	pricehigh = price;
}
void GasPump::setMedPrice(double price){
//sets the price of gas in the indicated tank to parameter value	
	pricemed = price;
}
void GasPump::setLowPrice(double price){
//sets the price of gas in the indicated tank to parameter value	
	pricelow = price;

}
int GasPump::getHigh(){
//returns  # gallons of high octane
	return highOctane;
}
int GasPump::getMed(){
//returns  # gallons of medium octane    
	return medOctane;
}
int GasPump::getLow(){
//returns  # gallons of low octane	
	return lowOctane;
}

double GasPump::getPriceHigh(){
//returns price for high octane
	return pricehigh;
}
double GasPump::getPriceMed(){
//returns price for medium octane
	return pricemed;
}
double GasPump::getPriceLow(){
//returns price for low octane
	return pricelow;
}

double GasPump::salePriceHigh(int gal){
//purchase quantity of high octane, cost of this purchase is returned                       
    highOctane -= gal;
    return totalHigh =(gal*pricehigh);
}
double GasPump::salePriceMed(int gal){
//purchase quantity of meduim octane, cost of this purchase is returned
    medOctane -= gal;
    return totalMed = (gal*pricemed);
}

double GasPump::salePriceLow(int gal){
//purchase quantity of low octane, cost of this purchase is returned
    lowOctane =- gal;
	return totalLow =(gal*pricelow);
}
bool GasPump::emptyHigh(){
//is high octane empty?
	if (highOctane == 0)
		return true;
	else
		return false;
}
bool GasPump::emptyMed(){
//is medium octane empty?
	if (medOctane == 0)
		return true;
	else
		return false;
}
bool GasPump::emptyLow(){
//is low octane empty?	
    if (lowOctane == 0)
		return true;
	else
		return false;

}

double GasPump::earnedHigh(){
// returns total earned for high octane
	return totalHigh;	
}
double GasPump::earnedMed(){
// returns total earned for meduim octane	
    return totalMed;
}
double GasPump::earnedLow(){
// returns total earned for low octane	
	return totalLow;
}

void GasPump::display(ostream& out) const{
     out << "Total HIgh: " << totalHigh << endl;

}

Ok, in the switch statement, I am having some trouble calling the salePriceLow, salePriceMed, salePriceHigh function after I enter 40 gallons. The gal for the salePriceMed should automatically initialize 40.
I'll explain clearly what I want to do
First the user enters number of gallons per grade.
lets say I enter 50, 50, 50
then I enter the price $1, $2, $3
then it should ask the user to pick which grade I want to buy, and then the user ask how many gallons I buy? So I say 40. and it should output
You purchased 40 gallons and output the total cost.
-Buy a quantity of low grade gasoline, displaying the cost of the gasoline. If the low grade tank is empty, display a message to that effect. If the required quantity of gasoline is not available, dispense what is left, and output a message to that effect.
I was take care of med grade, and high grade after you help me solve this problem

I know its long, any help would be appreciated.
Thanks

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by blackbyron
0

First the moan - as this is your 9th post you should know about code tags. Please use them, you'll get more help.
Now some problems:
GasPump::salePriceHigh() is being called with an uninitialised variable (gal2).
GasPump::display() is only outputting the value for totalHigh so obviously won't be correct for low and medium. Think about using a display method for each grade.
That's all I can see immediately, if you still have problems, try and be more specific about the error.

0

Sorry, but how specific do you want to be? My english is not good, and I'm not sure I understand.

Thanks

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.