CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2006
    Posts
    12

    vehicle maintenance program question

    the following is a console vehicle maintenance program. We cannot seem to get the edit function working correctly: when we wish to delete a vehicle it does not work. Try out the program and see if it works for you. I would appreciate any advice...thanx in advanx

    Code:
    //============================================================================
    // Vehicle Maintenance Tracking Application
    // -----------------------------------------
    //
    // Application Overview:
    // This application allows the user to input up to 20 different vehicles that will be tracked.
    // Each Vehicle will have the data entered.......
    //
    //
    
    //==============================================================================
    
    // Header Files
    #include "stdafx.h"
    #include <iostream>
    #include <string>
    #include <iomanip>
    
    // Namespace
    using namespace std;
    
    // Structs
    struct vehicleType
    {
    	int number;
    	int mileage;
    	string plate;
    	string vin;
    	string model;
    };
    
    // Prototypes
    void mainMenu(int& parUserChoice);
    void initVehicles(vehicleType parVehicles[]);
    void QuickCheck(vehicleType parVehicles[]);
    void addVehicle(vehicleType parVehicles[]);
    void EditVehicle(vehicleType parVehicles[]);
    void ListVehicles(vehicleType parVehicles[]);
    
    // Global Variables
    char x;
    int main (void)
    {
    	// Local Variable Declaration
    	int userChoice = 0; // User main menu selection
    	vehicleType vehicles[20]; // Create 20 element struct
    	
    	initVehicles(vehicles);
    	do
    	{
    		mainMenu(userChoice);
    		switch (userChoice)
    		{
    		case 0:
    			//Exit
    			break;
    		case 1:
    			addVehicle(vehicles);
    			break;
    		case 2:
    			EditVehicle(vehicles); //call EditVehicle function
    			break;
    		case 3:
    			QuickCheck(vehicles);//call QuickCheck function
    			break;
    		case 4:
    			ListVehicles(vehicles); //call Reports function
    			system("PAUSE");
    			break;
    		}
    	}while (userChoice != 0);
    }
    
    void mainMenu(int& parUserChoice)
    { // Begin mainMenu
    	do  // Displays menu until user chooses to quit the program
    	{	// Begin do loop
    		// Clear Screen
    		system("cls");
    
    		// List Main Menu
    		cout << " Main Menu" << endl;
    		cout << "===========" << endl;
    		cout << "1 - Enter New" << endl;
    		cout << "2 - Edit" << endl;
    		cout << "3 - Quick Check" << endl;
    		cout << "4 - Display Report" << endl;
    		cout << "0 - Exit" << endl;
    		cout << "Enter your selection(1-4, 0 to exit): ";
    		cin >> parUserChoice;
    	} while (parUserChoice > 4 || parUserChoice <0); // Continues until user enters a valid selection
    } // End mainMenu
    
    void addVehicle(vehicleType parVehicles[])
    {	// Begin addVehicle
    	bool found = false;
    
    	for (int counter = 0;counter<20;counter++) // Loop to count through vehicle records
    	{
    		if (parVehicles[counter].number == 0) // Checks whether data record exists
    		{
    			parVehicles[counter].number = counter + 1;
    			cout << "Enter Model: ";
    			cin >> parVehicles[counter].model;
    			cout << "Enter VIN: ";
    			cin >> parVehicles[counter].vin;
    			cout << "Enter Plate Number: ";
    			cin >> parVehicles[counter].plate;
    			cout << "Enter Mileage (Whole numbers only): ";
    			cin >> parVehicles[counter].mileage;
    			
    
    		    counter = 20;
    			found = true;
    		}
    	}
    
    	if (!found) // Used if all struct elements have data in them
    	{
    		cout << "Vehicle capacity is full" << endl;
    		system("pause");
    	}
    }
    
    
    void initVehicles(vehicleType parVehicles[])
    {
    	// Init all vehicle numbers to 0
    	for (int counter = 0;counter < 20;counter++)
    	{
    		parVehicles[counter].number=0;
    	}
    }
    
    void EditVehicle(vehicleType parVehicles[])
    {	// Begin EditVehicle()
    	int EditSelect = 0;	// User selection of which vehicle attribute to edit
    	int VehicleSelect = 0; // User selection of which vehicle to edit
    
    	if(parVehicles[0].number == 0) // Checks to see if there is at least one record in the system
    	{
    		cout << "There are no vehicles in the database to edit.";
    		system("PAUSE");
    	}
    	else // Executed if there is at least one vehicle in the system
    	{
    		cout << "Which vehicle would you like to edit?" << endl << endl;
    		ListVehicles(parVehicles);
    		cout << "Please make your selection (1-20) and hit Enter:";
    		cin >> VehicleSelect;
    		system("cls");
    		cout << "What would you like to edit on the vehicle?" << endl;
    		cout << "0 - Nothing/Exit Without Changes" << endl;
    		cout << "1 - Model" << endl;
    		cout << "2 - VIN" << endl;
    		cout << "3 - License Plate" << endl;
    		cout << "4 - Mileage" << endl;
    		cout << "5 - Remove Vehicle" << endl;
    		cin >> EditSelect;
    		
    		switch(EditSelect) // User selection of which vehicle item to edit
    		{
    		case 0:
    			break; // Quit Edit
    		case 1:
    			cout << "Old Model: " << parVehicles[VehicleSelect-1].model << "\tNew Model: ";
    			cin >> parVehicles[VehicleSelect-1].model;
    			break;
    		case 2:
    			cout << "Old VIN: " << parVehicles[VehicleSelect-1].vin << "\tNew VIN: ";
    			cin >> parVehicles[VehicleSelect-1].vin;
    			break;
    		case 3:
    			cout << "Old Plate: " << parVehicles[VehicleSelect-1].plate << "\tNew Plate: ";
    			cin >> parVehicles[VehicleSelect-1].plate;
    			break;
    		case 4:
    			cout << "Old Mileage: " << parVehicles[VehicleSelect-1].mileage << "\tNew Mileage: ";
    			cin >> parVehicles[VehicleSelect-1].mileage;
    			break;
    		case 5:
    			cout << "Deleting Vehicle: " << parVehicles[VehicleSelect-1].model << " ";
    			parVehicles[VehicleSelect-1].number = NULL;
    			//parVehicles[VehicleSelect-1].model = " ";
    			//parVehicles[VehicleSelect-1].vin = " ";
    			//parVehicles[VehicleSelect-1].plate = " ";
    			//parVehicles[VehicleSelect-1].mileage = 0;
    			system("cls");
    			ListVehicles(parVehicles);
    			system("PAUSE");
    			break;
    
    
    
    		} // End switch statement
    	}	// End else statement
    }	// End EditVehicle()
    
    void ListVehicles(vehicleType parVehicles[])
    {
    	if(parVehicles[0].number == 0)
    	{
    		cout << "You have not entered any vehicles in the database.";
    		system("PAUSE");
    	}
    	else
    	{
    		cout << "Number\tModel\tVIN\tPlate\tMileage" << endl << endl;
    		for(int a=0; a<20; a++)
    		{	// Begin for loop
    			if(parVehicles[a].number == 0)
    			{	// Begin if statement
    				cout << a+1 << "\tEmpty Record" << endl;	// Prints "Empty Record if a structure element does not contain info
    			}	// End if statement
    			else // Executes if there is at least one vehicle record in the system
    			{	// Begin else statement
    				cout << parVehicles[a].number;
    				cout << "\t" << parVehicles[a].model;
    				cout << "\t" << parVehicles[a].vin;
    				cout << "\t" << parVehicles[a].plate;
    				cout << "\t" << parVehicles[a].mileage << endl;
    			}	// End else statement
    		}	// End for loop
    	}	// End else statement
    }	// End ListVehicles function
    
    void QuickCheck(vehicleType parVehicles[])
    {
    	
    	int a = 0;
    	int status = 0;
    		cout << "Which vehicle would you like to check?" << endl << endl;
    		ListVehicles(parVehicles);
    		cout << "Please make your selection (1-20) and hit Enter:";
    		cin >> a;
    		a = a -1;
    		system("cls");
    
    if((parVehicles[a].mileage >= 45000) && (parVehicles[a].mileage < 50000))
    {
    cout << "Your vehicle will require a 50,000 mile checkup soon.\n";
    status = 1;
    }
    else if (parVehicles[a].mileage >=50000) 
    {
    cout << "The vehicle you have selected is due for a 50,000 mile checkup.\n";
    status = 1;
    }
      
    if((parVehicles[a].mileage >= 25000) && (parVehicles[a].mileage < 30000))
    {
    cout << "Your vehicle will require a new air filter soon.\n";
    status = 1;
    }
    else if (parVehicles[a].mileage >=30000) 
    {
    cout << "The vehicle you have selected is due for a new air filter.\n";
    status = 1;
    }
    
    if((parVehicles[a].mileage >= 70000) && (parVehicles[a].mileage < 75000))
    {
    cout << "Your vehicle will require a 50,000 mile checkup soon.\n";
    status = 1;
    }
    else if (parVehicles[a].mileage >=75000) 
    {
    cout << "The vehicle you have selected is due for transmission checkup.\n";
    status = 1;
    }
    
    if (status == 0)
       cout << "Your vehicle is currently up to date with maintenance.\n";
    
    system("PAUSE");
    }

  2. #2
    Join Date
    Dec 2003
    Location
    Syracuse, NY
    Posts
    400

    Re: vehicle maintenance program question

    What does it say when you try to delete the vehicle?

    If I enter 1 vehicle into it, and then delete that then it states that there are no vehicles in the database, which it should I assume. When I enter 2 or more, it deletes them and they don't appear in the databases anymore, which I assume it should do also.
    "Windows programming is like going to the dentist: You know it's good for you, but no one likes doing it."
    - Andre LaMothe

    DLL For Beginners(UPDATED)
    Please use CODE tags
    Rate me if I've helped.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured