How to create class

Hi experts! Can some one help in explaining the step i can take to create class name "Parking" in a parking ticket calculating system, with member function that will compute the total hours charge after spending 3. the parking rate is $1.50 for the 1st hour and $1.20 for every subsequent hour.
Step # 1: make a class.

1
2
3
4
5
6
7
8
9
 class parkingCalc{
 protected:
 float rate;
 float firstHour;
 public:
 void set_rate(float set);
 void set_firstHour(float set);
 void get_total(int hours);
 };
thanks alot.
kindly can you explain it a little further.
What i understood from the above is:
line 1: created class type "parkingCalc"
line 2-4: declares 2 member data with access specifier - private - of type - float
line 6-8: declares 3 member functions with access specifier - public - of type - void(what is
meaning of void here)
How can i use these parameters in the main function.

I really appreciate your input.
It might be useful to read through this: http://cplusplus.com/doc/tutorial/classes/
Thanks. i have read the section for classes, but could not make any meaning out of it. May be because i am new to C++.
I will really appreciate your input on the above.
By void he means the function will not return anything as it is .... Void. You can also have void as an argument parameter such as:
int displayTotal (void);
In this example it would return an integer (that being the total parking ticket) but would require no additional information as an argument ... thus again being void.

I like to think of it as a machine demonstrated in this amazing piece of artwork I did for you:
http://i1105.photobucket.com/albums/h349/Father_Sloth/Functiondiagram.png

Hope this helps :)

- Simon

*edit: link fixed
Last edited on
try something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

class calculate
{
	double hours;
	double total;
public:
	calculate(int);
	void findTotal();
};

calculate::calculate(int data)
{
	total = 1.5;
	hours = data - 1;
}

void calculate::findTotal(void)
{
	while (hours > 0)
	{
		total += 1.2;
		hours--;
	}
	cout << "You owe: $" << total << endl;
}

int main()
{
	string entered;
	int length;
	
	cout << "How many hours were you parked: ";
	cin >> entered;
	stringstream(entered) >> length;
	
	calculate total(length);
	total.findTotal();
	
	system("pause");

	return 0;	
}
@father sloth
AMAZING ARTWORK xD musta' takin days! xD as far as the classes go I think I'm a little late to help out.
Topic archived. No new replies allowed.