Answer to Question #155836 in C++ for ARIBA

Question #155836

In a factory, different vehicles are being allocated different id. There are vehicles that have same ids as well because they have loaded same material and are of same model. At check post there are two list for maintaining the records of vehicle.

●      In_list which consist of ids of vehicle that are present in factory.

●      out_list contain the ids of vehicles that are about to come in factory.

Any vehicle from out_list will enter in factory when vehicle from In_list will go out of factory.Write a program that ask user vehicle id which will go out and delete that entry from In_list (if duplicate remove all entries and adjust array by back shifting as shown in example). Take next entry from the out_list and put in the In_list. Remember Out_list does not have any duplicate entries. Value from the out_list should be taken from index zero 


1
Expert's answer
2021-01-15T18:15:49-0500


#include <iostream>
using namespace std;
int main () {
    
    int l1 = 0, l2 = 0;
    int in_list[l1], out_list[l2];
    
    cout << "Please enter number of available vehcles in the lst: \n";
    cin >> l1;
    cout << "Please enter the available vehcile id: \n";
    for (int i = 0; i < l1; i++) {
        int vehicle;
        cin >> vehicle;
        in_list[i] = vehicle;
    }
    cout << "\n\n";
    
    cout << "Please enter the vehicle number which need to be out list: \n";
    cin >> l2;
    cout << "Please enter the vehicle id which is going to come in the factory: \n";
    for (int i = 0; i < l2; i++) {
        int vehicle1;
        cin >> vehicle1;
        out_list[i] = vehicle1;
    }
    
    cout << "At the initial state: \n";
    cout << "\n The vehicle id of the available vehicles in the list: \n";
    for (int i = 0; i < l1; i++) {
        cout << in_list[i] << endl;
    }
    cout << "Vehicle id of the available vehicles in the out_list: \n";
    for (int i = 0; i < l2; i++) {
        cout << out_list[i] << endl;
    }
    
    int delete_entry;
    cout << "\n Please enter the vehicle id which we need to delete: ";
    cin >> delete_entry;
   
       for (int i = 0; i < l1; i++) {
        if (delete_entry == in_list[i]) {
            for(int j = i; j< l1; j++)
                in_list[j] = in_list[j+1];
            i--;
            l1--;
        }
    }
    cout << "\n available vehicle id in the list: \n";
    for (int i = 0; i < l1; i++) {
        cout << in_list[i] << endl;
    }
    cout << "vehicle id in the out_list: \n";
    for (int i = 0; i < l2; i++) {
        cout << out_list[i] << endl;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS