Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. //============================================================================
  2. // Name : Kolokwium.cpp
  3. // Author :
  4. // Version :
  5. // Copyright : Your copyright notice
  6. // Description : Hello World in C++, Ansi-style
  7. //============================================================================
  8.  
  9. #include <iostream>
  10. #include <cstdlib>
  11. #include <string>
  12. using namespace std;
  13.  
  14.  
  15. float zad1(int tab[], int rozmiar)
  16. {
  17.  
  18. float sred=0;
  19. for (int i=0; i<=rozmiar-1; i++)
  20. {
  21. sred=sred+tab[i];
  22. }
  23.  
  24. sred=sred/rozmiar;
  25.  
  26.  
  27. float m1,m2;
  28. if (tab[0]<=sred)
  29. m1=sred-tab[0];
  30. else if (tab[0]>=sred)
  31. m1=tab[0]-sred;
  32.  
  33. m2=tab[0];
  34. for (int i=1; i<=rozmiar-1; i++)
  35. {
  36. if (tab[i]>=sred && tab[i]-sred<=m1)
  37. {
  38. m1=tab[i]-sred;
  39. m2=i;
  40. }
  41. else if (tab[i]<sred && sred-tab[i]<=m1)
  42. {
  43. m1=sred-tab[i];
  44. m2=i;
  45. }
  46.  
  47.  
  48. }
  49. return m2;
  50.  
  51.  
  52. }
  53.  
  54. void zad3(char tab[], char tab2[])
  55. {
  56. int rozmiar=strlen(tab);
  57.  
  58.  
  59. int j=0;
  60. for (int i=0; i<=rozmiar; i++)
  61. {
  62. tab2[j]=tab[i];
  63. j++;
  64. tab2[j]=' ';
  65. j++;
  66. }
  67. cout<<tab2<<endl;
  68. for (int i=0 ; i<=2*rozmiar; i++)
  69. {
  70. cout<<tab2[i];
  71. }
  72. }
  73.  
  74. int zad2()
  75. {
  76. string cosd;
  77. cout<<"Wprowadz string: "<<endl;
  78. cin.sync();
  79. getline(cin,cosd);
  80.  
  81. int buf=cosd.find(" ");
  82.  
  83. if (buf<0)
  84. return 0;
  85. else if (buf>=0)
  86. return 1;
  87. }
  88.  
  89.  
  90. int main() {
  91. while(true)
  92. {
  93. int tab[]={100,2,3,4};
  94. cout<<"Wybierz zadanie:"<<endl;
  95. cout<<"1. Zadanie 1"<<endl;
  96. cout<<"2. Zadanie 2"<<endl;
  97. cout<<"3. Zadanie 3"<<endl;
  98.  
  99. char tab2[100];
  100. int x;
  101. char wybor;
  102. cin>>wybor;
  103.  
  104. if (wybor=='q' || wybor=='Q')
  105. exit(0);
  106. else
  107. {
  108. switch(wybor)
  109. {
  110. case '1': cout<<zad1(tab,4); break;
  111. case '2': cout<<zad2(); break;
  112. case '3': zad3("MITP",tab2); break;
  113. }
  114. }
  115.  
  116. cout<<endl;
  117.  
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement