472,955 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,955 software developers and data experts.

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 6592

<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Rafael | last post by:
Hi Everyone, I need some help with my calculator program. I need my program to do 2 arguments and a 3rd, but the 3rd with different operators. Any help would be great. Here is my code.... ...
3
by: Paul | last post by:
I want to make a simple calculator program but dont know where to get started. This is not GUI but a simple terminal program. It would get input like this Enter number: 5 + 10
3
by: quilkin | last post by:
Hi When I use the WM_QUERYENDSESSION event to prevent closing of my app when Windows is shut down, I get the 'windows forms parking window' appearing which is very confusing for users. Any ideas...
2
by: vgame64 | last post by:
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...
24
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
19
by: TexasNewbie | last post by:
This was originally just a calculator without a decimal point. After I added the decimal, it now tells me invalid second number. //GUI Calculator Program import javax.swing.*; import...
2
by: cpaucar15 | last post by:
I have this homework and all help will be apreciated The Putdentsinem Parking Garage contains a single lane that holds up to 7 cars. Cars arrive at the south end of the ...
3
by: itsmichelle | last post by:
This is a very primative code of a java swing calculator. I have assigned all the number buttons and the operator buttons and I can add, subtract, multiply, and divide two numbers together. However,...
3
by: mandy335 | last post by:
public class Calculator { private long input = 0; // current input private long result = 0; // last input/result private String lastOperator = ""; // keeps track of...
1
by: borla123 | last post by:
Hi- I'm trying to make an application that computes the fee for parking a car in a parking garage. The user should provide the Time In: and Time Out: values by using DateTimePickers. The...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
1
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.