Advertisement
RedWarden

긴급갱킹050

May 20th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int *arr = new int[5];
  6. int tot = 0, avg = 0;
  7. cout << "정수 5개 입력>> ";
  8. for (int i = 0; i < 5; i++)
  9. {
  10. cin >> arr[i];
  11. tot += arr[i];
  12. }
  13. avg = tot / 5;
  14. cout << "평균 " << avg;
  15. delete[] arr;
  16. return 0;
  17. }
  18.  
  19. /////////////////////////////////////////////////////////////////
  20.  
  21. #include <iostream>
  22. #include <string>
  23. using namespace std;
  24.  
  25. int main() {
  26. int cnt = 0, index, atStr;
  27. string str;
  28. cout << "문자열 입력>> ";
  29. getline(cin, str);
  30. //at를 이용한 방법
  31. for (int i = 0; i < str.size(); i++) {
  32. if (str.at(i) == 'a') {
  33. cnt++;
  34. }
  35. }
  36. cout << "문자 a는 "<< cnt << "개 있습니다." << endl;
  37. //find를 이용한 방법
  38. cnt = 0;
  39. for (index = 0; index < str.size();) {
  40. if (str.find('a', index) != -1)
  41. {
  42. atStr = str.find('a', index) - index + 1;
  43. cnt++;
  44. index += atStr;
  45. } else {
  46. break;
  47. }
  48.  
  49. }
  50. cout << "문자 a는 " << cnt << "개 있습니다." << endl;
  51. return 0;
  52. }
  53.  
  54. ////////////////////////////////////////////////////////////////////
  55.  
  56. #include <iostream>
  57. using namespace std;
  58.  
  59. class Sample {
  60. public:
  61. Sample(int n) {
  62. size = n; p = new int[n];
  63. };
  64. void read();
  65. void write();
  66. int big();
  67. ~Sample();
  68.  
  69. private:
  70. int *p;
  71. int size;
  72. };
  73. void Sample::read() {
  74. for (int i = 0; i < size; i++)
  75. {
  76. cin >> p[i];
  77. }
  78. }
  79. void Sample::write() {
  80. for (int i = 0; i < size; i++)
  81. {
  82. cout << p[i] << " ";
  83. }
  84. cout << endl;
  85. }
  86. int Sample::big() {
  87. int max = p[0];
  88. for (int i = 1; i < size; i++)
  89. {
  90. if (max < p[i])
  91. {
  92. max = p[i];
  93. }
  94. }
  95. return max;
  96. }
  97. Sample::~Sample() {
  98. delete[] p;
  99. }
  100. int main() {
  101. Sample s(10);
  102. s.read();
  103. s.write();
  104. cout << "가장 큰 수는 " << s.big() << endl;
  105. return 0;
  106. }
  107.  
  108. /////////////////////////////////////////////////////////////////////
  109.  
  110. #include <iostream>
  111. #include <string>
  112. using namespace std;
  113.  
  114. int main() {
  115. string str;
  116. while (true)
  117. {
  118. cout << "아래에 한 줄을 입력하세요.(exit를 입력하면 종료합니다)" << endl << ">>";
  119. getline(cin, str);
  120. if (str == "exit")
  121. {
  122. break;
  123. }
  124. for (int i = str.size() - 1; i >= 0; i--)
  125. {
  126. cout << str.at(i);
  127. }
  128. cout << endl;
  129. }
  130. }
  131.  
  132. //////////////////////////////////////////////////////////////////////////////////////
  133.  
  134. #include <iostream>
  135. using namespace std;
  136.  
  137. class Circle
  138. {
  139. int radius;
  140. public:
  141. void setRadius(int radius) { this->radius = radius; };
  142. double getArea() { return 3.14*radius*radius; };
  143. };
  144.  
  145.  
  146. int main() {
  147. int input = 0, cnt = 0;
  148. Circle c1;
  149. Circle c2;
  150. Circle c3;
  151. cout << "원 1의 반지름 >> ";
  152. cin >> input;
  153. c1.setRadius(input);
  154. cout << "원 2의 반지름 >> ";
  155. cin >> input;
  156. c2.setRadius(input);
  157. cout << "원 3의 반지름 >> ";
  158. cin >> input;
  159. c3.setRadius(input);
  160.  
  161. if (c1.getArea() > 100)
  162. cnt++;
  163. if (c2.getArea() > 100)
  164. cnt++;
  165. if (c3.getArea() > 100)
  166. cnt++;
  167.  
  168. cout << "면적이 100보다 큰 원은 " << cnt << "개 입니다.";
  169. return 0;
  170. }
  171.  
  172. ///////////////////////////////////////////////////////////////////////////////////
  173.  
  174. #include <iostream>
  175. using namespace std;
  176.  
  177. class Circle
  178. {
  179. int radius;
  180. public:
  181. void setRadius(int radius) { this->radius = radius; };
  182. double getArea() { return 3.14*radius*radius; };
  183. };
  184.  
  185. class ArrCircle
  186. {
  187. int size;
  188. int overHundred;
  189. Circle *cir;
  190. public:
  191. ArrCircle(int size) {
  192. this->size = size;
  193. cir = new Circle[size];
  194. };
  195. int getSize() { return size; };
  196. void write();
  197. int getOverHundred();
  198. ~ArrCircle() {
  199. delete[] cir;
  200. }
  201. private:
  202.  
  203. };
  204. void ArrCircle::write() {
  205. for (int i = 0; i < size; i++)
  206. {
  207. int tmp;
  208. cout << "원 "<< i+1 <<"의 반지름 >> ";
  209. cin >> tmp;
  210. cir[i].setRadius(tmp);
  211. }
  212. }
  213. int ArrCircle::getOverHundred() {
  214. overHundred = 0;
  215. for (int i = 0; i < size; i++)
  216. {
  217. if (cir[i].getArea() > 100)
  218. {
  219. overHundred++;
  220. }
  221. }
  222. return overHundred;
  223. }
  224. int main() {
  225. int input = 0, cnt = 0;
  226. cout << "원의 갯수 >> ";
  227. cin >> input;
  228. ArrCircle cirArr(input);
  229. cirArr.write();
  230. cout << "면적이 100보다 큰 원은 " << cirArr.getOverHundred() << "개 입니다.";
  231. return 0;
  232. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement