Vous êtes sur la page 1sur 17

Contents

Introduction................................................................................................................ 2
Algorithm Flow Chart....................................................................................................... 3
User Guide..................................................................................................................... 4
Explanation of Code......................................................................................................... 8

Introduction
This project involves the development of a program in C++ to track the use of equipment in
electronics lab. The complete program developed was expected to perform the following
functions,

Secure the stock information from unauthorized personnel


Display the stock information upon request
Issue equipment and update stock information
A low stock warning, if number of any component becomes 5 or less
Add equipment and update stock information
Exit and save the updated information to a file

Following assumptions were made during the development of the code for this project,

Total number of technicians working in the lab is three


There are only four types of equipment namely,
o Resistors
o Diodes
o Capacitors
o Transistors
Each type of equipment has five types namely,
o Type A
o Type B
o Type C
o Type D
o Type E

At the completion of the project, the program written in C++ was tested multiple times. It was
found, that the program was completely working and was performing all the expected functions
correctly.

Algorithm Flow Chart

User Guide
On start up the program asks you to enter the username and password as shown below,

You can use any of the username and password combination listed below,
Username
wna1
wna2
wna3

Password
123
456
789

If the login credentials are not correct then the program asks to enter them again,

If the login is successful, then the file database.txt present in the same directory as the code is
read and the following screen appears,

The program asks to enter your choice. There are four options. Let us say that we want to display
the stock information then we enter 1.
Upon entering 1, the following screen appears,

It can be seen that the current stock information is displayed and after that the program again
asks for choice. Let us issue a component by entering 2. This time the program asks to enter
the name of the equipment and also mention its type. After it, the program asks for the quantity
that is to be issued. If the amount of the stock after issuing is five or less then the program issues
a warning too.

Now we again display the stock information by entering 1.

It can be seen in the above figure that the number of Type C resistors is now 65, which was 100
before issuing the resistors.
Similarly, if we input 3, then the program asks to add the stock as shown below,

Again displaying the results show,

From the above figure it can be seen that 25 capacitors of type C have been added to the stock
and the total quantity has reached to 125, which was 100 before the addition operation.
If we enter 4, then all the updated information is transferred to the file and database.txt and
saved there. After saving the program quits

Explanation of Code
Two structures were created for storing the information of Lab technicians and Lab stock. The
structures also included functions to access the values of its members.

struct labMember{
string userName;
string Password;
labMember()
{
userName = "";
Password = "";
}
labMember(string username, string password)
{
userName = username;
Password = password;
}
string getUser()
{
return userName;
}
string getPass()
{
return Password;
}
void setuser(string name)
{
userName = name;
}
void setPass(string pass)
{
Password = pass;
}
};
struct LabStock
{
string equipmentName;
string type[5];
int amount[5];

LabStock()
{
equipmentName = "";
}

LabStock(string name)
{
equipmentName = name;
type[0] = "A";
type[1] = "B";
type[2] = "C";
type[3] = "D";
type[4] = "E";
}

string getEquipmentName()
{
return equipmentName;
}
void setEquipmentName(string equipmentName)
{
this->equipmentName = equipmentName;
}
int getAmount(int index)
{
return amount[index];
}
void setAmount(int index, int amount)
{
this->amount[index] = amount;
}
string getType(int index)
{
return type[index];

}
};

At the start of the main function, three instances of the labMember structure and four instances
of LabStock structure were created.
labMember technicians[3];
technicians[0] = labMember("wna1", "123");
technicians[1] = labMember("wna2", "456");
technicians[2] = labMember("wna3", "789");
LabStock stock[4];
stock[0] = LabStock("Resistors");
stock[1] = LabStock("Capacitors");
stock[2] = LabStock("Diodes");
stock[3] = LabStock("Transistors");

The login details for the technicians were checked thereafter,


bool loginCheck = false;
do
{
string inputUser, pass = " ";
cout << "\n\tEnter your username : ";
cin >> inputUser;
cout << "\tEnter you password : ";
cin >> pass;

for (int i = 0; i<3; i++)


{
if (technicians[i].getUser() == inputUser)
{
if (technicians[i].getPass() == pass)
{
loginCheck = true;
cout << "\n\tWelcome! " << technicians[i].getUser();
cout << " to the Lab storage management\n";
}

10

}
}
if (!loginCheck)
{
cout << "\nYou have entered a wrong username or password.;
cout<<Please enter your details again\n";
}
} while (!loginCheck);

