470,810 Members | 1,433 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,810 developers. It's quick & easy.

parking garage calculator

hi all...i am stuck again with a simple program...
I am supposed to create a parking garage rate calc that follows the
rules up to 3 hours its 2 bucks, after that for its fifty cents. Max
charge for a day can be 10 bucks.

out of everything my taecher has said to do, one line of his
instructions i do not understand: Create four objects of class parking
and initialize them with customer specified parking
hour durations. (Feel free to use an array of objects, if you know how.
However you will
not receive any extra credit for it.)

that and he wrote the int main() portion of the program and i am not
sure how I am supposed to tie it with my part of the program. Please
help...thanks!

Feb 15 '06 #1
7 6368

<vg*****@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
hi all...i am stuck again with a simple program...
I am supposed to create a parking garage rate calc that follows the
rules up to 3 hours its 2 bucks, after that for its fifty cents. Max
charge for a day can be 10 bucks.

out of everything my taecher has said to do, one line of his
instructions i do not understand: Create four objects of class parking
and initialize them with customer specified parking
hour durations. (Feel free to use an array of objects, if you know how.
However you will
not receive any extra credit for it.)

that and he wrote the int main() portion of the program and i am not
sure how I am supposed to tie it with my part of the program. Please
help...thanks!


Do you know how to define a class? If so, define a class called parking.
You probably want to make a constructor for it that accepts the hours to
park, according to the instructions you quoted. Can you do that?

Do you know how to declare a variable of a given type? If so, then declare
four of them in your main function.

If you can't do these things, then I suspect you're not attending classes,
or not reading your textbook(s). If you can do these things, then what's
the problem you're having?

We're not here to simply do your homework for you.

-Howard


Feb 15 '06 #2
Hi,
Usually help is not provided here for Home Works.

vg*****@gmail.com wrote:
Create four objects of class parking
and initialize them with customer specified parking
hour durations. Four separate objects of the class parking (here refered to as
Class_Parking): -

Class_Parking Cust1 = {"Some data here - for initialization"};
Class_Parking Cust2 = {"Some data here - for initialization"}
Class_Parking Cust3 = {"Some data here - for initialization"}
Class_Parking Cust4 = {"Some data here - for initialization"}

(Feel free to use an array of objects, if you know how.
However you will
not receive any extra credit for it.)
Array of objects: -

Class_Parking Cust[4] = {
Class_Parking("Some data here - for initialization Cust1"),
Class_Parking("Some data here - for initialization Cust2"),
Class_Parking("Some data here - for initialization Cust3"),
Class_Parking("Some data here - for initialization Cust4")
}

that and he wrote the int main() portion of the program and i am not
sure how I am supposed to tie it with my part of the program. Please
help...thanks!


No one can help you with this part, unless you let us look at both what
your teacher said and what you have written. In fact the only way you
can encourage others to help you is to show what code you have written
i.e. what attempt you have already made.

O.O

Feb 15 '06 #3
err im an idiot...i forgot to post the code i wrote

parking.h
#include<iostream>

class parking
{
public:
parking();
void set_hour(float);
void calculate_charge();
float get_hour();
float get_charge();

private:
float charge,hour;

};
parking.cpp

#include<iostream>
#include<string>
#include "parking.h"

using std::cout;
using std::cin;
using std::endl;
using std::string;


parking::parking()
{
charge = 0;
hour = 0;
}

void parking::set_hour(float a)
{
charge = a;

}

void parking::calculate_charge()
{
if (hour <= 3 )
charge == 2;
else charge = (.5 * (3 - hour)) + 2;

if ( hour >= 24 )
charge == 10;
}

float parking::get_hour()
{
return hour;
}

float parking::get_charge()
{
return charge;
}

int main()
{

float n1,n2,n3,n4;

cin>>n1;
cout<<n1;
cin>>n2;
cin>>n3;
cin>>n4;
cout<<" "<<n2<<" "<<n3<<" "<<n4;

return 0;
}

Feb 15 '06 #4
and easy on getting pissed off howard...im not here to ask for
answers...i just want pointers. I have been writing code for a long
time...but I learned myself and never learned the terminology for this
stuff. I can make a program that follows his reqz easily but when I do
that, I tend to not include certain instructions he asks for, and thus
I lose points.

I just forgot to post my code...sorry...thanks for the help though!
(and I understand your frustration if i was trying to leech)

Feb 15 '06 #5
Your class parking - does not have a constructor. From the wording of
your teachers statements - it may imply that you are required to have a
constructor in there.

Is this main() function yours - or your teachers. If its your
teachers, then I expect you teacher wants you to have a constructor for
the class parking. Then initialize four objects (or an array of
objects) as I had mentioned in my previous post with n1, n2 ….
Respectively.

O.O.

Feb 15 '06 #6
yeah that main() function is the teachers...thanks

Feb 15 '06 #7

<vg*****@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
err im an idiot...i forgot to post the code i wrote

parking.h
#include<iostream>

class parking
{
public:
parking();
void set_hour(float);
void calculate_charge();
float get_hour();
float get_charge();

private:
float charge,hour;

};
parking.cpp

#include<iostream>
#include<string>
#include "parking.h"

using std::cout;
using std::cin;
using std::endl;
using std::string;


parking::parking()
{
charge = 0;
hour = 0;
}

void parking::set_hour(float a)
{
charge = a;

}

void parking::calculate_charge()
{
if (hour <= 3 )
charge == 2;
The == symbol is the boolean comparison "equal to". To assign a value in
c++, use just one = sign, not two.
else charge = (.5 * (3 - hour)) + 2;

That can't be right. Did you mean "(hour -3)"? If hour is greater than 3,
then your computation will produce negative results.
if ( hour >= 24 )
charge == 10;
Again, use =, not ==.

}

float parking::get_hour()
{
return hour;
}

float parking::get_charge()
{
return charge;
}

int main()
{

float n1,n2,n3,n4;

cin>>n1;
cout<<n1;
cin>>n2;
cin>>n3;
cin>>n4;
cout<<" "<<n2<<" "<<n3<<" "<<n4;


I assume you're supposed to create four parking variables here, and pass
these four floats above as the number of hours for the four parking objects
(either to a constructor or to your set_hour function. Then you can use
cout to display the results of calling get_charge for each object.

return 0;
}

Feb 15 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Rafael | last post: by
3 posts views Thread by Paul | last post: by
3 posts views Thread by quilkin | last post: by
2 posts views Thread by vgame64 | last post: by
24 posts views Thread by firstcustomer | last post: by
2 posts views Thread by cpaucar15 | last post: by
3 posts views Thread by mandy335 | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.