Académique Documents
Professionnel Documents
Culture Documents
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,
Following assumptions were made during the development of the code for this project,
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.
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.
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,
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");
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
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
<<
"\n\nHow
much
"
<<
stock[eqpNumber].equipmentName
<<
"
of
type
";
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