Advertisement
pieniakoskar

Dysk twardy

Mar 19th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <stdio.h>
  4.  
  5. using namespace std;
  6.  
  7. class cPartycja
  8. {
  9. private:
  10. int Glowice;
  11. int RozmiarSektora; // B
  12. int RozmiarDyskuWSektorach;
  13. int Partycja[4];
  14. public:
  15. cPartycja(int glowice, int rozmiar_dysku_w_sektorach)
  16. {
  17. Glowice=glowice;
  18. RozmiarSektora=512;
  19. RozmiarDyskuWSektorach=rozmiar_dysku_w_sektorach;
  20. Partycja[0]=RozmiarDyskuWSektorach;
  21. Partycja[1]=0; Partycja[2]=0; Partycja[3]=0;
  22. }
  23. int getGlowice(){return Glowice;}
  24. int getPojemnoscSektory(){return RozmiarDyskuWSektorach;}
  25. int getPojemnoscKiB(){return RozmiarDyskuWSektorach*RozmiarSektora/1024;}
  26. int getSektor(){return RozmiarSektora;};
  27.  
  28. void setSektor(int rozmiarsektora)
  29. {
  30. RozmiarSektora=rozmiarsektora;
  31. }
  32. int getPartycjaSektory(int partycja){return Partycja[partycja-1];}
  33. int getPartycjaKiB(int partycja){return (Partycja[partycja-1]*RozmiarSektora/1024);}
  34. bool Zwieksz(int partycja, int ile)
  35. {
  36. if(Partycja[partycja-2] >= ile)
  37. {
  38. Partycja[(partycja-2)]-=ile;
  39. Partycja[(partycja-1)]+=ile;
  40. return true;
  41. }
  42. return false;
  43. }
  44. bool Zmniejsz(int partycja, int ile)
  45. {
  46. if(Partycja[partycja-1] >= ile)
  47. {
  48. Partycja[partycja-2]+=ile;
  49. Partycja[partycja-1]-=ile;
  50. return true;
  51. }
  52. return false;
  53. }
  54. };
  55.  
  56. int DrawMenu()
  57. {
  58. int Choosen;
  59. printf("1. Zwiekszenie partycji.\n");
  60. printf("2. Zmniejszenie partycji.\n");
  61. printf("0. Koniec programu.\n");
  62. printf("Wybieram: ");
  63. scanf("%d", &Choosen);
  64. return Choosen;
  65. }
  66. int WyborPartycji()
  67. {
  68. int Choosen;
  69. do
  70. {
  71. printf("\n Ktora partycja:");
  72. scanf("%d", &Choosen);
  73. } while( (Choosen<2) || (Choosen>4) );
  74. return Choosen;
  75. }
  76. int PobierzWielkosc()
  77. {
  78. int Wielkosc;
  79. do
  80. {
  81. printf("\n Ile sektorow:");
  82. scanf("%d", &Wielkosc);
  83. } while(Wielkosc<0);
  84. return Wielkosc;
  85. }
  86.  
  87. int main(int argc, char *argv[])
  88. {
  89. cPartycja HDD(2, 1024);
  90. int Choosen;
  91. int Partycja;
  92. int Ile;
  93. do
  94. {
  95. system("CLS");
  96. printf("Rozmiar dysku: %-8d sekt. (%-6d KiB)\n", HDD.getPojemnoscSektory(), HDD.getPojemnoscKiB());
  97. for(int i=0; i<4; )
  98. {
  99. ++i;
  100. printf("Partycja %d: %-8d sekt. (%-6d KiB)\n", i, HDD.getPartycjaSektory(i), HDD.getPartycjaKiB(i));
  101. }
  102. printf("\n\n");
  103. Choosen=DrawMenu();
  104. switch(Choosen)
  105. {
  106. case 1:
  107. {
  108. Partycja=WyborPartycji();
  109. Ile=PobierzWielkosc();
  110. HDD.Zwieksz(Partycja, Ile);
  111. }
  112. break;
  113. case 2:
  114. {
  115. Partycja=WyborPartycji();
  116. Ile=PobierzWielkosc();
  117. HDD.Zmniejsz(Partycja, Ile);
  118. }
  119. break;
  120. }
  121. } while(Choosen!=0);
  122. return EXIT_SUCCESS;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement