To create a "class object"

Apr 10, 2011 at 2:49pm
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.
Apr 10, 2011 at 4:36pm
1
2
3
4
5
struct Parking{
   float rate1, rate2;
   
   float getCost(float time);
}
?
Apr 10, 2011 at 4:48pm
thanks. but how can am i going to use the struct in the main function.
Apr 10, 2011 at 6:12pm
This struct you'd use like
1
2
3
Parking p(1.5, 1.2);//I assume you'd write a constructor
int n = 5;
std::cout << "After " << n << " hours, you'll have to pay $" << p.getCost(n) << '\n'; 

Note that I don't know if that is what your assignment wants you to do.
Last edited on Apr 10, 2011 at 6:12pm
Topic archived. No new replies allowed.