KakaoTalk_20190606_001802318.png
  • 246x0w
Welcome
Curriculum
Install&Go
Board
실제 작동 상태를 확인하려면 라이브 사이트로 이동하세요.
  • 카테고리
  • 전체 게시물
  • 내 게시물
avrea
2020년 7월 25일

200725

게시판: 소스 코드 제출

/*

#include <iostream>

using namespace std;


class MyIntStack{

int *p;

int size;

int tos;

public:

MyIntStack();

MyIntStack(int size);

MyIntStack(const MyIntStack& s);

~MyIntStack();

int GetSize(){return this->size;}

bool push(int n);

bool pop(int &n);

};


MyIntStack::MyIntStack(){

this->tos = 0;

}


MyIntStack::MyIntStack(int size){

this->size = size;

this->tos = 0;

this->p = new int [size];

}


MyIntStack::MyIntStack(const MyIntStack& s){

this->size = s.size;

this->tos = s.tos;

this->p = new int [size];

}

// p = (int*) malloc(sizeof(int)*n);


MyIntStack::~MyIntStack(){

if(p)

delete [] p;

}


bool MyIntStack::push(int n){

if(tos==size){return false;}

p[tos] = n;

tos++;

return true;

}


bool MyIntStack::pop(int &n){

if(tos==0){return false;}

n = p[--tos];

return true;

}


int main(){

MyIntStack a(20);

for(int i=0; i<a.GetSize()+1; i++){

if(a.push(i)) cout << i << ' ';

else cout << endl << i+1 << " 번째 stack full" << endl;

}


int n;

for(int i=0; i<a.GetSize()+1; i++){

if(a.pop(n)) cout << n << ' ';

else cout << endl << i+1 << " 번째 stack empty";

}

cout << endl;


a.push(10);

a.push(20);

MyIntStack b = a;

b.push(30);


a.pop(n);

cout << "스택 a에서 팝한 값 " << n << endl;

b.pop(n);

cout << "스택 b에서 팝한 값 " << n << endl;


return 0;

}

*/

/*

#include <iostream>

using namespace std;


class Accumulator{

int value;

public:

Accumulator(int value){ this->value = value; }

Accumulator& add(int n);

int get() { return value;}

};


Accumulator& Accumulator::add(int n){

value += n;

return *this;

}


int main(){

Accumulator acc(10);

acc.add(5).add(6).add(7);

cout << acc.get();

//Accumulator ap = acc.add(10);

}

*/

/*

#include <iostream>

#include <string>

using namespace std;


class Buffer{

public:

string text;

public:

Buffer(string text) { this->text = text; }

void add(string next) { text += next; }

void print() { cout << text << endl;}

//Buffer& append(Buffer a, string next);

};


Buffer& append(Buffer& a, string b){

a.add(b);

return a;

}


int main(){

Buffer buf("Hello");

Buffer& temp = append(buf, "Guys");

//cout << "aaa";

temp.print();

buf.print();

}

*/

/*

#include <iostream>

using namespace std;


class Dept{

int size;

int* scores;

public:

Dept(int size){

this->size = size;

scores = new int[size];

}

// Dept(const Dept& dept);

~Dept();

int getSize(){return size;}

void read();

bool isOver60(int index);

};


void Dept::read(){

cout << getSize() << "개 점수 입력>> ";

for(int i=0; i<getSize(); i++){

cin >> scores[i];

}

cout << endl;

}


bool Dept::isOver60(int index){

if(scores[index]>=60){

return true;

}

else{

return false;

}

}


Dept::~Dept(){

if(scores){

delete [] scores;

}

}


int countPass(Dept &dept){

int count=0;

for (int i=0; i<dept.getSize(); i++){

if(dept.isOver60(i)) count++;

}

return count;

}


int main(){

Dept com(10);

com.read();

int n = countPass(com);

cout << "60점 이상은 " << n << "명";

}

*/

/*

#include <iostream>

using namespace std;


int big(int a, int b){

if(a>b) return a;

else return b;

}

int big(int a[], int size){

int res = a[0];

for(int i=1; i<size; i++){

if(res < a[i]) res=a[i];

return res;

}

}


int main(){

int array[5] = {1, 9, -2, 8, 6};

cout << big(2,3) << endl;

cout << big(array, 5) << endl;

}

*/

/*

#include <iostream>

using namespace std;


int sum(int a, int b){

int s = 0;

for(int i=a; i<=b; i++)

s += i;

return s;

}


int sum(int a)

{

int s = 0;

for(int i=0; i<=a; i++)

s += i;

return s;

}


int main(){

cout << sum(3,5) << endl;

cout << sum(3) << endl;

cout << sum(100) << endl;

}

*/

/*

#include <iostream>

#include <string>

using namespace std;


void star(int a=5);

void msg(int id, string text="");


void star(int a){

for(int i=0; i<a; i++) cout << '*';

cout << endl;

}


void msg(int id, string text){

cout << id << ' ' << text << endl;

}


int main(){

star();

star(10);


msg(10);

msg(10, "Hello");

}

*/


#include <iostream>

using namespace std;


void f(char c=' ', int line=1);


void f(char c, int line){

for(int i=0; i<line; i++){

for(int j=0; j<10; j++)

cout << c;

cout << endl;

}

}


int main(){

f();

f('%');

f('@', 5);

}


댓글 0개
0
댓글
댓글 0개
유사 게시물
  • 200725
  • 200725
  • 200725
주소 : 경기도 용인시 광교중앙로 302 블루 스퀘어 602호
연락처 : 031) 216 - 1546
사업자등록번호 : 465-92-00916
​학원 등록 제 4603호