Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Programmer: MANCENIDO, Miguel Jose M.
- * Date Created: 1/21/2020
- * Terminal No: 39
- * Program: BMCS
- * Course / Section: CS127L/BM2
- * Purpose: This is an inventory program that displays the products inputted by the user.
- */
- #include <iostream>
- #include <string>
- #include <stdlib.h>
- #include <fstream>
- #include<conio.h>
- #include<windows.h>
- #include<iomanip>
- using namespace std;
- void login();
- string EnterPassword();
- struct newprod
- {
- string product;
- int prodNo;
- int prodVal;
- };
- struct newproduct
- {
- string name;
- double price;
- int stock;
- int sold;
- };
- int main()
- {
- login();
- newprod product[200];
- newproduct prod[200][200];
- int no1, no2;
- int i;
- int j;
- char ch;
- cout<< "***** INVENTORY SYSTEM C++.2 *****"<<endl;
- cout<< "ENTER NUMBER OF PRODUCTS FOR INVENTORY: ";
- cin>>no1;
- cout<<endl<<"ENTER "<<no1<<" PRODUCTS"<<endl;
- for(i=0; i<no1; i++)
- {
- cout<< "Product"<<i+1<<":";
- cin>> product[i].product;
- product[i].prodNo=i+1;
- cout<<endl;
- cout<< "How many "<<product[i].product<<"?";
- cin>>no2;
- product[i].prodVal=no2;
- for(j=0; j<no2; j++)
- {
- cout<< product[i].product<<"["<<j+1<<"]:";
- cin>>prod[i][j].name;
- cout<<endl;
- cout<<"price: Php";
- cin>>prod[i][j].price;
- cout<<"stock: ";
- cin>>prod[i][j].stock;
- cout<<"sold: ";
- cin>>prod[i][j].sold;
- cout<<endl;
- }
- }
- system("cls");
- cout<< "***** INVENTORY SYSTEM C++.2 *****"<<endl;
- cout<<"PROD.NO PRODUCT NAME PRICE STOCK SOLD LEFT";
- for(i=0; i<no1; i++)
- {
- cout<<endl<<" ["<< product[i].prodNo <<"] "<< product[i].product<< " ";
- for(j=0; j<product[i].prodVal ; j++)
- {
- if(j>0)
- {
- cout<<" ";
- }
- cout <<setw(17)<< left<< prod[i][j].name << setw(8)<< left << prod[i][j].price << setw(8)<< left << prod[i][j].stock << setw(8)<< left<< prod[i][j].sold << setw(8)<< left <<prod[i][j].stock-prod[i][j].sold<<endl<<endl;
- }
- }
- }
- void login ()
- {
- string userName;
- string userPassword;
- int loginAttempt = 0;
- while (loginAttempt < 3)
- {
- cout << " PRODUCT INVENTORY SYSTEM CS127L "<<endl;
- cout << "Username: ";
- cin >> userName;
- system("cls");
- cout << " PRODUCT INVENTORY SYSTEM CS127L "<<endl;
- cout << "Password: ";
- userPassword = EnterPassword();
- system("cls");
- try{
- if (userName == "miguel" && userPassword == "jose")
- {
- cout << "Welcome Miguel"<<endl;
- break;
- }
- else if (userName == "isabel" && userPassword == "obordo")
- {
- cout << "Welcome Isabel!"<<endl;
- break;
- }
- else
- {
- throw 99;
- }
- }catch(int error){
- cout<<"Invalid username and/or password"<<endl<<"ERROR NUMBER:"<< error<<endl;
- loginAttempt++;
- system("pause");
- system("cls");
- }
- }
- if (loginAttempt == 3)
- {
- cout << "Too many login attempts! The program will now terminate.";
- exit(0);
- }
- }
- string EnterPassword()
- {
- //add code here
- string password="";
- char ch;//h
- while(ch != '\r') //Loop until 'Enter' is pressed
- {
- ch = getch();
- if(ch=='\b')
- {
- if(password.size()!=0)
- {
- cout<<"\b"<<" "<<"\b";
- password.erase(password.size()-1,-1);
- }
- }
- else if(ch=='\r')
- {
- break;
- }
- else
- {
- password += ch;
- cout << "*";
- }
- }
- return password;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement