Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 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. #include<iomanip>
  16. using namespace std;
  17. void login();
  18. string EnterPassword();
  19. struct newprod
  20. {
  21. string product;
  22. int prodNo;
  23. int prodVal;
  24. };
  25. struct newproduct
  26. {
  27. string name;
  28. double price;
  29. int stock;
  30. int sold;
  31. };
  32.  
  33. int main()
  34. {
  35. login();
  36. newprod product[200];
  37. newproduct prod[200][200];
  38. int no1, no2;
  39. int i;
  40. int j;
  41. char ch;
  42. cout<< "***** INVENTORY SYSTEM C++.2 *****"<<endl;
  43. cout<< "ENTER NUMBER OF PRODUCTS FOR INVENTORY: ";
  44. cin>>no1;
  45. cout<<endl<<"ENTER "<<no1<<" PRODUCTS"<<endl;
  46.  
  47.  
  48. for(i=0; i<no1; i++)
  49. {
  50. cout<< "Product"<<i+1<<":";
  51. cin>> product[i].product;
  52. product[i].prodNo=i+1;
  53. cout<<endl;
  54. cout<< "How many "<<product[i].product<<"?";
  55. cin>>no2;
  56. product[i].prodVal=no2;
  57.  
  58.  
  59. for(j=0; j<no2; j++)
  60. {
  61. cout<< product[i].product<<"["<<j+1<<"]:";
  62. cin>>prod[i][j].name;
  63. cout<<endl;
  64. cout<<"price: Php";
  65. cin>>prod[i][j].price;
  66. cout<<"stock: ";
  67. cin>>prod[i][j].stock;
  68. cout<<"sold: ";
  69. cin>>prod[i][j].sold;
  70. cout<<endl;
  71. }
  72.  
  73. }
  74. system("cls");
  75. cout<< "***** INVENTORY SYSTEM C++.2 *****"<<endl;
  76. cout<<"PROD.NO PRODUCT NAME PRICE STOCK SOLD LEFT";
  77. for(i=0; i<no1; i++)
  78. {
  79.  
  80. cout<<endl<<" ["<< product[i].prodNo <<"] "<< product[i].product<< " ";
  81.  
  82. for(j=0; j<product[i].prodVal ; j++)
  83. {
  84. if(j>0)
  85. {
  86. cout<<" ";
  87. }
  88. 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;
  89.  
  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