Classes Problem

Hi! So maybe you can help me spot my error. We just started learning about classes and constructors and I'm working on an assignment that asks the following:

Write the interface (.h file) of a class GasTank containing:
An data member named amount of type double .
A constructor that accepts no parameters .
A function named addGas that accepts a parameter of type double and returns no value .
A function named useGas that accepts a parameter of type double and returns no value .
A function named isEmpty that accepts no parameters and returns a boolean value .
A function named getGasLevel that accepts no parameters and returns double .

I've tried a lot of different things but it keeps telling me stuff like I don't have the right return type for addGas. Any help?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class GasTank {
	public:
		GasTank() {
		
		}
		void addGas(double add_1) {
			
		}
		void useGas(double use_1) {
		
		}
		bool isEmpty() {

		}
		double getGasLevel() {

		}
	private:
		double amount;
		double add_1;
		double use_1;
};
Try getting rid of all of the curly braces in your public and replace them with the semi-colon. For example: GasTank ();
The WHY for ^^^^

if you studied functions outside of objects, its the same thing.

in a header file you have
void foo(int x); // header for the function!

and in the cpp file you have

void foo(int x)
{
stuff;
}


classes work *exactly* the same way in this context.
inside the header, and the class definition, you have function headers:

class GasTank {
public:
GasTank();
...


and later you will have the body in the cpp file..

GasTank :: GasTank () // format is <type> classname::classfunctionname (params)
{
amount = 10; //example using your variables
}


Last edited on
Okay, thanks!
Topic archived. No new replies allowed.