Ok Im still having problems, Im wanting the name that I enter as the truck name to always be the same, so if the user is asked to enter the truck name it must be one thing, and if anything other it shoud make the user retry, I dont want it to just put any name in, also the truck id is allowing the user again to put any number in and it takes it and the program runs, but i want it to remember the truck number, add to the truck inventory and I want it to be the correct number, not able to just put in any number again. Im still wanting the user to enter the days date,not sure where to put that in, should be at the beginning of program, but still not able to make that work as well. Also right now the program has a couple of errors line 40 declaration terminated incorrectly and line 104 expression syntax in function main [ ]. I am using Borland c++. Again any help would be greatly appreciated..Thank you
/ - *This program allows the user to add and remove trucks to their
-
inventory. It also allows them to add and remove donations
-
from the truck chosen. It also display a chart of
-
what trucks are in inventory, with the name of the
-
truck and the amount of donations in each one.th use will also be able to
-
enter the current days date and print out the days inventory.
-
*/
-
#include <iostream.h>
-
#include <iomanip.h>
-
#include <stdlib.h>
-
#include <conio.h>
-
#include <string.h>
-
#include <ctype.h>
-
-
#define max_trucks 200
-
#define max_capacity 250
-
-
class GOODWILL_TRUCK
-
{
-
private:
-
int ID_NUM;
-
int TRUCK_CAP;
-
int DON_ON_HAND;
-
char *TRUCK_NAME;
-
static int NUM_TRUCKS;
-
-
public:
-
GOODWILL_TRUCK (int id, char *Truck_Name, int don= 0);
-
~ GOODWILL_TRUCK ();
-
int ADD_DON (int amt);
-
int REMOVE_DON (int amt);
-
inline int GET_ID_NUM (){return ID_NUM;}
-
inline int GET_CAP () {return TRUCK_CAP;}
-
inline int GET_CONT() {return DON_ON_HAND;}
-
inline char* GET_NAME () {return TRUCK_NAME;}
-
static int TOTAL_TRUCKS ();
-
};
-
int GOODWILL_TRUCK::NUM_TRUCKS = 0;
-
-
GOODWILL_TRUCK (int id, char *Truck_Name, int don)
-
{
-
ID_NUM = id;
-
TRUCK_NAME = new char [strlen(T_Name)+1];
-
strcpy (TRUCK_NAME, T_Name);
-
DON_ON_HAND = don;
-
TRUCK_CAP = 250;
-
++NUM_TRUCKS;
-
}
-
int GOODWILL_TRUCK::ADD_DON (int amt)
-
{
-
if (DON_ON_HAND + amt > TRUCK_CAP)
-
return -1;
-
else
-
return DON_ON_HAND += amt;
-
}
-
int GOODWILL_TRUCK::REMOVE_DON (int amt)
-
{
-
if (DON_ON_HAND - amt < 0)
-
return -1;
-
else
-
return DON_ON_HAND -= amt;
-
}
-
-
GOODWILL_TRUCK::~GOODWILL_TRUCK ()
-
{
-
delete [] TRUCK_NAME;
-
}
-
int OIL_TANK::TOTAL_TRUCKS()
-
{
-
return NUM_TRUCKS;
-
}
-
GOODWILL_TRUCK* create_truck();
-
void display (GOODWILL_TRUCK&);
-
-
void main ()
-
{
-
int don_amt,
-
result,
-
count = 0,
-
choice;
-
char select = ' ';
-
char answer = ' ';
-
-
GOODWILL_TRUCK* truck_table[max_trucks];
-
do
-
{
-
cout << "\n WELCOME TO THE MERS/GOODWILL TRUCK INVENTORY";
-
cout << "\n\nPlease choose a number from the menu below.";
-
cout << "\nl. Add a truck to inventory.";
-
cout << "\n2. Add donations to a truck.";
-
cout << "\n3. Remove donations from a truck.";
-
cout << "\n4. Display the trucks in inventory.";
-
cout << "\n5. Quit the Program.";
-
cout << "\n\nPlease enter your selection now: ";
-
cin >> select;
-
clrscr ();
-
switch (select)
-
{
-
case '1':
-
cout << "\nDo you want to add a truck to inventory? (Y/N): ";
-
cin >> answer;
-
while (toupper(answer) == 'Y' && count < max_trucks)
-
{
-
*truck_table& [count] = create_truck();
-
++count;
-
cout << "\nDo you want to add a truck to inventory? (Y/N): ";
-
cin >> answer;
-
}
-
break ;
-
case '2':
-
cout << "\nTo which truck would you like to add donations?(1-15): ";
-
cin >> choice;
-
if (choice < 1 || choice > count)
-
{
-
cout << "\n\nINVALID ENTRY!!! ";
-
break;
-
}
-
else
-
{
-
cout << "n\nPlease enter the amount of donations to add: ";
-
cin >> don_amt;
-
result = truck_table[choice - 1]->ADD_DON (don_amt);
-
if (result < 0)
-
cout<< "\nERROR Truck capacity is not large enough!!!\n";
-
else
-
cout << "\nDonations Added!!! ";
-
break;
-
}
-
case '3':
-
cout << "\nFrom which truck would you like to remove donations? (1-max): ";
-
cin >> choice;
-
if (choice < 1 || choice > count)
-
{
-
cout << "\n\nINVALID ENTRY!!! ";
-
break;
-
}
-
else
-
cout << "\nPlease enter the amount of donations to remove: ";
-
cin >> don_amt;
-
result = truck_table[choice - 1]->REMOVE_DON (don_amt);
-
if (result < 0)
-
cout <<"\nERROR Truck does not have enough donations in it! !!\n";
-
else
-
cout << "\nDonations Removed!!! ";
-
-
break;
-
-
case '4':
-
for (int x = 0; x < count; ++x)
-
display(*truck_table[x]);
-
break;
-
}
-
}
-
while (select != '5');
-
cout << "\n\n\n\n THANK YOU";
-
cout << "\n\n GOODBYE";
-
for (int x = 0; x < count; ++x)
-
delete truck_table[x];
-
}
-
GOODWILL_TRUCK* create_truck()
-
{
-
int id_num,
-
donations = 0;
-
char name [80];
-
GOODWILL_TRUCK* truckptr;
-
cout << "\nPlease enter the id number: ";
-
cin >> id_num;
-
cin.ignore(81, '\n');
-
cout << "\nPlease enter the truck name: ";
-
cin.getline(name, 80);
-
cout << "\nPlease enter the amount of donations in truck: ";
-
cin >> donations;
-
cin.ignore(81, '\n');
-
clrscr();
-
truckptr = new GOODWILL_TRUCK (id_num, name, donations);
-
cout << "\n\n\Trucks in inventory: " << truckptr->TOTAL_TRUCKS();
-
return truckptr;
-
}
-
void display (GOODWILL_TRUCK& truck)
-
{
-
cout << "\nTruck ID " << truck.GET_ID_NUM();
-
cout << "\nName of Truck: " << truck.GET_NAME();
-
cout << "\nTruck Capacity: " << truck.GET_CAP();
-
cout << "\nDonations on Hand: " << truck.GET_CONT();
-
}
If you don't have a book on the STL I would recommend you picking one up. The C++ Standard Library by Nicolai Josuttis is a good reference to have.
Another good reference for the stl map is here. It will give you code examples so you can modify them for your needs. http://www.cplusplus.com/reference/stl/map/
James
3 1932
If I were you I would consider picking either Truck Name or ID as your unique identifier for your trucks. That way you could use the stl map container to store the unique keys and values.
@hype261
Ok, working on that, then can you help me with entering truck number to where it will remember them
If you don't have a book on the STL I would recommend you picking one up. The C++ Standard Library by Nicolai Josuttis is a good reference to have.
Another good reference for the stl map is here. It will give you code examples so you can modify them for your needs. http://www.cplusplus.com/reference/stl/map/
James
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Peter Blum |
last post by:
I have built an assembly (dll) from which I expect third parties to
subclass. As a result, when my assembly has a version change, it will cause
any third party assembly based on it to break unless...
|
by: Jens Körte |
last post by:
Hi NG!
I encountered some strange behaviour when using focus()
I use a form with several input-fields. A user can enter stuff. After
entering I want to check the value, i.e. that a number is...
|
by: cody |
last post by:
no this is no trollposting and please don't get it wrong but iam very
curious why people still use C instead of other languages especially C++.
i heard people say C++ is slower than C but i can't...
|
by: damian birchler |
last post by:
If I run the following I get a segmentation fault:
#define NAMELEN 15
#define NPERS 10
typedef struct pers {
char name;
int money;
} pers_t;
|
by: Mr. Mountain |
last post by:
In the following code I simulate work being done on different threads by
sleeping a couple methods for about 40 ms. However, some of these methods
that should finish in about 40 -80 ms take as long...
|
by: Jenny |
last post by:
Hi all
I've problems with forms authentication. I'm using a simple
function on the login.aspx page:
Private Sub LoginButton_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs)...
|
by: suzee_q00 |
last post by:
I will admit that lots of times the obvious eludes me and this is most likely one of those times but if anyone has any ideas on what I can do to make this code work, I would greatly appreciate it....
|
by: kashif456 |
last post by:
I can't figure out why I am getting error updating, deleting and
inserting new rows. I am amble to get my dataview populated and also
detailview populated: Here's my code:
<%@ Page...
|
by: dtvuser |
last post by:
Hi,
I'm new to PHP and seem to be having soom problems, I'm getting confused with all the different styles of script writing.
I've created a PHP script to submit details to my email but the...
|
by: rustyc |
last post by:
Well, here's my first post in this forum (other than saying 'HI' over in the hi forum ;-)
As I said over there:
... for a little side project at home, I'm writing a ham radio web site in...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |