Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5.  
  6. char prod[10][100];
  7. int qty[10][2];
  8. int price[10][2];
  9. int sortQty[10];
  10. int index = 1, maxIndex, total, i, j;
  11. int maxIncome, roundMode = -1;
  12. int pid, pq;
  13.  
  14. int main()
  15. {
  16. while(true) {
  17. cout << "Introducere produs #" << index << ":";
  18. cin.get(prod[index], 100);
  19. cin.get();
  20.  
  21. if(strlen(prod[index]) == 0) {
  22. break;
  23. }
  24.  
  25. qty[index][0] = index;
  26. cout << "Introducere cantitate pentru " << prod[index] << ":";
  27. cin >> qty[index][1];
  28.  
  29. price[index][0] = index;
  30. cout << "Introducere pret pentru " << prod[index] << ":";
  31. cin >> price[index][1];
  32.  
  33. index++;
  34. maxIndex = index;
  35. cin.get();
  36. }
  37.  
  38. cout << endl << "Produse Disponibile: " << endl;
  39.  
  40. for(i = 1; i < maxIndex; i++) {
  41. cout << i << ". " << prod[i] << " (x" << qty[i][1] << "): " << price[i][1] << " Lei (Valoare Totala: " << qty[i][1] * price[i][1] << ")" << endl;
  42. }
  43.  
  44. // Sort by Lowest Quantities
  45. for(i = 1; i < maxIndex; i++) {
  46. for(j = 1; j < i; j++) {
  47. if(qty[i][1] < qty[j][1]) {
  48. pid = qty[i][0];
  49. pq = qty[i][1];
  50. qty[i][0] = qty[j][0];
  51. qty[i][1] = qty[j][1];
  52. qty[j][0] = pid;
  53. qty[j][1] = pq;
  54. }
  55. }
  56. }
  57.  
  58. /* Show sorted quantities
  59. for(i = 1; i < maxIndex; i++) {
  60. cout << qty[i][0] << " " << qty[i][1] << endl;
  61. } */
  62.  
  63. cout << endl << "Profit maxim dupa vanzarea a 50% din stocul ultimelor 3 produse dupa cantitate: " << endl;
  64.  
  65. for(i = 1; i <= 3; i++) {
  66. if(qty[i][1] % 2 != 0) {
  67. qty[i][1] = qty[i][1] + roundMode;
  68. }
  69.  
  70. cout << prod[qty[i][0]] << " (x" << qty[i][1] << "): " << price[qty[i][0]][1] << " Lei (Valoare Totala: " << price[qty[i][0]][1] * qty[i][1] << ")" << endl;
  71. total += price[qty[i][0]][1] * qty[i][1];
  72. }
  73.  
  74. cout << "=> Total maxim dupa criteriul specificat: " << total << " Lei";
  75.  
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement