Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <cstdlib>
  4. #include <cmath>
  5. /* Program do obliczania pól figur geometrycznych oraz sredniej arytmetycznej liczb*/
  6.  
  7. using namespace std;
  8. //global vars
  9. double tmp1,tmp2,sum;
  10. int const tabSize = 10;
  11. double tab [tabSize];
  12.  
  13. void printMenu(){
  14. cout<<"Menu:\n1.Policz pole trojkata\n2.Policz pole kwadratu\n3.Policz pole prostokata\n4.Policz pole rownoległoboku\n5.Policz pole kola\n6.Policz srednia arytmetyczna z 10 liczb\n7.EXIT."<<endl;
  15. }
  16. double triangle(double a, double h ){
  17. return a * h * 1/2;
  18. }
  19. double square(double a){
  20. return a * a;
  21. }
  22. double rectangleAndParallelogram(double a, double b){
  23. return a * b;
  24. }
  25. double circle(double r){
  26. return r * r * M_PI ;
  27. }
  28. bool checkArgs(double a, double b){
  29. if (a <= 0 || b <= 0) {
  30. cout<<"PARAMETRY NIE MOGA BYC UJEMNE!";
  31. return true;
  32. }
  33. return false;
  34. }
  35. bool checkArg(double a){
  36. if (a <= 0) {
  37. cout<<"PARAMETR NIE MOZE BYC UJEMNY!";
  38. return true;
  39. }
  40. return false;
  41. }
  42.  
  43. int main() {
  44. int choice;
  45. while(true){
  46. printMenu();
  47. cin>>choice;
  48. switch(choice){
  49. case 1:
  50. cout<<"Podaj dlugosc podstawy: ";
  51. cin>>tmp1;
  52. cout<<"Podaj wysokosc: ";
  53. cin>>tmp2;
  54. if(checkArgs(tmp1,tmp2)) break;
  55. cout<< "Pole trojkata: "<< triangle(tmp1,tmp2);;
  56. break;
  57.  
  58. case 2:
  59. cout<<"Podaj dlugosc boku: ";
  60. cin>>tmp1;
  61. if(checkArg(tmp1)) break;
  62. cout<< "Pole kwadratu: "<<square(tmp1);
  63. break;
  64.  
  65. case 3:
  66. cout<<"Podaj dlugosc pierwszego boku: ";
  67. cin>>tmp1;
  68. cout<<"Podaj dlugosc drugiego boku: ";
  69. cin>>tmp2;
  70. if(checkArgs(tmp1,tmp2)) break;
  71. cout<< "Pole prostokata: "<< rectangleAndParallelogram(tmp1,tmp2);;
  72. break;
  73. case 4:
  74. cout<<"Podaj dlugosc podstawy: ";
  75. cin>>tmp1;
  76. cout<<"Podaj wysokosc: ";
  77. cin>>tmp2;
  78. if(checkArgs(tmp1,tmp2)) break;
  79. cout<< "Pole równoległoboku: "<< rectangleAndParallelogram(tmp1,tmp2);
  80. break;
  81.  
  82. case 5:
  83. cout<<"Podaj promien: ";
  84. cin>>tmp1;
  85. if(checkArg(tmp1)) break;
  86. cout<< "Pole kola: "<< circle(tmp1);;
  87. break;
  88. case 6:
  89. system("cls");
  90. int avgChoice;
  91. cout<< "1.Sam wypisz liczby\n2.Wylosuj liczby\n";
  92. cin>>avgChoice;
  93. switch(avgChoice){
  94. case 1:
  95. for(int i = 0 ; i<tabSize ; i++){
  96. cout<<i+1 <<". liczba: ";
  97. cin>>tab[i];
  98. }
  99. break;
  100. case 2:
  101. for(int i = 0 ; i<tabSize ; i++){
  102. tab[i] = rand() % 100 + 1;
  103. }
  104. break;
  105. default:
  106. cout <<"Nie ma takiej opcji";
  107. break;
  108. }
  109. cout<<"srednia dla liczb: ";
  110. for(int i = 0 ; i<tabSize ; i++){
  111. cout<<tab[i]<<" ";
  112. sum+=tab[i];
  113. }
  114. cout<<"\n to: " << sum/tabSize;
  115. break;
  116.  
  117. case 7: return 0; break;
  118.  
  119. default:
  120. cout << "Nie ma takiej opcji";
  121. break;
  122. }
  123. getch();
  124. system("cls");
  125. }
  126. return 0;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement