parking garage calculator

V

vgame64

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!
 
H

Howard

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
 
O

olson_ord

Hi,
Usually help is not provided here for Home Works.

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
 
V

vgame64

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;
}
 
V

vgame64

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)
 
O

olson_ord

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.
 
H

Howard

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top