still having problems with entering truck name and truck number

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Blondie1966
    New Member
    • Mar 2010
    • 12

    #1

    still having problems with entering truck name and truck number

    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..Th ank you

    /
    Code:
    *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();
    }
  • hype261
    New Member
    • Apr 2010
    • 207

    #2
    Consider picking ID or Truck Name as PK

    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.

    Comment

    • Blondie1966
      New Member
      • Mar 2010
      • 12

      #3
      Originally posted by hype261
      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.
      Ok, working on that, then can you help me with entering truck number to where it will remember them

      Comment

      • hype261
        New Member
        • Apr 2010
        • 207

        #4
        Reference Material

        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.



        James

        Comment

        Working...