-
Parking Garage program
[code]So, not sure if my other post took since I tried to look for it and cannot find it but I'm a first time poster and just now saw how to enter code so I'm going to repeat myself:
I feel really dumb not being able to figure this out but in the pseudo code it says:
A-1-1-21) through A-1-1-24) Enter function header for private member function calculateCustomerParkingCharge and opening brace for function’s body
Now the private is already there so I'm not quote sure how I'm suppose to use up 4 lines on this like I think it should be void calculateCusomterParkingCharge() { but that is only one line......
there is a couple of of those in this program but normally it breaks it down by line and not 21 thru 24 etc.
<< awful formatted code snipped - see replies >>
-
<< awful formatted code snipped - see replies >>
-
Ok so I tried twice to post the [code] deal and its not coming out quite right grrrr..............sorry
-
You need to get rid of every comment and line number or whatever those are. I can't even read that and I guarantee nobody else will even bother.
-
Well you need to try posting something as text, not as HTML.
In whatever you're copying from, rather than pressing ctrl-c, see if there is a "copy as text" option.
If that doesn't work, first paste the content into something "dumb", like notepad, then redo the ctrl-a ctrl-c bit. That should wash away all the horrible formatting.
Anyway, this is your code with the useless HTML font/size/colour removed.
Code:
#include
< iostream > // A-1-1-04
#include
<iomanip > // A-1-1-05
#include
<string > // A-1-1-06
#include
<cmath > // A-1-1-07
#include
<cstdlib > // A-1-1-08
using namespace std; // A-1-1-09
class Garage { // A-1-1-10
public: // A-1-1-11
void prepareDailyReceiptsReport() { // A-1-1-12
int hoursParkedByCustomer[c_customerCount]; // A-1-3-001 DONE?
int customerNumber; // A-1-3-002
double totalParkingReceipts = 0; // A-1-3-003 DONE
double parkingCharge; // A-1-3-004 DONE
bool usedMaximumParkingCharge = false; // A-1-3-005 TODO
bool usedMinimumParkingCharge = false; // A-1-3-006 TODO
getDailyParkingActivity(hoursParkedByCustomer);
// A-1-3-007 TODO
cout << "\n\nToday's Parking Receipts:\n"; // A-1-3-008
displayColumnHeadings();
// A-1-3-009
for (customerNumber = 1; customerNumber <= getCustomerCount(); customerNumber++) { // A-1-3-010
calculateCustomerParkingCharge
// A-1-3-011 TODO
(hoursParkedByCustomer[customerNumber - 1],
// A-1-3-012 TODO
usedMaximumParkingCharge,
// A-1-3-013 TODO
usedMaximumParkingCharge
// A-1-3-014 TODO
= parkingCharge);
// A-1-3-015 TODO
totalParkingReceipts += parkingCharge;
// A-1-3-016 TODO
displayThisCustomer
// A-1-3-017 TODO
(customerNumber,
// A-1-3-018 TODO
hoursParkedByCustomer[customerNumber - 1],
// A-1-3-019 TODO
parkingCharge,
// A-1-3-020 TODO
usedMaximumParkingCharge,
// A-1-3-021 TODO
usedMinimumParkingCharge)
// A-1-3-022 TODO
}
// for // A-1-3-023
displayReportSummaryLine(totalParkingReceipts, "Total Receipts"; // A-1-3-024 TODO
displayReportSummaryLine
// A-1-3-025 TODO
(totalParkingReceipts / getCustomerCount(), "Average Fee") // A-1-3-026 TODO
}
// function prepareDailyReceiptsReport // A-1-1-13
private: // A-1-1-14
const static int c_customerColumnWidth = 8; // A-1-1-15
const static int c_customerCount = 30; // A-1-1-16
const static int c_defaultChargeColumnWidth = 7; // A-1-1-17
const static int c_interColumnWidth = 3; // A-1-1-18
const static int c_hoursParkedColumnWidth = 6; // A-1-1-19
const static int c_parkingChargeColumnWidth = 7; // A-1-1-20
// A-1-1-21 TODO
// A-1-1-22 TODO
// A-1-1-23 TODO
// A-1-1-24 TODO
double c_minimumParkingCharge = 2.0; // A-1-3-027 TODO
double c_maximumParkingCharge = 10.0; // A-1-3-028 TODO
double c_maximumParkingHoursForMinimumParkingCharge = 3.0; // A-1-3-029 TODO
double c_chargePerHourAfterMinimum = .5; // A-1-3-030 TODO
double parkingCharge = c_minimumParkingCharge; // A-1-3-031 TODO
if hoursParked > c_minimumParkingCharge { // A-1-3-032 TODO
(c_minimumParkingCharge +
c_chargePerHourAfterMinimum
// A-1-3-033 TODO
* ceil(hoursParked
// A-1-3-034 TODO
-
c_maximumParkingHoursForMinimumParkingCharge)
// A-1-3-035 TODO
= parkingCharge;}
// A-1-3-036 TODO
if (parkingCharge > c_maximumParkingCharge) { // A-1-3-037 TODO
usedMaximumParkingCharge = true; // A-1-3-038 TODO
parkingCharge = c_maximumParkingCharge;
// A-1-3-039 TODO
}
else { // A-1-3-040 TODO
usedMaximumParkingCharge = false;} // A-1-3-041 TODO
if parkingCharge = c_minimumParkingCharge // A-1-3-042 TODO
usedMinimumParkingCharge = true; // A-1-3-043 TODO
else // A-1-3-044 TODO
usedMinimumParkingCharge = false; // A-1-3-045 TODO
return parkingCharge; // A-1-3-046 TODO
}
// A-1-1-25 EDIT NAME ON THIS
void displayColumnHeadings() { // A-1-1-26
cout << "\n\t" << right // A-1-3-047
<< setw(getCustomerColumnWidth()) << "Customer" // A-1-3-048
<< setw(getInterColumnWidth()) << " " // A-1-3-049
<< setw(getHoursParkedColumnWidth()) << "Hours " // A-1-3-050
<< setw(getInterColumnWidth()) << " " // A-1-3-051
<< setw(getParkingChargeColumnWidth()) << "Parking" // A-1-3-052
<< setw(getInterColumnWidth()) << " " // A-1-3-053
<< setw(getDefaultChargeColumnWidth()) << "Default"; // A-1-3-054
cout << "\n\t" << right // A-1-3-055 TODO
<< setw(getCustomerColumnWidth()) << "Number" // A-1-3-056 TODO
<< setw(getInterColumnWidth()) << " " // A-1-3-057 TODO
<< setw(getHoursParkedColumnWidth()) << "Parked" // A-1-3-058 TODO
<< setw(getInterColumnWidth()) << " " // A-1-3-059 TODO
<< setw(getParkingChargeColumnWidth()) << "Fee" // A-1-3-060 TODO
<< setw(getInterColumnWidth()) << " " // A-1-3-061 TODO
<< setw(getDefaultChargeColumnWidth()) << "Charge"; // A-1-3-062 TODO
cout << "\n"; // A-1-3-063 TODO
}
// function displayColumnHeadings // A-1-1-27
// A-1-1-28 TODO
// A-1-1-29 TODO
// A-1-1-30 TODO
// A-1-3-064 TODO
// A-1-3-065 TODO
// A-1-3-066 TODO
// A-1-3-067 TODO
// A-1-3-068 TODO
// A-1-3-069 TODO
// A-1-3-070 TODO
// A-1-3-071 TODO
// A-1-3-072 TODO
// A-1-3-073 TODO
// A-1-1-31 TODO
void displayThisCustomer // A-1-1-32
(int customerNumber, // A-1-1-33
int hoursParked, // A-1-1-34
double parkingCharge, // A-1-1-35
bool usedMaximumParkingCharge, // A-1-1-36
bool usedMinimumParkingCharge) { // A-1-1-37
string defaultChargeLiteral;
// A-1-3-074
if (usedMaximumParkingCharge == true) // A-1-3-075
defaultChargeLiteral = "Maximum"; // A-1-3-076
else // A-1-3-077
if (usedMinimumParkingCharge == true) // A-1-3-078
defaultChargeLiteral = "Minimum"; // A-1-3-079
else // A-1-3-080
defaultChargeLiteral = "-- "; // A-1-3-081
// A-1-3-082 TODO
// A-1-3-083 TODO
// A-1-3-084 TODO
// A-1-3-085 TODO
// A-1-3-086 TODO
// A-1-3-087 TODO
// A-1-3-088 TODO
// A-1-3-089 TODO
// A-1-3-090 TODO
// A-1-3-091 TODO
// A-1-3-092 TODO
}
// function displayThisCustomer // A-1-1-38
int getCustomerCount() { // A-1-1-39
return c_customerCount; // A-1-3-093
}
// function getCustomerCount // A-1-1-40
int getCustomerColumnWidth() { // A-1-1-41
return c_customerColumnWidth; // A-1-3-094
}
// function getCustomerColumnWidth // A-1-1-42
void getDailyParkingActivity(int hoursParkedByCustomer[]) { // A-1-1-43
const int c_maximumHoursParked = 24; // A-1-3-095
srand(12321);
// A-1-3-096
for (int customerNumber = 1; customerNumber <= getCustomerCount(); // A-1-3-097
customerNumber++) {
// A-1-3-097
hoursParkedByCustomer[customerNumber - 1] =
1 + rand() % c_maximumHoursParked;
// A-1-3-098
}
// for // A-1-3-099
}
// function getDailyParkingActivity // A-1-1-44
int getDefaultChargeColumnWidth() { // A-1-1-45
return c_defaultChargeColumnWidth; // A-1-3-100
}
// function getChargeColumnWidth // A-1-1-46
int getHoursParkedColumnWidth() { // A-1-1-47
return c_hoursParkedColumnWidth; // A-1-3-101
}
// function getHoursParkedColumnWidth // A-1-1-48
int getInterColumnWidth() { // A-1-1-49
return c_interColumnWidth; // A-1-3-102
}
// function getInterColumnWidth // A-1-1-50
int getParkingChargeColumnWidth() { // A-1-3-51
return c_parkingChargeColumnWidth; // A-1-3-103
}
// function getParkingChargeColumnWidth // A-1-1-52
};
// class Garage // A-1-1-53
int main() { // A-1-5-01
Garage myGarage;
// A-1-5-02 DONE
string enterKey;
// A-1-5-03
cout << "\nTask 09-02, Ch06, Programmed by XXXXXXXX"; // A-1-5-04
myGarage.prepareDailyReceiptsReport();
// A-1-5-05 DONE
cout << ("\n\nEnd of Program: Press <Enter> to exit program."); // A-1-5-06
getline(cin, enterKey);
// A-1-5-07
}
// function main
Now, can you
a) post an even better copy with better indentation
b) explain what all those A-n-n-n comments are for. If you want to refer to line numbers in the code, then the board automatically numbers the code anyway.
c) explain what you're expecting for all those "TO DO" comments.
-
Ok, here goes, I've removed most of the A-x-x-x (which is the sheet/code that were supposed to write from. The part I'm trying to figure out the code sheet says to:
A-1-1-21) through A-1-1-24) Enter function header for private member function calculateCustomerParkingCharge and opening brace for function’s body
Thanks, and sorry if I hurt anybody's eyes!
Code:
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <cstdlib>
using namespace std;
class Garage {
public:
void prepareDailyReceiptsReport() {
int hoursParkedByCustomer [ c_customerCount ];
int customerNumber;
double totalParkingReceipts = 0;
double parkingCharge;
bool usedMaximumParkingCharge = false;
bool usedMinimumParkingCharge = false;
getDailyParkingActivity(hoursParkedByCustomer);
cout << "\n\nToday's Parking Receipts:\n";
displayColumnHeadings();
for (customerNumber=1;customerNumber<=getCustomerCount();customerNumber++) {
calculateCustomerParkingCharge
(hoursParkedByCustomer[customerNumber-1],
usedMaximumParkingCharge,
usedMaximumParkingCharge
= parkingCharge);
totalParkingReceipts += parkingCharge;
displayThisCustomer
(customerNumber,
hoursParkedByCustomer[customerNumber-1],
parkingCharge,
usedMaximumParkingCharge,
usedMinimumParkingCharge)
} // for
displayReportSummaryLine(totalParkingReceipts,"Total Receipts";
displayReportSummaryLine
(totalParkingReceipts/getCustomerCount(), "Average Fee")
} // function prepareDailyReceiptsReport
private:
const static int c_customerColumnWidth = 8;
const static int c_customerCount = 30;
const static int c_defaultChargeColumnWidth = 7;
const static int c_interColumnWidth = 3;
const static int c_hoursParkedColumnWidth = 6;
const static int c_parkingChargeColumnWidth = 7;
// A-1-1-21 TODO
// A-1-1-22 TODO
// A-1-1-23 TODO
// A-1-1-24 TODO
double c_minimumParkingCharge = 2.0;
double c_maximumParkingCharge = 10.0;
double c_maximumParkingHoursForMinimumParkingCharge = 3.0;
double c_chargePerHourAfterMinimum = .5;
double parkingCharge = c_minimumParkingCharge;
if hoursParked > c_minimumParkingCharge {
(c_minimumParkingCharge + c_chargePerHourAfterMinimum
* ceil(hoursParked
- c_maximumParkingHoursForMinimumParkingCharge)
= parkingCharge;}
if (parkingCharge > c_maximumParkingCharge){
usedMaximumParkingCharge = true;
parkingCharge = c_maximumParkingCharge;
} else {
usedMaximumParkingCharge = false;}
if parkingCharge = c_minimumParkingCharge
usedMinimumParkingCharge = true;
else
usedMinimumParkingCharge = false;
return parkingCharge;
}
void displayColumnHeadings() {
cout << "\n\t" << right
<< setw(getCustomerColumnWidth()) << "Customer"
<< setw(getInterColumnWidth()) << " "
<< setw(getHoursParkedColumnWidth()) << "Hours "
<< setw(getInterColumnWidth()) << " "
<< setw(getParkingChargeColumnWidth()) << "Parking"
<< setw(getInterColumnWidth()) << " "
<< setw(getDefaultChargeColumnWidth()) << "Default";
cout << "\n\t" << right
<< setw(getCustomerColumnWidth()) << "Number"
<< setw(getInterColumnWidth()) << " "
<< setw(getHoursParkedColumnWidth()) << "Parked"
<< setw(getInterColumnWidth()) << " "
<< setw(getParkingChargeColumnWidth()) << "Fee"
<< setw(getInterColumnWidth()) << " "
<< setw(getDefaultChargeColumnWidth()) << "Charge";
cout << "\n";
} // function displayColumnHeadings
// A-1-1-28 TODO
// A-1-1-29 TODO
// A-1-1-30 TODO
// A-1-3-064 TODO
// A-1-3-065 TODO
// A-1-3-066 TODO
// A-1-3-067 TODO
// A-1-3-068 TODO
// A-1-3-069 TODO
// A-1-3-070 TODO
// A-1-3-071 TODO
// A-1-3-072 TODO
// A-1-3-073 TODO
// A-1-1-31 TODO
void displayThisCustomer
(int customerNumber,
int hoursParked,
double parkingCharge,
bool usedMaximumParkingCharge,
bool usedMinimumParkingCharge) {
string defaultChargeLiteral;
if (usedMaximumParkingCharge == true)
defaultChargeLiteral = "Maximum";
else
if (usedMinimumParkingCharge == true)
defaultChargeLiteral = "Minimum";
else
defaultChargeLiteral = "-- ";
// A-1-3-082 TODO
// A-1-3-083 TODO
// A-1-3-084 TODO
// A-1-3-085 TODO
// A-1-3-086 TODO
// A-1-3-087 TODO
// A-1-3-088 TODO
// A-1-3-089 TODO
// A-1-3-090 TODO
// A-1-3-091 TODO
// A-1-3-092 TODO
} // function displayThisCustomer
int getCustomerCount() {
return c_customerCount;
} // function getCustomerCount
int getCustomerColumnWidth() {
return c_customerColumnWidth;
} // function getCustomerColumnWidth
void getDailyParkingActivity(int hoursParkedByCustomer[]) {
const int c_maximumHoursParked = 24;
srand(12321);
for (int customerNumber=1;customerNumber<=getCustomerCount();
customerNumber++) {
hoursParkedByCustomer[customerNumber-1] = 1 + rand() % c_maximumHoursParked;
} // for
} // function getDailyParkingActivity
int getDefaultChargeColumnWidth() {
return c_defaultChargeColumnWidth;
} // function getChargeColumnWidth
int getHoursParkedColumnWidth() {
return c_hoursParkedColumnWidth;
} // function getHoursParkedColumnWidth
int getInterColumnWidth() {
return c_interColumnWidth;
} // function getInterColumnWidth
int getParkingChargeColumnWidth() {
return c_parkingChargeColumnWidth;
} // function getParkingChargeColumnWidth
}; // class Garage
int main() {
Garage myGarage;
string enterKey;
cout << "\nTask 09-02, Ch06, Programmed by ME";
myGarage.prepareDailyReceiptsReport();
cout << ("\n\nEnd of Program: Press <Enter> to exit program.");
getline(cin, enterKey);
} // function main
-
-
So, this would be the part in question:
Code:
// A-1-1-21 TODO
// A-1-1-22 TODO
// A-1-1-23 TODO
// A-1-1-24 TODO
double c_minimumParkingCharge = 2.0;
double c_maximumParkingCharge = 10.0;
double c_maximumParkingHoursForMinimumParkingCharge = 3.0;
double c_chargePerHourAfterMinimum = .5;
double parkingCharge = c_minimumParkingCharge;
if hoursParked > c_minimumParkingCharge {
(c_minimumParkingCharge + c_chargePerHourAfterMinimum
* ceil(hoursParked - c_maximumParkingHoursForMinimumParkingCharge)
= parkingCharge;
}
if (parkingCharge > c_maximumParkingCharge) {
usedMaximumParkingCharge = true;
parkingCharge = c_maximumParkingCharge;
} else {
usedMaximumParkingCharge = false;
}
if parkingCharge = c_minimumParkingCharge
usedMinimumParkingCharge = true;
else
usedMinimumParkingCharge = false;
return parkingCharge;
}
See how much simpler the program seems now, compared to that amorphous blob of text :D Remember that code is for humans to read, not computers, so use whatever whitespace you need to make the structure of the program clear to you.
(Hopefully you'll notice the syntax errors littered about now, too; compilers do a good enough job yelling about those sorts of things so I'll avoid them for the time being.)
Now, as for your problem of having to fill four lines:
Code:
void displayThisCustomer
(int customerNumber,
int hoursParked,
double parkingCharge,
bool usedMaximumParkingCharge,
bool usedMinimumParkingCharge) {
based on this prototype provided later on in the file, it looks like your instructor likes to have one argument per line. Presumably, that's where the extra lines would come from. And if the number of lines in your answer actually matters (which seems awfully silly to me) I'm sure you could take some... liberties... with the whitespace :p
-
So, to determine what would go in those lines, I'd need to look in the body of that function and int everything? This is my first programming class and it's getting harder and harder. I should not of took this class as an online class but with my work schedule it's pretty much all I can do at this point. So if I do something like this for Lines A-1-1-21 through a-1-1-24. I get this......
Code:
void calculateCustomerParkingCharge() {
int hoursParked, c_minimumParkingCharge,
int usedMaximumParkingCharge,
usedMinimumParkingCharge;
but then I get errors for the *(ceil(hoursParked line as well as a return value type does not match the function type.........