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 (then adjust array shown in example)
#include <iostream>
using namespace std;
int main () {
// declare a variable for lists
int len1 = 0, len2 = 0;
int in_list[len1], out_list[len2];
cout << "Enter the number of vehicles in in_list: \n";
cin >> len1;
cout << "Enter ids of vehicles that are present in a factory: \n";
for (int i = 0; i < len1; i++) {
int vehicle;
cin >> vehicle;
in_list[i] = vehicle;
}
cout << "\n\n";
cout << "Enter the number of vehicles in out_list: \n";
cin >> len2;
cout << "Enter ids of vehicles that are are about to come in factory: \n";
for (int i = 0; i < len2; i++) {
int vehicle1;
cin >> vehicle1;
out_list[i] = vehicle1;
}
cout << "At the beginning: \n";
cout << "\nThe vehicles' ids in in_list: \n";
for (int i = 0; i < len1; i++) {
cout << in_list[i] << endl;
}
cout << "The vehicles' ids in out_list: \n";
for (int i = 0; i < len2; i++) {
cout << out_list[i] << endl;
}
int delete_entry;
cout << "\nEnter id of vehicle which you want delete: ";
cin >> delete_entry;
for (int i = 0; i < len1; i++) {
if (delete_entry == in_list[i]) {
for(int j = i; j< len1; j++)
in_list[j] = in_list[j+1];
i--;
len1--;
}
}
cout << "\nThe vehicles' ids in in_list: \n";
for (int i = 0; i < len1; i++) {
cout << in_list[i] << endl;
}
cout << "The vehicles' ids in out_list: \n";
for (int i = 0; i < len2; i++) {
cout << out_list[i] << endl;
}
}
Comments
Leave a comment