Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int *arr = new int[5];
- int tot = 0, avg = 0;
- cout << "정수 5개 입력>> ";
- for (int i = 0; i < 5; i++)
- {
- cin >> arr[i];
- tot += arr[i];
- }
- avg = tot / 5;
- cout << "평균 " << avg;
- delete[] arr;
- return 0;
- }
- /////////////////////////////////////////////////////////////////
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int cnt = 0, index, atStr;
- string str;
- cout << "문자열 입력>> ";
- getline(cin, str);
- //at를 이용한 방법
- for (int i = 0; i < str.size(); i++) {
- if (str.at(i) == 'a') {
- cnt++;
- }
- }
- cout << "문자 a는 "<< cnt << "개 있습니다." << endl;
- //find를 이용한 방법
- cnt = 0;
- for (index = 0; index < str.size();) {
- if (str.find('a', index) != -1)
- {
- atStr = str.find('a', index) - index + 1;
- cnt++;
- index += atStr;
- } else {
- break;
- }
- }
- cout << "문자 a는 " << cnt << "개 있습니다." << endl;
- return 0;
- }
- ////////////////////////////////////////////////////////////////////
- #include <iostream>
- using namespace std;
- class Sample {
- public:
- Sample(int n) {
- size = n; p = new int[n];
- };
- void read();
- void write();
- int big();
- ~Sample();
- private:
- int *p;
- int size;
- };
- void Sample::read() {
- for (int i = 0; i < size; i++)
- {
- cin >> p[i];
- }
- }
- void Sample::write() {
- for (int i = 0; i < size; i++)
- {
- cout << p[i] << " ";
- }
- cout << endl;
- }
- int Sample::big() {
- int max = p[0];
- for (int i = 1; i < size; i++)
- {
- if (max < p[i])
- {
- max = p[i];
- }
- }
- return max;
- }
- Sample::~Sample() {
- delete[] p;
- }
- int main() {
- Sample s(10);
- s.read();
- s.write();
- cout << "가장 큰 수는 " << s.big() << endl;
- return 0;
- }
- /////////////////////////////////////////////////////////////////////
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string str;
- while (true)
- {
- cout << "아래에 한 줄을 입력하세요.(exit를 입력하면 종료합니다)" << endl << ">>";
- getline(cin, str);
- if (str == "exit")
- {
- break;
- }
- for (int i = str.size() - 1; i >= 0; i--)
- {
- cout << str.at(i);
- }
- cout << endl;
- }
- }
- //////////////////////////////////////////////////////////////////////////////////////
- #include <iostream>
- using namespace std;
- class Circle
- {
- int radius;
- public:
- void setRadius(int radius) { this->radius = radius; };
- double getArea() { return 3.14*radius*radius; };
- };
- int main() {
- int input = 0, cnt = 0;
- Circle c1;
- Circle c2;
- Circle c3;
- cout << "원 1의 반지름 >> ";
- cin >> input;
- c1.setRadius(input);
- cout << "원 2의 반지름 >> ";
- cin >> input;
- c2.setRadius(input);
- cout << "원 3의 반지름 >> ";
- cin >> input;
- c3.setRadius(input);
- if (c1.getArea() > 100)
- cnt++;
- if (c2.getArea() > 100)
- cnt++;
- if (c3.getArea() > 100)
- cnt++;
- cout << "면적이 100보다 큰 원은 " << cnt << "개 입니다.";
- return 0;
- }
- ///////////////////////////////////////////////////////////////////////////////////
- #include <iostream>
- using namespace std;
- class Circle
- {
- int radius;
- public:
- void setRadius(int radius) { this->radius = radius; };
- double getArea() { return 3.14*radius*radius; };
- };
- class ArrCircle
- {
- int size;
- int overHundred;
- Circle *cir;
- public:
- ArrCircle(int size) {
- this->size = size;
- cir = new Circle[size];
- };
- int getSize() { return size; };
- void write();
- int getOverHundred();
- ~ArrCircle() {
- delete[] cir;
- }
- private:
- };
- void ArrCircle::write() {
- for (int i = 0; i < size; i++)
- {
- int tmp;
- cout << "원 "<< i+1 <<"의 반지름 >> ";
- cin >> tmp;
- cir[i].setRadius(tmp);
- }
- }
- int ArrCircle::getOverHundred() {
- overHundred = 0;
- for (int i = 0; i < size; i++)
- {
- if (cir[i].getArea() > 100)
- {
- overHundred++;
- }
- }
- return overHundred;
- }
- int main() {
- int input = 0, cnt = 0;
- cout << "원의 갯수 >> ";
- cin >> input;
- ArrCircle cirArr(input);
- cirArr.write();
- cout << "면적이 100보다 큰 원은 " << cirArr.getOverHundred() << "개 입니다.";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement