In: Computer Science
You are part of the IT Department at the newly established 200-bed Hospital Puteri Bestari in Ipoh, Perak. The hospital decided to have an in-house inventory system for all of its assets. Write a short program that accepts the inventory tagging number, and store it in a global array named ASSET_NUMBER. The array must be able to store up to 100 assets, and the tagging number is a 7-digit integer. The program should not overwrite existing data in the array, and must first find an empty element before storing the integer at that location.
USE ONLY C++!!
Global variable has global scope. In our given program we will be declaring a global array to store the tagging number
We will also have a counter variable which will help us track the number of elements currently in the array and the next location where the new input should be added.
Solution:
#include <iostream>
using namespace std;
// array of size 100
int ASSET_NUMBER[100];
int main()
{
// counter to keep track of index
int curr = 0;
int tag;
while(true) {
// get user input of the inventory tag
cin >> tag;
// store it in the inventory array
ASSET_NUMBER[curr] = tag;
// increment the counter
curr++;
}
return 0;
}
Screenshot of the code and sample output from an IDE: