URUK UNIVERSITY
DEPARTMENT OF ELECTRONIC AND
COMMUNICATION ENGINEERING
{THE FIRST STAGE }
( C++ )
A program for a specific warehouse that allows the following to be done:-
- Adding a new material to the warehouse
- Changing the information of a specific material
- Increasing the number of a specific material or withdrawing a quantity of a material
from the warehouse.
- Arranging the warehouse materials according to their number
Prepared by: احمد ثجيل كزار
#include <iostream>
using namespace std;
const int MAX_MATERIALS = 100; // Maximum number of
materials
// Structure to store material details
struct Material {
string name;
int quantity;
string supplier;
string arrivalDate;
string description;
};
// Function to add a new material
void addMaterial(Material materials[], int& count) {
if (count >= MAX_MATERIALS) {
cout << "Cannot add more materials. The warehouse
is full.\n";
return;
}
cout << "Enter material name: ";
cin >> materials[count].name;
cout << "Enter quantity: ";
cin >> materials[count].quantity;
cout << "Enter supplier name: ";
cin >> materials[count].supplier;
cout << "Enter arrival date (YYYY-MM-DD): ";
cin >> materials[count].arrivalDate;
cout << "Enter description: ";
cin >> materials[count].description;
count++;
}
// Function to find a material by name
int findMaterial(Material materials[], int count, const
string& name) {
for (int i = 0; i < count; i++) {
if (materials[i].name == name) {
return i;
}
}
return -1;
}
// Function to update material details
void updateMaterial(Material materials[], int count) {
string name;
cout << "Enter material name to update: ";
cin >> name;
int index = findMaterial(materials, count, name);
if (index != -1) {
cout << "Enter new quantity: ";
cin >> materials[index].quantity;
cout << "Enter new supplier name: ";
cin >> materials[index].supplier;
cout << "Enter new arrival date (YYYY-MM-DD): ";
cin >> materials[index].arrivalDate;
cout << "Enter new description: ";
cin >> materials[index].description;
cout << "Material updated.\n";
}
else {
cout << "Material not found.\n";
}
}
// Function to increase or withdraw the quantity of a
material
void modifyMaterialQuantity(Material materials[], int
count) {
string name;
cout << "Enter material name to modify quantity: ";
cin >> name;
int index = findMaterial(materials, count, name);
if (index != -1) {
int change;
cout << "Enter quantity to add (positive) or
withdraw (negative): ";
cin >> change;
materials[index].quantity += change;
cout << "New quantity of " <<
materials[index].name << " is " <<
materials[index].quantity << ".\n";
}
else {
cout << "Material not found.\n";
}
}
// Function to sort materials by quantity
void sortMaterialsByQuantity(Material materials[], int
count) {
for (int i = 0; i < count - 1; i++) {
for (int j = i + 1; j < count; j++) {
if (materials[i].quantity > materials[j].quantity) {
Material temp = materials[i];
materials[i] = materials[j];
materials[j] = temp;
}
}
}
cout << "Materials sorted by quantity.\n";
}
// Function to display all materials
void displayMaterials(const Material materials[], int
count) {
for (int i = 0; i < count; i++) {
cout << i + 1 << ". " << materials[i].name << " -
Quantity: " << materials[i].quantity
<< ", Supplier: " << materials[i].supplier
<< ", Arrival Date: " << materials[i].arrivalDate
<< ", Description: " << materials[i].description <<
"\n";
}
}
int main() {
Material materials[MAX_MATERIALS]; // Array to store
materials
int count = 0; // Counter for materials
int choice;
do {
// Display menu options for the user
cout << "Warehouse Management System\n";
cout << "1. Add new material\n";
cout << "2. Update material information\n";
cout << "3. Modify material quantity\n";
cout << "4. Sort materials by quantity\n";
cout << "5. Display all materials\n";
cout << "0. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
// Handle user choice and call the appropriate
function
switch (choice) {
case 1:
addMaterial(materials, count);
break;
case 2:
updateMaterial(materials, count);
break;
case 3:
modifyMaterialQuantity(materials, count);
break;
case 4:
sortMaterialsByQuantity(materials, count);
break;
case 5:
displayMaterials(materials, count);
break;
case 0:
cout << "Exiting the program.\n";
break;
default:
cout << "Invalid choice. Please try again.\n";
}
} while (choice != 0);
return 0;
}