The information of current stock was read from the file database.txt if the login was successful
and all the variables were initialized to proper values.
ifstream infile("database.txt");
string data;
int number, n;
char data1[20];
while (!infile.eof())
{
getline(infile, data);
if (data == "Equipment Name = Resistors")
{
stock[0].setEquipmentName("Resistors");
for (int i = 0; i < 5; i++)
{
getline(infile, data);
n = data.find("=") + 1;
data = data.substr(n, data.length());
strcpy_s(data1, data.c_str());
number = atoi(data1);
stock[0].setAmount(i, number);
}
}
else if (data == "Equipment Name = Capacitors")
{
stock[1].setEquipmentName("Capacitors");
for (int i = 0; i < 5; i++)
{

11

getline(infile, data);
n = data.find("=") + 1;
data = data.substr(n, data.length());
strcpy_s(data1, data.c_str());
number = atoi(data1);
stock[1].setAmount(i, number);
}
}
else if (data == "Equipment Name = Diodes")
{
stock[2].setEquipmentName("Diodes");
for (int i = 0; i < 5; i++)
{
getline(infile, data);
n = data.find("=") + 1;
data = data.substr(n, data.length());
strcpy_s(data1, data.c_str());
number = atoi(data1);
stock[2].setAmount(i, number);
}
}
else if (data == "Equipment Name = Transistors")
{
stock[3].setEquipmentName("Transistors");
for (int i = 0; i < 5; i++)
{
getline(infile, data);
n = data.find("=") + 1;
data = data.substr(n, data.length());
strcpy_s(data1, data.c_str());
number = atoi(data1);
stock[3].setAmount(i, number);
}
}
}
infile.close();

After the initialization phase, the required operations listed below were performed,

12

Display Current Stock


Issue Item
Add Item to Stock
Exit

int choice = 0;
do {
cout << "\n\n\tEnter your choice\n";
cout << "\tEnter 1 for displaying stock \n" << "\tEnter 2 for issuing item \n";
cout<<"\tEnter 3 for adding stock\n"<<"\tEnter 4 for exiting the lab management\n";
cin >> choice;
if (choice == 1)
{
for (int i = 0; i<4; i++)
{
cout << "\nEquipment # " << i + 1 << " = " << stock[i].getEquipmentName() << endl;
for (int j = 0; j<5; j++)
{
cout << "Type # " << j + 1 << " = " << stock[i].getType(j);
cout << "\tAmount = " << stock[i].getAmount(j) << endl;
}
}
}
else if (choice == 2)
{
int eqpNumber = 0;
int typeNumber = 0;
do {
cout << "Enter the equipment number ";
cin >> eqpNumber;
eqpNumber--;
if (eqpNumber < 0 || eqpNumber > 3)
cout << "You have entered the wrong equipment Number. Try again\n";
else
break;
} while (true);
do
{
cout << "Enter the type number of the equipment ";
cin >> typeNumber;
typeNumber--;

13

if (typeNumber < 0 || typeNumber > 4)


{
cout << "You have entered the wrong type number. Try again\n";
}
else
break;
} while (true);
int issue;
cout

<<

"\n\nHow

much

"

<<

stock[eqpNumber].equipmentName

<<

"

of

type

";

cout<<stock[eqpNumber].getType(typeNumber) << " you wants to issue?\n";


cin >> issue;
int presentAmount = stock[eqpNumber].getAmount(typeNumber);
if (presentAmount - issue <= 5)
{
cout << "If you issue this product the amount would be less than 5\n Choose Another item\n";
}
else
{
int newAmount;
newAmount = presentAmount - issue;
stock[eqpNumber].setAmount(typeNumber, newAmount);
}
}
else if (choice == 3)
{
int eqpNumber = 0;
int typeNumber = 0;
do {
cout << "Enter the equipment number ";
cin >> eqpNumber;
eqpNumber--;
if (eqpNumber < 0 || eqpNumber > 3)
cout << "You have entered the wrong equipment Number. Try again\n";
else
break;
} while (true);

14

do
{
cout << "Enter the type number of the equipment ";
cin >> typeNumber;
typeNumber--; //-1 because index starts from 0
if (typeNumber < 0 || typeNumber > 4)
{
cout << "You have entered the wrong type number. Try again\n";
}
else
break;
} while (true);
int add;
cout << "\n\nHow much " << stock[eqpNumber].equipmentName << " of type " ;
cout<< stock[eqpNumber].getType(typeNumber) << " you wants to add?\n";
cin >> add;
int presentAmount = stock[eqpNumber].getAmount(typeNumber);
int newAmount;
newAmount = presentAmount + add;
stock[eqpNumber].setAmount(typeNumber, newAmount);
}
} while (choice != 4);

If the user asks for exit, then the file database.txt was updated and all the values were stored to
it.
ofstream outfile;
outfile.open("database.txt");
for (int i = 0; i < 4; i++)
{
outfile <<"Equipment Name = " +stock[i].getEquipmentName() << endl;
for (int j = 0; j < 5; j++)
{
outfile << "Type " + stock[i].getType(j) + "=" <<stock[i].getAmount(j)<< endl;
}
}

15

outfile.close();

16

Vous aimerez peut-être aussi