Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. /*
  2. * Programmer: MANCENIDO, Miguel Jose M.
  3. * Date Created: 1/21/2020
  4. * Terminal No: 39
  5. * Program: BMCS
  6. * Course / Section: CS127L/BM2
  7. * Purpose: This is an inventory program that displays the products inputted by the user.
  8. */
  9. #include <iostream>
  10. #include <string>
  11. #include <stdlib.h>
  12. #include <fstream>
  13. #include<conio.h>
  14. #include<windows.h>
  15. using namespace std;
  16. void login();
  17. string EnterPassword();
  18. struct newprod
  19. {
  20. string product;
  21. int prodNo;
  22. int prodVal;
  23. };
  24. struct newproduct
  25. {
  26. string name;
  27. double price;
  28. int stock;
  29. int sold;
  30. };
  31.  
  32. int main()
  33. {
  34. login();
  35. newprod product[200];
  36. newproduct prod[200][200];
  37. int no1, no2;
  38. int i;
  39. int j;
  40. char ch;
  41. cout<< "***** INVENTORY SYSTEM C++.2 *****"<<endl;
  42. cout<< "ENTER NUMBER OF PRODUCTS FOR INVENTORY: ";
  43. cin>>no1;
  44. cout<<endl<<"ENTER "<<no1<<" PRODUCTS"<<endl;
  45.  
  46.  
  47. for(i=0; i<no1; i++)
  48. {
  49. cout<< "Product"<<i+1<<":";
  50. cin>> product[i].product;
  51. product[i].prodNo=i+1;
  52. cout<<endl;
  53. cout<< "How many "<<product[i].product<<"?";
  54. cin>>no2;
  55. product[i].prodVal=no2;
  56.  
  57.  
  58. for(j=0; j<no2; j++)
  59. {
  60. cout<< product[i].product<<"["<<j+1<<"]:";
  61. cin>>prod[i][j].name;
  62. cout<<endl;
  63. cout<<"price: Php";
  64. cin>>prod[i][j].price;
  65. cout<<"stock: ";
  66. cin>>prod[i][j].stock;
  67. cout<<"sold: ";
  68. cin>>prod[i][j].sold;
  69. cout<<endl;
  70. }
  71.  
  72. }
  73. system("cls");
  74. cout<< "***** INVENTORY SYSTEM C++.2 *****"<<endl;
  75. for(i=0; i<no1; i++)
  76. {
  77. cout<<endl<<"PRODUCT:"<< product[i].product <<"PROD NO:"<< product[i].prodNo<<endl;
  78.  
  79. for(j=0; j<product[i].prodVal ; j++)
  80. {
  81. cout<< product[i].product<<"["<<j+1<<"]:";
  82. cout<< prod[i][j].name;
  83. cout<<endl;
  84. cout<<"price: Php";
  85. cout<<prod[i][j].price<<endl;
  86. cout<<"stock: ";
  87. cout<<prod[i][j].stock<<endl;
  88. cout<<"sold: ";
  89. cout<<prod[i][j].sold<<endl;
  90. }
  91.  
  92. }
  93. }
  94.  
  95. void login ()
  96. {
  97. string userName;
  98. string userPassword;
  99. int loginAttempt = 0;
  100.  
  101. while (loginAttempt < 3)
  102. {
  103. cout << " PRODUCT INVENTORY SYSTEM CS127L "<<endl;
  104. cout << "Username: ";
  105. cin >> userName;
  106. system("cls");
  107. cout << " PRODUCT INVENTORY SYSTEM CS127L "<<endl;
  108. cout << "Password: ";
  109. userPassword = EnterPassword();
  110. system("cls");
  111. try{
  112. if (userName == "miguel" && userPassword == "jose")
  113. {
  114. cout << "Welcome Miguel"<<endl;
  115. break;
  116. }
  117. else if (userName == "isabel" && userPassword == "obordo")
  118. {
  119. cout << "Welcome Isabel!"<<endl;
  120. break;
  121. }
  122. else
  123. {
  124. throw 99;
  125.  
  126. }
  127. }catch(int error){
  128. cout<<"Invalid username and/or password"<<endl<<"ERROR NUMBER:"<< error<<endl;
  129. loginAttempt++;
  130. system("pause");
  131. system("cls");
  132. }
  133. }
  134. if (loginAttempt == 3)
  135. {
  136. cout << "Too many login attempts! The program will now terminate.";
  137. exit(0);
  138. }
  139.  
  140. }
  141. string EnterPassword()
  142. {
  143. //add code here
  144. string password="";
  145. char ch;//h
  146.  
  147. while(ch != '\r') //Loop until 'Enter' is pressed
  148. {
  149. ch = getch();
  150.  
  151. if(ch=='\b')
  152. {
  153. if(password.size()!=0)
  154. {
  155. cout<<"\b"<<" "<<"\b";
  156. password.erase(password.size()-1,-1);
  157. }
  158. }
  159.  
  160. else if(ch=='\r')
  161. {
  162. break;
  163. }
  164.  
  165. else
  166. {
  167. password += ch;
  168. cout << "*";
  169. }
  170. }
  171.  
  172. return password;
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement