top of page

게시판 게시물

kja090500
2022년 1월 04일
In 소스 코드 제출
# 딥러닝에 필요한 케라스 함수 호출 from keras.utils import np_utils from keras.models import Sequential from keras.layers import Dense, Conv2D import cv2 # 필요 라이브러리 호출 import numpy import tensorflow as tf # 데이터 셋 호출 from keras.datasets import mnist # 실행 시마다 같은 결과값 도출을 위한 시드 설정 numpy.random.seed(0) tf.random.set_seed(0) # 데이터를 불러와서 각 변수에 저장 (X_train, Y_train), (X_test, Y_test) = mnist.load_data() # 학습에 적합한 형태로 데이터 가공 X_train = X_train.reshape(X_train.shape[0], 784).astype('float32') / 255 X_test = X_test.reshape(X_test.shape[0], 784).astype('float32') / 255 # 클래스를 학습에 이용하기 위해 데이터 가공 Y_train = np_utils.to_categorical(Y_train, 10) Y_test = np_utils.to_categorical(Y_test, 10) # 딥러닝 모델 구조 설정(2개층, 512개의 뉴런 연결, 10개 클래스 출력 뉴런, 784개 픽셀 input 값, relu와 softmax 활성화 함수 이용) ''' model = Sequential() model.add(Dense(512, input_dim=784, activation='relu')) model.add(Dense(10, activation='softmax')) ''' model = tf.keras.Sequential() model.add(Dense(512, input_dim=784, activation='relu')) model.add(tf.keras.layers.Dense(units = 320, activation = 'sigmoid')) model.add(tf.keras.layers.Dense(units = 160, activation = 'sigmoid')) model.add(tf.keras.layers.Dense(units = 80, activation = 'sigmoid')) model.add(tf.keras.layers.Dense(units = 40, activation = 'sigmoid')) model.add(tf.keras.layers.Dense(units = 20, activation = 'sigmoid')) model.add(tf.keras.layers.Dense(units = 10, activation = 'softmax')) model.summary() # 딥러닝 구조 설정(loss 옵션을 다중 클래스에 적합한 categorical_crossentropy, 옵티마이저는 adam 설정) model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) # 모델 실행(X_test, Y_test로 검증, 200개씩 30번 학습) model.fit(X_train, Y_train, validation_data=(X_test, Y_test), epochs=30, batch_size=100, verbose=2) # 학습 정확도, 검증 정확도 출력 print('\nAccuracy: {:.4f}'.format(model.evaluate(X_train, Y_train)[1])) print('\nVal_Accuracy: {:.4f}'.format(model.evaluate(X_test, Y_test)[1])) # 모델 저장 model.save('Predict_Model.h5') # 딥러닝에 필요한 케라스 함수 호출 from keras.models import load_model from keras.utils import np_utils # 필요 라이브러리 호출(PIL은 이미지파일 처리위함) from PIL import Image import numpy as np import random # test.png는 그림판에서 붓으로 숫자 8을 그린 이미지 파일 # test.png 파일 열어서 L(256단계 흑백이미지)로 변환 #i = random.randrange(0,20) img = [] sum=0 b =0 answer = [2, 7, 8, 2, 3, 1, 9, 4, 1, 3, 4, 5, 5, 6, 6, 7, 8, 9, 0, 0] anssuc = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ansfal = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] success = 0 fail = 0 while(1): i = random.randrange(0, 20) #print(i,end = "***********\n") img = cv2.imread('./numbers/'+str(i)+'.png', cv2.IMREAD_GRAYSCALE) # 이미지를 784개 흑백 픽셀로 사이즈 변환 img = np.resize(img, (1, 784)) # 데이터를 모델에 적용할 수 있도록 가공 test_data = [] test_data.append(((np.array(img) / 255) - 1) * -1) # 모델 불러오기 model = load_model('Predict_Model.h5') # 클래스 예측 함수에 가공된 테스트 데이터 넣어 결과 도출 res = model.predict(test_data,verbose = 0) res0 = res.argmax(axis=-1) # 2021/10/02 수정 - 오류시 아래 명령어로 대체 가능합니다. # res =(model.predict(test_data) > 0.5).astype("int32") k = res0.max() ans = answer[i] #print(k, i) if k == ans: success += 1 anssuc[i] += 1 else: fail += 1 ansfal[i] += 1 b+=1 a = res0.max() sum = sum+a if b%10==0: print('>', end='') if b>10: print(sum) print(success, fail) print(success/(success+fail), fail/(success+fail)) print(anssuc) print(ansfal) break list0 = [] list0.append(res0.max())
0
0
4
kja090500
2021년 12월 28일
In 소스 코드 제출
# 딥러닝에 필요한 케라스 함수 호출 from keras.utils import np_utils from keras.models import Sequential from keras.layers import Dense, Conv2D import cv2 # 필요 라이브러리 호출 import numpy import tensorflow as tf # 데이터 셋 호출 from keras.datasets import mnist # 실행 시마다 같은 결과값 도출을 위한 시드 설정 numpy.random.seed(0) tf.random.set_seed(0) # 데이터를 불러와서 각 변수에 저장 (X_train, Y_train), (X_test, Y_test) = mnist.load_data() # 학습에 적합한 형태로 데이터 가공 X_train = X_train.reshape(X_train.shape[0], 784).astype('float32') / 255 X_test = X_test.reshape(X_test.shape[0], 784).astype('float32') / 255 # 클래스를 학습에 이용하기 위해 데이터 가공 Y_train = np_utils.to_categorical(Y_train, 10) Y_test = np_utils.to_categorical(Y_test, 10) # 딥러닝 모델 구조 설정(2개층, 512개의 뉴런 연결, 10개 클래스 출력 뉴런, 784개 픽셀 input 값, relu와 softmax 활성화 함수 이용) ''' model = Sequential() model.add(Dense(512, input_dim=784, activation='relu')) model.add(Dense(10, activation='softmax')) ''' model = tf.keras.Sequential() model.add(Dense(512, input_dim=784, activation='relu')) model.add(tf.keras.layers.Dense(units = 320, activation = 'sigmoid')) model.add(tf.keras.layers.Dense(units = 160, activation = 'sigmoid')) model.add(tf.keras.layers.Dense(units = 80, activation = 'sigmoid')) model.add(tf.keras.layers.Dense(units = 40, activation = 'sigmoid')) model.add(tf.keras.layers.Dense(units = 20, activation = 'sigmoid')) model.add(tf.keras.layers.Dense(units = 10, activation = 'softmax')) model.summary() # 딥러닝 구조 설정(loss 옵션을 다중 클래스에 적합한 categorical_crossentropy, 옵티마이저는 adam 설정) model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) # 모델 실행(X_test, Y_test로 검증, 200개씩 30번 학습) model.fit(X_train, Y_train, validation_data=(X_test, Y_test), epochs=30, batch_size=100, verbose=2) # 학습 정확도, 검증 정확도 출력 print('\nAccuracy: {:.4f}'.format(model.evaluate(X_train, Y_train)[1])) print('\nVal_Accuracy: {:.4f}'.format(model.evaluate(X_test, Y_test)[1])) # 모델 저장 model.save('Predict_Model.h5') # 딥러닝에 필요한 케라스 함수 호출 from keras.models import load_model from keras.utils import np_utils # 필요 라이브러리 호출(PIL은 이미지파일 처리위함) from PIL import Image import numpy as np import random # test.png는 그림판에서 붓으로 숫자 8을 그린 이미지 파일 # test.png 파일 열어서 L(256단계 흑백이미지)로 변환 #i = random.randrange(0,20) img = [] sum=0 b =0 answer = [2, 7, 8, 2, 3, 1, 9, 4, 1, 3, 4, 5, 5, 6, 6, 7, 8, 9, 0, 0] anssuc = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ansfal = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] success = 0 fail = 0 while(1): i = random.randrange(0, 20) #print(i,end = "***********\n") img = cv2.imread('./numbers/'+str(i)+'.png', cv2.IMREAD_GRAYSCALE) # 이미지를 784개 흑백 픽셀로 사이즈 변환 img = np.resize(img, (1, 784)) # 데이터를 모델에 적용할 수 있도록 가공 test_data = [] test_data.append(((np.array(img) / 255) - 1) * -1) # 모델 불러오기 model = load_model('Predict_Model.h5') # 클래스 예측 함수에 가공된 테스트 데이터 넣어 결과 도출 res = model.predict(test_data,verbose = 0) res0 = res.argmax(axis=-1) # 2021/10/02 수정 - 오류시 아래 명령어로 대체 가능합니다. # res =(model.predict(test_data) > 0.5).astype("int32") k = res0.max() ans = answer[i] #print(k, i) if k == ans: success += 1 anssuc[i] += 1 else: fail += 1 ansfal[i] += 1 b+=1 a = res0.max() sum = sum+a if b%10==0: print('>', end='') if b>1000: print(sum) print(success, fail) print(success/(success+fail), fail/(success+fail)) print(anssuc) print(ansfal) break list0 = [] list0.append(res0.max())
0
0
4
kja090500
2021년 11월 23일
In 소스 코드 제출
#이미지 컬러있는 버전으로 나오는 거 ''' import cv2 import numpy as np img = cv2.imread('./images/meat.jpeg', cv2.IMREAD_GRAYSCALE) #hist,bins = np.histogram(img.ravel(),256,[0,256]) cv2.imshow('color', img) cv2.waitKey() cv2.destroyAllwindows() ''' #히스토그램 from typing import List, Any import numpy '''import cv2 from matplotlib import pyplot as plt img = cv2.imread('./images/meat.jpeg') color = ('b','g','r') for i,col in enumerate(color): histr = cv2.calcHist([img],[i],None,[256],[0,256]) plt.plot(histr,color = col) plt.xlim([0,256]) plt.show() ''' ''' import cv2 import numpy as np img = cv2.imread('./images/meat.jpeg') x=320; y=150; w=50; h=50 # roi 좌표 roi = img[y:y+h, x:x+w] # roi 지정 ---① print(roi.shape) # roi shape, (50,50,3) cv2.rectangle(roi, (0,0), (h-10, w+100), (0,0,255)) # roi 전체에 사각형 그리기 ---② cv2.imshow("img", img) key = cv2.waitKey(0) print(key) cv2.destroyAllWindows() ''' ''' import cv2 import numpy as np import matplotlib.pylab as plt # haarcascade 불러오기 face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml') eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_eye.xml') # 이미지 불러오기 img = cv2.imread('./images2/face2.jpg') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) img2 = cv2.imread('./images2/face2.jpg') # 얼굴 찾기 faces = face_cascade.detectMultiScale(gray, 1.3, 5) k = 0 loc = [] for (x, y, w, h) in faces: #face = cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2) loc.append([x, y]) #print(loc) # 눈 찾기 roi_color = img[y:y + h, x:x + w] # jooseok roi_gray = gray[y:y + h, x:x + w] if k==0: roi_first = gray[y:y + h, x:x + w] #print(roi_gray) cv2.imwrite('./images/result' + str(k) + '.jpg', roi_color) k += 1 for i in range(len(roi_first)): for j in range(len(roi_first[i])): img[i+y][j+x] = roi_first[i][j] # 얼굴부분을 한 사람 얼굴로 전부 바꾸기 eyes = eye_cascade.detectMultiScale(gray) for (ex, ey, ew, eh) in eyes: roi_color1 = img2[ey:ey+eh, ex:ex+ew] for l in range(len(roi_color1)): for t in range(len(roi_color1[l])): img[l+ey][t+ex] = roi_color1[l][t] #눈부분만 컬러로 (각얼굴에 맞게) #cv2.rectangle(roi_color, (ex, ey), (ex+ew, ey+eh), (0, 255, 0), 2) # 영상 출력 cv2.imshow('image', img) from matplotlib import pyplot as plt img = cv2.imread('./images2/face2.jpg',0) ''' ''' color = ('b','g','r') for i,col in enumerate(color): histr = cv2.calcHist([img],[i],None,[256],[0,256]) plt.plot(histr,color = col) plt.xlim([0,256]) plt.show() ''' ''' img2 = cv2.equalizeHist(img) img = cv2.resize(img,(400,400)) img2 = cv2.resize(img2,(400,400)) dst = np.hstack((img, img2)) cv2.imshow('img',dst) cv2.waitKey() cv2.destroyAllWindows() ''' ''' clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8)) img2 = clahe.apply(img) img = cv2.resize(img,(400,400)) img2 = cv2.resize(img2,(400,400)) dst = np.hstack((img, img2)) cv2.imshow('img',dst) #print(loc) key = cv2.waitKey(0) cv2.destroyAllWindows() import glob target_dir = './images/' files = glob.glob(target_dir+'*.*') #print(files) from PIL import Image def imgresize(files,x_size,y_size): file_list = [] for file in files: image = Image.open(file) resized_file = image.resize((x_size,y_size)) file_list.append(resized_file) thumb_sizeX = 100 thumb_sizeY = 100 file_list = imgresize(files, thumb_sizeX,thumb_sizeY) def imgMerge(file_list,sizeX,sizeY,numX): new_image = Image.new("RGB",(sizeX*numX,sizeY*(len(file_list)//numX+1)),(256,256,256)) count_X = 0 count_Y = 0 for index in range(len(file_list)): area = ((count_X*sizeX),count_Y*sizeY,(count_X+1)*sizeX,(count_Y+1)*sizeY) new_image.paste(file_list[index],area) if(index+1)%numX ==0: count_Y+=1 count_X =0 else: count_X +=1 new_image.show() new_image.save('./images2/face2','jpg') numX = 3 imgMerge(file_list,thumb_sizeX, thumb_sizeY, numX) ''' import tensorflow as tf ''' # 1. MNIST 데이터셋 임포트 mnist = tf.keras.datasets.mnist (x_train, y_train), (x_test, y_test) = mnist.load_data() # 2. 데이터 전처리 x_train, x_test = x_train/255.0, x_test/255.0 # 3. 모델 구성 model = tf.keras.models.Sequential([ tf.keras.layers.Flatten(input_shape=(28, 28)), tf.keras.layers.Dense(512, activation=tf.nn.relu), tf.keras.layers.Dense(10, activation=tf.nn.softmax) ]) # 4. 모델 컴파일 model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) # 5. 모델 훈련 model.fit(x_train, y_train, epochs=20) # 6. 정확도 평가 test_loss, test_acc = model.evaluate(x_test, y_test) print('테스트 정확도:', test_acc) ''' ''' import sys import tensorflow as tf from PyQt5.QtWidgets import * from PyQt5.QtGui import * from PyQt5.QtCore import * import numpy as np class MyApp(QMainWindow): def __init__(self): super().__init__() self.image = QImage(QSize(400, 400), QImage.Format_RGB32) self.image.fill(Qt.white) self.drawing = False self.brush_size = 30 self.brush_color = Qt.black self.last_point = QPoint() self.loaded_model = None self.initUI() def initUI(self): menubar = self.menuBar() menubar.setNativeMenuBar(False) filemenu = menubar.addMenu('File') load_model_action = QAction('Load model', self) load_model_action.setShortcut('Ctrl+L') load_model_action.triggered.connect(self.load_model) save_action = QAction('Save', self) save_action.setShortcut('Ctrl+S') save_action.triggered.connect(self.save) clear_action = QAction('Clear', self) clear_action.setShortcut('Ctrl+C') clear_action.triggered.connect(self.clear) filemenu.addAction(load_model_action) filemenu.addAction(save_action) filemenu.addAction(clear_action) self.statusbar = self.statusBar() self.setWindowTitle('MNIST Classifier') self.setGeometry(300, 300, 400, 400) self.show() def paintEvent(self, e): canvas = QPainter(self) canvas.drawImage(self.rect(), self.image, self.image.rect()) def mousePressEvent(self, e): if e.button() == Qt.LeftButton: self.drawing = True self.last_point = e.pos() def mouseMoveEvent(self, e): if (e.buttons() & Qt.LeftButton) & self.drawing: painter = QPainter(self.image) painter.setPen(QPen(self.brush_color, self.brush_size, Qt.SolidLine, Qt.RoundCap)) painter.drawLine(self.last_point, e.pos()) self.last_point = e.pos() self.update() def mouseReleaseEvent(self, e): if e.button() == Qt.LeftButton: self.drawing = False arr = np.zeros((28, 28)) for i in range(28): for j in range(28): arr[j, i] = 1 - self.image.scaled(28, 28).pixelColor(i, j).getRgb()[0] / 255.0 arr = arr.reshape(-1, 28, 28) if self.loaded_model: pred = self.loaded_model.predict(arr)[0] pred_num = str(np.argmax(pred)) self.statusbar.showMessage('숫자 ' + pred_num + '입니다.') def load_model(self): fname, _ = QFileDialog.getOpenFileName(self, 'Load Model', '') if fname: self.loaded_model = tf.keras.models.load_model(fname) self.statusbar.showMessage('Model loaded.') def save(self): fpath, _ = QFileDialog.getSaveFileName(self, 'Save Image', '', "PNG(*.png);;JPEG(*.jpg *.jpeg);;All Files(*.*) ") if fpath: self.image.scaled(28, 28).save(fpath) def clear(self): self.image.fill(Qt.white) self.update() self.statusbar.clearMessage() if __name__ == '__main__': app = QApplication(sys.argv) ex = MyApp() sys.exit(app.exec_()) ''' import tensorflow as tf from tensorflow import keras from tensorflow.keras import layers import matplotlib.pyplot as plt #from google.colab import auth #from google.colab import drive import cv2 import numpy as np #drive.mount('/content/gdrive/') # google drive address #import glob import os scr = os.listdir('./long numbers/') ''' plt.title('The number I write') plt.imshow(myNum, cmap='gray') print(myNum.shape) ''' # data input mnist = tf.keras.datasets.mnist (x_train, y_train), (x_test, y_test) = mnist.load_data() x_train, x_test = x_train/255.0, x_test/255.0 print(x_train.shape, y_train.shape, x_test.shape, y_test.shape) # view Images ''' plt.figure(figsize=(10, 10)) c = 0 for x in range(2): for y in range(5): plt.subplot(2, 5, c+1) plt.imshow(x_train[c], cmap='gray') c+=1 plt.show() print(y_train[:10]) ''' # make a model model = tf.keras.models.Sequential([ tf.keras.layers.Flatten(input_shape=(28, 28)), tf.keras.layers.Dense(128, activation='relu'), tf.keras.layers.Dropout(0.2), tf.keras.layers.Dense(10, activation='softmax') ]) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) model.summary() model.fit(x_train, y_train, epochs=1) model.evaluate(x_test, y_test) # test my Image data myNum = np.array(myNum) #v = model.predict(np.reshape(myNum, (1,28,28))) #print(v) #print(max(v[0])) #이미지 파일 하나 찝어와서 안의 숫자 인식, 출력 sum = 0 dataVV = [] s = [] #for i in range(3): for i in range(2): #path = os.path.join('./number/'+str(scr[i])) src = cv2.imread('./long numbers/result'+str(i)+'.png', cv2.IMREAD_GRAYSCALE) dataVV.append(src) s.append() dst = [] for i in range(0,140,28): dst.append(dataVV[0:28, 0:28].copy()) 5 < dataVV[0] for i in range(0,len(dataVV)): ret, binary = cv2.threhold(dataVV[i]) for i in range(0,len(dataVV)): ret, binary = cv2.threshold(dataVV[i], 170, 255, cv2.THRESH_BINARY_INV) scr = np.asarray(cv2.resize(binary,dsize=(28, 28), interpolation=cv2.INTER_AREA))/255 myNum = np.array(scr) v = model.predict(np.reshape(myNum, (1, 28, 28))) s.append(list(v[i]).index(max(v[i]))) sum += int(s.pop())*(10*(i+1)) print(sum) ''' import random from PIL import Image width1 = 28*5 height1 = 28 path1 = './numbers/0.png' path2 = './numbers/1.png' path3 = './numbers/2.png' list_input = [] for i in range(20): #v = cv2.imread('./numbers/'+str(i)+'.png', cv2.IMREAD_GRAYSCALE) #v = numpy.array(v) v = Image.open('./numbers/'+str(i)+'.png') list_input.append(v) #list_input[i] = cv2.imread('./numbers/'+str(i)+'.png', cv2.IMREAD_GRAYSCALE) idx =0 for i in range(3): idx +=1 for j in range(20): result0 = Image.new("L",(width1,height1)) for i in range(5): v = random.randrange(0,19) result0.paste(im = list_input[v],box = (i*28, 0)) result0.save('./numbers/result'+str(j)+'.png'.format(idx)) print(sum) ''' r = []; ret , binary = cv2.threshold(src,170,255,cv2.THRESH_BINARY_INV) if (type(scr) == type(None)): pass else: scr = np.asarray(cv2.resize(binary,dsize=(28, 28), interpolation=cv2.INTER_AREA))/255 #vv = np.asarray(cv2.resize(binary, dsize=(28, 28), interpolation=cv2.INTER_AREA))/255 #dataVV.append() myNum = np.array(binary) v = model.predict(np.reshape(myNum, (1, 28, 28))) s = list(v[0]).index(max(v[0])) r.append(s); for i in range(len(r),0): a = s.pop() sum += a*(10**len(r)) print('>',sum)
0
0
5
kja090500
2021년 11월 21일
In 소스 코드 제출
#이미지 컬러있는 버전으로 나오는 거 ''' import cv2 import numpy as np img = cv2.imread('./images/meat.jpeg', cv2.IMREAD_GRAYSCALE) #hist,bins = np.histogram(img.ravel(),256,[0,256]) cv2.imshow('color', img) cv2.waitKey() cv2.destroyAllwindows() ''' #히스토그램 import numpy '''import cv2 from matplotlib import pyplot as plt img = cv2.imread('./images/meat.jpeg') color = ('b','g','r') for i,col in enumerate(color): histr = cv2.calcHist([img],[i],None,[256],[0,256]) plt.plot(histr,color = col) plt.xlim([0,256]) plt.show() ''' ''' import cv2 import numpy as np img = cv2.imread('./images/meat.jpeg') x=320; y=150; w=50; h=50 # roi 좌표 roi = img[y:y+h, x:x+w] # roi 지정 ---① print(roi.shape) # roi shape, (50,50,3) cv2.rectangle(roi, (0,0), (h-10, w+100), (0,0,255)) # roi 전체에 사각형 그리기 ---② cv2.imshow("img", img) key = cv2.waitKey(0) print(key) cv2.destroyAllWindows() ''' ''' import cv2 import numpy as np import matplotlib.pylab as plt # haarcascade 불러오기 face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml') eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_eye.xml') # 이미지 불러오기 img = cv2.imread('./images2/face2.jpg') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) img2 = cv2.imread('./images2/face2.jpg') # 얼굴 찾기 faces = face_cascade.detectMultiScale(gray, 1.3, 5) k = 0 loc = [] for (x, y, w, h) in faces: #face = cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2) loc.append([x, y]) #print(loc) # 눈 찾기 roi_color = img[y:y + h, x:x + w] # jooseok roi_gray = gray[y:y + h, x:x + w] if k==0: roi_first = gray[y:y + h, x:x + w] #print(roi_gray) cv2.imwrite('./images/result' + str(k) + '.jpg', roi_color) k += 1 for i in range(len(roi_first)): for j in range(len(roi_first[i])): img[i+y][j+x] = roi_first[i][j] # 얼굴부분을 한 사람 얼굴로 전부 바꾸기 eyes = eye_cascade.detectMultiScale(gray) for (ex, ey, ew, eh) in eyes: roi_color1 = img2[ey:ey+eh, ex:ex+ew] for l in range(len(roi_color1)): for t in range(len(roi_color1[l])): img[l+ey][t+ex] = roi_color1[l][t] #눈부분만 컬러로 (각얼굴에 맞게) #cv2.rectangle(roi_color, (ex, ey), (ex+ew, ey+eh), (0, 255, 0), 2) # 영상 출력 cv2.imshow('image', img) from matplotlib import pyplot as plt img = cv2.imread('./images2/face2.jpg',0) ''' ''' color = ('b','g','r') for i,col in enumerate(color): histr = cv2.calcHist([img],[i],None,[256],[0,256]) plt.plot(histr,color = col) plt.xlim([0,256]) plt.show() ''' ''' img2 = cv2.equalizeHist(img) img = cv2.resize(img,(400,400)) img2 = cv2.resize(img2,(400,400)) dst = np.hstack((img, img2)) cv2.imshow('img',dst) cv2.waitKey() cv2.destroyAllWindows() ''' ''' clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8)) img2 = clahe.apply(img) img = cv2.resize(img,(400,400)) img2 = cv2.resize(img2,(400,400)) dst = np.hstack((img, img2)) cv2.imshow('img',dst) #print(loc) key = cv2.waitKey(0) cv2.destroyAllWindows() import glob target_dir = './images/' files = glob.glob(target_dir+'*.*') #print(files) from PIL import Image def imgresize(files,x_size,y_size): file_list = [] for file in files: image = Image.open(file) resized_file = image.resize((x_size,y_size)) file_list.append(resized_file) thumb_sizeX = 100 thumb_sizeY = 100 file_list = imgresize(files, thumb_sizeX,thumb_sizeY) def imgMerge(file_list,sizeX,sizeY,numX): new_image = Image.new("RGB",(sizeX*numX,sizeY*(len(file_list)//numX+1)),(256,256,256)) count_X = 0 count_Y = 0 for index in range(len(file_list)): area = ((count_X*sizeX),count_Y*sizeY,(count_X+1)*sizeX,(count_Y+1)*sizeY) new_image.paste(file_list[index],area) if(index+1)%numX ==0: count_Y+=1 count_X =0 else: count_X +=1 new_image.show() new_image.save('./images2/face2','jpg') numX = 3 imgMerge(file_list,thumb_sizeX, thumb_sizeY, numX) ''' import tensorflow as tf ''' # 1. MNIST 데이터셋 임포트 mnist = tf.keras.datasets.mnist (x_train, y_train), (x_test, y_test) = mnist.load_data() # 2. 데이터 전처리 x_train, x_test = x_train/255.0, x_test/255.0 # 3. 모델 구성 model = tf.keras.models.Sequential([ tf.keras.layers.Flatten(input_shape=(28, 28)), tf.keras.layers.Dense(512, activation=tf.nn.relu), tf.keras.layers.Dense(10, activation=tf.nn.softmax) ]) # 4. 모델 컴파일 model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) # 5. 모델 훈련 model.fit(x_train, y_train, epochs=20) # 6. 정확도 평가 test_loss, test_acc = model.evaluate(x_test, y_test) print('테스트 정확도:', test_acc) ''' ''' import sys import tensorflow as tf from PyQt5.QtWidgets import * from PyQt5.QtGui import * from PyQt5.QtCore import * import numpy as np class MyApp(QMainWindow): def __init__(self): super().__init__() self.image = QImage(QSize(400, 400), QImage.Format_RGB32) self.image.fill(Qt.white) self.drawing = False self.brush_size = 30 self.brush_color = Qt.black self.last_point = QPoint() self.loaded_model = None self.initUI() def initUI(self): menubar = self.menuBar() menubar.setNativeMenuBar(False) filemenu = menubar.addMenu('File') load_model_action = QAction('Load model', self) load_model_action.setShortcut('Ctrl+L') load_model_action.triggered.connect(self.load_model) save_action = QAction('Save', self) save_action.setShortcut('Ctrl+S') save_action.triggered.connect(self.save) clear_action = QAction('Clear', self) clear_action.setShortcut('Ctrl+C') clear_action.triggered.connect(self.clear) filemenu.addAction(load_model_action) filemenu.addAction(save_action) filemenu.addAction(clear_action) self.statusbar = self.statusBar() self.setWindowTitle('MNIST Classifier') self.setGeometry(300, 300, 400, 400) self.show() def paintEvent(self, e): canvas = QPainter(self) canvas.drawImage(self.rect(), self.image, self.image.rect()) def mousePressEvent(self, e): if e.button() == Qt.LeftButton: self.drawing = True self.last_point = e.pos() def mouseMoveEvent(self, e): if (e.buttons() & Qt.LeftButton) & self.drawing: painter = QPainter(self.image) painter.setPen(QPen(self.brush_color, self.brush_size, Qt.SolidLine, Qt.RoundCap)) painter.drawLine(self.last_point, e.pos()) self.last_point = e.pos() self.update() def mouseReleaseEvent(self, e): if e.button() == Qt.LeftButton: self.drawing = False arr = np.zeros((28, 28)) for i in range(28): for j in range(28): arr[j, i] = 1 - self.image.scaled(28, 28).pixelColor(i, j).getRgb()[0] / 255.0 arr = arr.reshape(-1, 28, 28) if self.loaded_model: pred = self.loaded_model.predict(arr)[0] pred_num = str(np.argmax(pred)) self.statusbar.showMessage('숫자 ' + pred_num + '입니다.') def load_model(self): fname, _ = QFileDialog.getOpenFileName(self, 'Load Model', '') if fname: self.loaded_model = tf.keras.models.load_model(fname) self.statusbar.showMessage('Model loaded.') def save(self): fpath, _ = QFileDialog.getSaveFileName(self, 'Save Image', '', "PNG(*.png);;JPEG(*.jpg *.jpeg);;All Files(*.*) ") if fpath: self.image.scaled(28, 28).save(fpath) def clear(self): self.image.fill(Qt.white) self.update() self.statusbar.clearMessage() if __name__ == '__main__': app = QApplication(sys.argv) ex = MyApp() sys.exit(app.exec_()) ''' import tensorflow as tf from tensorflow import keras from tensorflow.keras import layers import matplotlib.pyplot as plt #from google.colab import auth #from google.colab import drive import cv2 import numpy as np #drive.mount('/content/gdrive/') # google drive address #import glob import os scr = os.listdir('./long numbers/') ''' plt.title('The number I write') plt.imshow(myNum, cmap='gray') print(myNum.shape) ''' # data input mnist = tf.keras.datasets.mnist (x_train, y_train), (x_test, y_test) = mnist.load_data() x_train, x_test = x_train/255.0, x_test/255.0 print(x_train.shape, y_train.shape, x_test.shape, y_test.shape) # view Images ''' plt.figure(figsize=(10, 10)) c = 0 for x in range(2): for y in range(5): plt.subplot(2, 5, c+1) plt.imshow(x_train[c], cmap='gray') c+=1 plt.show() print(y_train[:10]) ''' # make a model model = tf.keras.models.Sequential([ tf.keras.layers.Flatten(input_shape=(28, 28)), tf.keras.layers.Dense(128, activation='relu'), tf.keras.layers.Dropout(0.2), tf.keras.layers.Dense(10, activation='softmax') ]) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) model.summary() model.fit(x_train, y_train, epochs=1) model.evaluate(x_test, y_test) # test my Image data #myNum = np.array(myNum) #v = model.predict(np.reshape(myNum, (1,28,28))) #print(v) #print(max(v[0])) #이미지 파일 하나 찝어와서 안의 숫자 인식, 출력 sum = 0 dataVV = [] s = [] #for i in range(3): for i in range(2): #path = os.path.join('./number/'+str(scr[i])) src = cv2.imread('./long numbers/result'+str(i)+'.png', cv2.IMREAD_GRAYSCALE) dataVV.append(src) 5 < dataVV[0] for i in range(0,len(dataVV)): ret, binary = cv2.threshold(dataVV[i], 170, 255, cv2.THRESH_BINARY_INV) scr = np.asarray(cv2.resize(binary,dsize=(28, 28), interpolation=cv2.INTER_AREA))/255 myNum = np.array(scr) v = model.predict(np.reshape(myNum, (1, 28, 28))) s.append(list(v[i]).index(max(v[i]))) sum += int(s.pop())*(10*(i+1)) print(sum) ''' import random from PIL import Image width1 = 28*5 height1 = 28 path1 = './numbers/0.png' path2 = './numbers/1.png' path3 = './numbers/2.png' list_input = [] for i in range(20): #v = cv2.imread('./numbers/'+str(i)+'.png', cv2.IMREAD_GRAYSCALE) #v = numpy.array(v) v = Image.open('./numbers/'+str(i)+'.png') list_input.append(v) #list_input[i] = cv2.imread('./numbers/'+str(i)+'.png', cv2.IMREAD_GRAYSCALE) idx =0 for i in range(3): idx +=1 for j in range(20): result0 = Image.new("L",(width1,height1)) for i in range(5): v = random.randrange(0,19) result0.paste(im = list_input[v],box = (i*28, 0)) result0.save('./numbers/result'+str(j)+'.png'.format(idx)) print(sum) ''' ''' ret , binary = cv2.threshold(src,170,255,cv2.THRESH_BINARY_INV) if (type(scr) == type(None)): pass else: scr = np.asarray(cv2.resize(binary,dsize=(28, 28), interpolation=cv2.INTER_AREA))/255 #vv = np.asarray(cv2.resize(binary, dsize=(28, 28), interpolation=cv2.INTER_AREA))/255 #dataVV.append() myNum = np.array(binary) v = model.predict(np.reshape(myNum, (1, 28, 28))) s = list(v[0]).index(max(v[0])) print(s) sum += s print('>',sum) '''
0
0
3
kja090500
2021년 11월 16일
In 소스 코드 제출
#이미지 컬러있는 버전으로 나오는 거 ''' import cv2 import numpy as np img = cv2.imread('./images/meat.jpeg', cv2.IMREAD_GRAYSCALE) #hist,bins = np.histogram(img.ravel(),256,[0,256]) cv2.imshow('color', img) cv2.waitKey() cv2.destroyAllwindows() ''' #히스토그램 '''import cv2 from matplotlib import pyplot as plt img = cv2.imread('./images/meat.jpeg') color = ('b','g','r') for i,col in enumerate(color): histr = cv2.calcHist([img],[i],None,[256],[0,256]) plt.plot(histr,color = col) plt.xlim([0,256]) plt.show() ''' ''' import cv2 import numpy as np img = cv2.imread('./images/meat.jpeg') x=320; y=150; w=50; h=50 # roi 좌표 roi = img[y:y+h, x:x+w] # roi 지정 ---① print(roi.shape) # roi shape, (50,50,3) cv2.rectangle(roi, (0,0), (h-10, w+100), (0,0,255)) # roi 전체에 사각형 그리기 ---② cv2.imshow("img", img) key = cv2.waitKey(0) print(key) cv2.destroyAllWindows() ''' ''' import cv2 import numpy as np import matplotlib.pylab as plt # haarcascade 불러오기 face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml') eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_eye.xml') # 이미지 불러오기 img = cv2.imread('./images2/face2.jpg') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) img2 = cv2.imread('./images2/face2.jpg') # 얼굴 찾기 faces = face_cascade.detectMultiScale(gray, 1.3, 5) k = 0 loc = [] for (x, y, w, h) in faces: #face = cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2) loc.append([x, y]) #print(loc) # 눈 찾기 roi_color = img[y:y + h, x:x + w] # jooseok roi_gray = gray[y:y + h, x:x + w] if k==0: roi_first = gray[y:y + h, x:x + w] #print(roi_gray) cv2.imwrite('./images/result' + str(k) + '.jpg', roi_color) k += 1 for i in range(len(roi_first)): for j in range(len(roi_first[i])): img[i+y][j+x] = roi_first[i][j] # 얼굴부분을 한 사람 얼굴로 전부 바꾸기 eyes = eye_cascade.detectMultiScale(gray) for (ex, ey, ew, eh) in eyes: roi_color1 = img2[ey:ey+eh, ex:ex+ew] for l in range(len(roi_color1)): for t in range(len(roi_color1[l])): img[l+ey][t+ex] = roi_color1[l][t] #눈부분만 컬러로 (각얼굴에 맞게) #cv2.rectangle(roi_color, (ex, ey), (ex+ew, ey+eh), (0, 255, 0), 2) # 영상 출력 cv2.imshow('image', img) from matplotlib import pyplot as plt img = cv2.imread('./images2/face2.jpg',0) ''' ''' color = ('b','g','r') for i,col in enumerate(color): histr = cv2.calcHist([img],[i],None,[256],[0,256]) plt.plot(histr,color = col) plt.xlim([0,256]) plt.show() ''' ''' img2 = cv2.equalizeHist(img) img = cv2.resize(img,(400,400)) img2 = cv2.resize(img2,(400,400)) dst = np.hstack((img, img2)) cv2.imshow('img',dst) cv2.waitKey() cv2.destroyAllWindows() ''' ''' clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8)) img2 = clahe.apply(img) img = cv2.resize(img,(400,400)) img2 = cv2.resize(img2,(400,400)) dst = np.hstack((img, img2)) cv2.imshow('img',dst) #print(loc) key = cv2.waitKey(0) cv2.destroyAllWindows() import glob target_dir = './images/' files = glob.glob(target_dir+'*.*') #print(files) from PIL import Image def imgresize(files,x_size,y_size): file_list = [] for file in files: image = Image.open(file) resized_file = image.resize((x_size,y_size)) file_list.append(resized_file) thumb_sizeX = 100 thumb_sizeY = 100 file_list = imgresize(files, thumb_sizeX,thumb_sizeY) def imgMerge(file_list,sizeX,sizeY,numX): new_image = Image.new("RGB",(sizeX*numX,sizeY*(len(file_list)//numX+1)),(256,256,256)) count_X = 0 count_Y = 0 for index in range(len(file_list)): area = ((count_X*sizeX),count_Y*sizeY,(count_X+1)*sizeX,(count_Y+1)*sizeY) new_image.paste(file_list[index],area) if(index+1)%numX ==0: count_Y+=1 count_X =0 else: count_X +=1 new_image.show() new_image.save('./images2/face2','jpg') numX = 3 imgMerge(file_list,thumb_sizeX, thumb_sizeY, numX) ''' import tensorflow as tf ''' # 1. MNIST 데이터셋 임포트 mnist = tf.keras.datasets.mnist (x_train, y_train), (x_test, y_test) = mnist.load_data() # 2. 데이터 전처리 x_train, x_test = x_train/255.0, x_test/255.0 # 3. 모델 구성 model = tf.keras.models.Sequential([ tf.keras.layers.Flatten(input_shape=(28, 28)), tf.keras.layers.Dense(512, activation=tf.nn.relu), tf.keras.layers.Dense(10, activation=tf.nn.softmax) ]) # 4. 모델 컴파일 model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) # 5. 모델 훈련 model.fit(x_train, y_train, epochs=20) # 6. 정확도 평가 test_loss, test_acc = model.evaluate(x_test, y_test) print('테스트 정확도:', test_acc) ''' ''' import sys import tensorflow as tf from PyQt5.QtWidgets import * from PyQt5.QtGui import * from PyQt5.QtCore import * import numpy as np class MyApp(QMainWindow): def __init__(self): super().__init__() self.image = QImage(QSize(400, 400), QImage.Format_RGB32) self.image.fill(Qt.white) self.drawing = False self.brush_size = 30 self.brush_color = Qt.black self.last_point = QPoint() self.loaded_model = None self.initUI() def initUI(self): menubar = self.menuBar() menubar.setNativeMenuBar(False) filemenu = menubar.addMenu('File') load_model_action = QAction('Load model', self) load_model_action.setShortcut('Ctrl+L') load_model_action.triggered.connect(self.load_model) save_action = QAction('Save', self) save_action.setShortcut('Ctrl+S') save_action.triggered.connect(self.save) clear_action = QAction('Clear', self) clear_action.setShortcut('Ctrl+C') clear_action.triggered.connect(self.clear) filemenu.addAction(load_model_action) filemenu.addAction(save_action) filemenu.addAction(clear_action) self.statusbar = self.statusBar() self.setWindowTitle('MNIST Classifier') self.setGeometry(300, 300, 400, 400) self.show() def paintEvent(self, e): canvas = QPainter(self) canvas.drawImage(self.rect(), self.image, self.image.rect()) def mousePressEvent(self, e): if e.button() == Qt.LeftButton: self.drawing = True self.last_point = e.pos() def mouseMoveEvent(self, e): if (e.buttons() & Qt.LeftButton) & self.drawing: painter = QPainter(self.image) painter.setPen(QPen(self.brush_color, self.brush_size, Qt.SolidLine, Qt.RoundCap)) painter.drawLine(self.last_point, e.pos()) self.last_point = e.pos() self.update() def mouseReleaseEvent(self, e): if e.button() == Qt.LeftButton: self.drawing = False arr = np.zeros((28, 28)) for i in range(28): for j in range(28): arr[j, i] = 1 - self.image.scaled(28, 28).pixelColor(i, j).getRgb()[0] / 255.0 arr = arr.reshape(-1, 28, 28) if self.loaded_model: pred = self.loaded_model.predict(arr)[0] pred_num = str(np.argmax(pred)) self.statusbar.showMessage('숫자 ' + pred_num + '입니다.') def load_model(self): fname, _ = QFileDialog.getOpenFileName(self, 'Load Model', '') if fname: self.loaded_model = tf.keras.models.load_model(fname) self.statusbar.showMessage('Model loaded.') def save(self): fpath, _ = QFileDialog.getSaveFileName(self, 'Save Image', '', "PNG(*.png);;JPEG(*.jpg *.jpeg);;All Files(*.*) ") if fpath: self.image.scaled(28, 28).save(fpath) def clear(self): self.image.fill(Qt.white) self.update() self.statusbar.clearMessage() if __name__ == '__main__': app = QApplication(sys.argv) ex = MyApp() sys.exit(app.exec_()) ''' import tensorflow as tf from tensorflow import keras from tensorflow.keras import layers import matplotlib.pyplot as plt #from google.colab import auth #from google.colab import drive import cv2 import numpy as np #drive.mount('/content/gdrive/') # google drive address #import glob import os scr = os.listdir('./numbers/') ''' plt.title('The number I write') plt.imshow(myNum, cmap='gray') print(myNum.shape) ''' # data input mnist = tf.keras.datasets.mnist (x_train, y_train), (x_test, y_test) = mnist.load_data() x_train, x_test = x_train/255.0, x_test/255.0 print(x_train.shape, y_train.shape, x_test.shape, y_test.shape) # view Images ''' plt.figure(figsize=(10, 10)) c = 0 for x in range(2): for y in range(5): plt.subplot(2, 5, c+1) plt.imshow(x_train[c], cmap='gray') c+=1 plt.show() print(y_train[:10]) ''' # make a model model = tf.keras.models.Sequential([ tf.keras.layers.Flatten(input_shape=(28, 28)), tf.keras.layers.Dense(128, activation='relu'), tf.keras.layers.Dropout(0.2), tf.keras.layers.Dense(10, activation='softmax') ]) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) model.summary() model.fit(x_train, y_train, epochs=1) model.evaluate(x_test, y_test) # test my Image data #myNum = np.array(myNum) #v = model.predict(np.reshape(myNum, (1,28,28))) #print(v) #print(max(v[0])) sum = 0 dataVV = [] #for i in range(3): for i in range(len(scr)): #path = os.path.join('./number/'+str(scr[i])) src = cv2.imread('./numbers/'+str(scr[i]), cv2.IMREAD_GRAYSCALE) dataVV.append(src) for i in range(len(dataVV)): ret, binary = cv2.threshold(dataVV[i], 170, 255, cv2.THRESH_BINARY_INV) scr = np.asarray(cv2.resize(binary,dsize=(28, 28), interpolation=cv2.INTER_AREA))/255 myNum = np.array(scr) v = model.predict(np.reshape(myNum, (1, 28, 28))) s = list(v[0]).index(max(v[0])) print(s) sum += s print(sum) ''' ret , binary = cv2.threshold(src,170,255,cv2.THRESH_BINARY_INV) if (type(scr) == type(None)): pass else: scr = np.asarray(cv2.resize(binary,dsize=(28, 28), interpolation=cv2.INTER_AREA))/255 #vv = np.asarray(cv2.resize(binary, dsize=(28, 28), interpolation=cv2.INTER_AREA))/255 #dataVV.append() myNum = np.array(binary) v = model.predict(np.reshape(myNum, (1, 28, 28))) s = list(v[0]).index(max(v[0])) print(s) sum += s print('>',sum) ''' https://www.photopea.com/
0
0
4
kja090500
2021년 11월 14일
In 소스 코드 제출
#이미지 컬러있는 버전으로 나오는 거 ''' import cv2 import numpy as np img = cv2.imread('./images/meat.jpeg', cv2.IMREAD_GRAYSCALE) #hist,bins = np.histogram(img.ravel(),256,[0,256]) cv2.imshow('color', img) cv2.waitKey() cv2.destroyAllwindows() ''' #히스토그램 '''import cv2 from matplotlib import pyplot as plt img = cv2.imread('./images/meat.jpeg') color = ('b','g','r') for i,col in enumerate(color): histr = cv2.calcHist([img],[i],None,[256],[0,256]) plt.plot(histr,color = col) plt.xlim([0,256]) plt.show() ''' ''' import cv2 import numpy as np img = cv2.imread('./images/meat.jpeg') x=320; y=150; w=50; h=50 # roi 좌표 roi = img[y:y+h, x:x+w] # roi 지정 ---① print(roi.shape) # roi shape, (50,50,3) cv2.rectangle(roi, (0,0), (h-10, w+100), (0,0,255)) # roi 전체에 사각형 그리기 ---② cv2.imshow("img", img) key = cv2.waitKey(0) print(key) cv2.destroyAllWindows() ''' ''' import cv2 import numpy as np import matplotlib.pylab as plt # haarcascade 불러오기 face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml') eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_eye.xml') # 이미지 불러오기 img = cv2.imread('./images2/face2.jpg') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) img2 = cv2.imread('./images2/face2.jpg') # 얼굴 찾기 faces = face_cascade.detectMultiScale(gray, 1.3, 5) k = 0 loc = [] for (x, y, w, h) in faces: #face = cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2) loc.append([x, y]) #print(loc) # 눈 찾기 roi_color = img[y:y + h, x:x + w] # jooseok roi_gray = gray[y:y + h, x:x + w] if k==0: roi_first = gray[y:y + h, x:x + w] #print(roi_gray) cv2.imwrite('./images/result' + str(k) + '.jpg', roi_color) k += 1 for i in range(len(roi_first)): for j in range(len(roi_first[i])): img[i+y][j+x] = roi_first[i][j] # 얼굴부분을 한 사람 얼굴로 전부 바꾸기 eyes = eye_cascade.detectMultiScale(gray) for (ex, ey, ew, eh) in eyes: roi_color1 = img2[ey:ey+eh, ex:ex+ew] for l in range(len(roi_color1)): for t in range(len(roi_color1[l])): img[l+ey][t+ex] = roi_color1[l][t] #눈부분만 컬러로 (각얼굴에 맞게) #cv2.rectangle(roi_color, (ex, ey), (ex+ew, ey+eh), (0, 255, 0), 2) # 영상 출력 cv2.imshow('image', img) from matplotlib import pyplot as plt img = cv2.imread('./images2/face2.jpg',0) ''' ''' color = ('b','g','r') for i,col in enumerate(color): histr = cv2.calcHist([img],[i],None,[256],[0,256]) plt.plot(histr,color = col) plt.xlim([0,256]) plt.show() ''' ''' img2 = cv2.equalizeHist(img) img = cv2.resize(img,(400,400)) img2 = cv2.resize(img2,(400,400)) dst = np.hstack((img, img2)) cv2.imshow('img',dst) cv2.waitKey() cv2.destroyAllWindows() ''' ''' clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8)) img2 = clahe.apply(img) img = cv2.resize(img,(400,400)) img2 = cv2.resize(img2,(400,400)) dst = np.hstack((img, img2)) cv2.imshow('img',dst) #print(loc) key = cv2.waitKey(0) cv2.destroyAllWindows() import glob target_dir = './images/' files = glob.glob(target_dir+'*.*') #print(files) from PIL import Image def imgresize(files,x_size,y_size): file_list = [] for file in files: image = Image.open(file) resized_file = image.resize((x_size,y_size)) file_list.append(resized_file) thumb_sizeX = 100 thumb_sizeY = 100 file_list = imgresize(files, thumb_sizeX,thumb_sizeY) def imgMerge(file_list,sizeX,sizeY,numX): new_image = Image.new("RGB",(sizeX*numX,sizeY*(len(file_list)//numX+1)),(256,256,256)) count_X = 0 count_Y = 0 for index in range(len(file_list)): area = ((count_X*sizeX),count_Y*sizeY,(count_X+1)*sizeX,(count_Y+1)*sizeY) new_image.paste(file_list[index],area) if(index+1)%numX ==0: count_Y+=1 count_X =0 else: count_X +=1 new_image.show() new_image.save('./images2/face2','jpg') numX = 3 imgMerge(file_list,thumb_sizeX, thumb_sizeY, numX) ''' import tensorflow as tf ''' # 1. MNIST 데이터셋 임포트 mnist = tf.keras.datasets.mnist (x_train, y_train), (x_test, y_test) = mnist.load_data() # 2. 데이터 전처리 x_train, x_test = x_train/255.0, x_test/255.0 # 3. 모델 구성 model = tf.keras.models.Sequential([ tf.keras.layers.Flatten(input_shape=(28, 28)), tf.keras.layers.Dense(512, activation=tf.nn.relu), tf.keras.layers.Dense(10, activation=tf.nn.softmax) ]) # 4. 모델 컴파일 model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) # 5. 모델 훈련 model.fit(x_train, y_train, epochs=20) # 6. 정확도 평가 test_loss, test_acc = model.evaluate(x_test, y_test) print('테스트 정확도:', test_acc) ''' import sys import tensorflow as tf from PyQt5.QtWidgets import * from PyQt5.QtGui import * from PyQt5.QtCore import * import numpy as np class MyApp(QMainWindow): def __init__(self): super().__init__() self.image = QImage(QSize(400, 400), QImage.Format_RGB32) self.image.fill(Qt.white) self.drawing = False self.brush_size = 30 self.brush_color = Qt.black self.last_point = QPoint() self.loaded_model = None self.initUI() def initUI(self): menubar = self.menuBar() menubar.setNativeMenuBar(False) filemenu = menubar.addMenu('File') load_model_action = QAction('Load model', self) load_model_action.setShortcut('Ctrl+L') load_model_action.triggered.connect(self.load_model) save_action = QAction('Save', self) save_action.setShortcut('Ctrl+S') save_action.triggered.connect(self.save) clear_action = QAction('Clear', self) clear_action.setShortcut('Ctrl+C') clear_action.triggered.connect(self.clear) filemenu.addAction(load_model_action) filemenu.addAction(save_action) filemenu.addAction(clear_action) self.statusbar = self.statusBar() self.setWindowTitle('MNIST Classifier') self.setGeometry(300, 300, 400, 400) self.show() def paintEvent(self, e): canvas = QPainter(self) canvas.drawImage(self.rect(), self.image, self.image.rect()) def mousePressEvent(self, e): if e.button() == Qt.LeftButton: self.drawing = True self.last_point = e.pos() def mouseMoveEvent(self, e): if (e.buttons() & Qt.LeftButton) & self.drawing: painter = QPainter(self.image) painter.setPen(QPen(self.brush_color, self.brush_size, Qt.SolidLine, Qt.RoundCap)) painter.drawLine(self.last_point, e.pos()) self.last_point = e.pos() self.update() def mouseReleaseEvent(self, e): if e.button() == Qt.LeftButton: self.drawing = False arr = np.zeros((28, 28)) for i in range(28): for j in range(28): arr[j, i] = 1 - self.image.scaled(28, 28).pixelColor(i, j).getRgb()[0] / 255.0 arr = arr.reshape(-1, 28, 28) if self.loaded_model: pred = self.loaded_model.predict(arr)[0] pred_num = str(np.argmax(pred)) self.statusbar.showMessage('숫자 ' + pred_num + '입니다.') def load_model(self): fname, _ = QFileDialog.getOpenFileName(self, 'Load Model', '') if fname: self.loaded_model = tf.keras.models.load_model(fname) self.statusbar.showMessage('Model loaded.') def save(self): fpath, _ = QFileDialog.getSaveFileName(self, 'Save Image', '', "PNG(*.png);;JPEG(*.jpg *.jpeg);;All Files(*.*) ") if fpath: self.image.scaled(28, 28).save(fpath) def clear(self): self.image.fill(Qt.white) self.update() self.statusbar.clearMessage() if __name__ == '__main__': app = QApplication(sys.argv) ex = MyApp() sys.exit(app.exec_())
0
0
21
kja090500
2021년 11월 09일
In 소스 코드 제출
#이미지 컬러있는 버전으로 나오는 거 ''' import cv2 import numpy as np img = cv2.imread('./images/meat.jpeg', cv2.IMREAD_GRAYSCALE) #hist,bins = np.histogram(img.ravel(),256,[0,256]) cv2.imshow('color', img) cv2.waitKey() cv2.destroyAllwindows() ''' #히스토그램 '''import cv2 from matplotlib import pyplot as plt img = cv2.imread('./images/meat.jpeg') color = ('b','g','r') for i,col in enumerate(color): histr = cv2.calcHist([img],[i],None,[256],[0,256]) plt.plot(histr,color = col) plt.xlim([0,256]) plt.show() ''' ''' import cv2 import numpy as np img = cv2.imread('./images/meat.jpeg') x=320; y=150; w=50; h=50 # roi 좌표 roi = img[y:y+h, x:x+w] # roi 지정 ---① print(roi.shape) # roi shape, (50,50,3) cv2.rectangle(roi, (0,0), (h-10, w+100), (0,0,255)) # roi 전체에 사각형 그리기 ---② cv2.imshow("img", img) key = cv2.waitKey(0) print(key) cv2.destroyAllWindows() ''' ''' import cv2 import numpy as np import matplotlib.pylab as plt # haarcascade 불러오기 face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml') eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_eye.xml') # 이미지 불러오기 img = cv2.imread('./images/face2.jpg') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # 얼굴 찾기 faces = face_cascade.detectMultiScale(gray, 1.3, 5) k = 0 for (x, y, w, h) in faces: face = cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2) # 눈 찾기 roi_color = img[y:y + h, x:x + w] # jooseok roi_gray = gray[y:y + h, x:x + w] cv2.imwrite('./images/result' + str(k) + '.jpg', roi_color) k += 1 eyes = eye_cascade.detectMultiScale(roi_gray) for (ex, ey, ew, eh) in eyes: cv2.rectangle(roi_color, (ex, ey), (ex+ew, ey+eh), (0, 255, 0), 2) # 영상 출력 cv2.imshow('image', img) key = cv2.waitKey(0) cv2.destroyAllWindows() ''' from PIL import Image import numpy as np for i in range(0,9): orig = Image.open('./images/result' + str(i) + '.jpg') orig_px = orig.getdata() orig_px = np.reshape(orig_px, (orig.height * orig.width, 3)) np.random.shuffle(orig_px) orig_px = np.reshape(orig_px, (orig.height, orig.width, 3)) res = Image.fromarray(orig_px.astype('uint8')) res.save('out.jpg')
0
1
4
kja090500
2021년 10월 05일
In 소스 코드 제출
//////////////////#include <iostream> ////////////////// //////////////////using namespace std; ////////////////// //////////////////int main() //////////////////{ ////////////////// cout << "Hello world!" << endl; ////////////////// return 0; //////////////////} //////////////// ////////////////#include <iostream> ////////////////using namespace std; ////////////////class Point{ ////////////////int x,y; ////////////////public: //////////////// void sett(int x,int y) { this->x=x; this->y=y; } //////////////// void show() { cout << "(" << x << ',' << y << ")" << endl; } ////////////////}; ////////////////class ColorPoint : public Point ////////////////{ //////////////// string color; ////////////////public: //////////////// void setc(string color) { this->color=color; } //////////////// void show1(); ////////////////}; ////////////////void ColorPoint::show1() { ////////////////cout << color << ": "; ////////////////show(); ////////////////} ////////////////int main() ////////////////{ //////////////// Point o; //////////////// ColorPoint cp; //////////////// cp.sett(3,4); //////////////// cp.setc("red"); //////////////// cp.show1(); ////////////////} ////////////// //////////////#include <iostream> //////////////using namespace std; //////////////class Point{ //////////////protected: //////////////int x,y; ////////////// //////////////public: ////////////// ////////////// void sett(int x,int y) { this->x=x; this->y=y; } ////////////// void show() { cout << "(" << x << ',' << y << ")" << endl; } //////////////}; //////////////class Cpoint : public Point { //////////////string color; //////////////public: ////////////// void setc(string color) { this->color=color; } ////////////// void show1(); ////////////// bool equals(Cpoint p); //////////////}; //////////////void Cpoint::show1() //////////////{ ////////////// cout << color << " : "; ////////////// show(); //////////////} //////////////bool Cpoint::equals(Cpoint p) //////////////{ ////////////// if(x==p.x && y == p.y && color == p.color) ////////////// return true; ////////////// else return false; //////////////} //////////////int main() //////////////{ ////////////// Point p; ////////////// p.sett(2,3); ////////////// p.x = 5; ////////////// p.y = 5; ////////////// p.show(); ////////////// ////////////// Cpoint cp; ////////////// cp.x = 10; ////////////// cp.y = 10; ////////////// cp.sett(3,4); ////////////// cp.setc("red"); ////////////// ////////////// Cpoint cp2; ////////////// cp2.sett(3,4); ////////////// cp2.setc("red"); ////////////// cout << ((cp.equals(cp2))?"true":"false"); //////////////} //////////// ////////////#include <iostream> ////////////#include <string> ////////////using namespace std; ////////////class TV{ ////////////int size; ////////////public: //////////// TV() { size = 20; } //////////// TV(int size) { this->size=size; } //////////// int getsize() { return size; } ////////////}; ////////////class wideTV : public TV{ ////////////bool videoIn; ////////////public: //////////// wideTV(int size, bool videoIn) : TV(size) //////////// { //////////// this->videoIn=videoIn; //////////// }-+ //////////// //////////// bool getVideoin() { return videoIn; } ////////////}; ////////////class SmartTV : public wideTV{ ////////////string ipaddr; ////////////public: //////////// SmartTV(string ipaddr,int size) : wideTV(size,true) //////////// { //////////// this->ipaddr = ipaddr; //////////// } //////////// string getip() { return ipaddr; } ////////////}; ////////////int main() ////////////{ //////////// SmartTV htv("192.0.01",32); //////////// cout << "size= " << htv.getsize() << endl; //////////// cout << "videoIn= " << boolalpha <<htv.getVideoin() << endl; //////////// cout << "IP= " << htv.getip() << endl; ////////////} ////////// //////////#include <iostream> //////////using namespace std; //////////class A{ ////////// //////////public: ////////// int x; ////////// A() { x = 0;} ////////// A(int x) { this->x=x; } //////////}; //////////class B : public A{ //////////public: ////////// int y; ////////// B(int x,int y) : A(x+5) { this->y=y; } ////////// void show1() { cout << x << ' ' << y << endl; } //////////}; //////////class C : public B{ ////////// //////////public: ////////// int m; ////////// C(int x,int y,int z) : B(x,y+100) { m = x*y*z; } ////////// void show() { cout << x << ' ' << y << ' ' << m << endl; } //////////}; //////////int main() //////////{ ////////// C c(3,5,2); ////////// B b(3,4); ////////// b.show1(); ////////// c.show(); //////////} //////// ////////#include <iostream> ////////using namespace std; ////////class Base ////////{ ////////protected: //////// void setA(int a) //////// { //////// this->a=a; //////// } ////////public: //////// int a; //////// void showB() //////// { //////// cout << a; //////// } ////////}; ////////class D : public Base ////////{ ////////protected: //////// void setB(int b) //////// { //////// this->b=b; //////// } ////////public: //////// int b; //////// void showA() //////// { //////// cout << b; //////// } ////////}; ////////int main() ////////{ //////// D x; //////// x.a = 5; //////// x.setA(10); //////// x.showB(); //////// x.b = 10; //////// x.setB(10); //////// x.showA(); ////////} //////// //////////////////////////////////////식 입력하면 답나오는거(이항 연산) //////#include <iostream> //////using namespace std; //////class Adder{ //////protected: ////// int add(int a,int b) { return a+b; } //////}; //////class Sub{ //////protected: ////// int minus(int a,int b) { return a-b; } //////}; //////class Calcul : public Adder, public Sub{ //////public: ////// int calc(char op, int a, int b); //////}; //////int Calcul::calc(char op, int a, int b) //////{ ////// int res=0; ////// switch(op) { ////// case '+' : res = add(a,b); break; ////// case '-' : res = minus(a,b); break; ////// } ////// return res; //////} //////int main() //////{ ////// Calcul hand; ////// int num1=0,num2=0; ////// char hangul=' '; ////// cin >> num1 >> hangul >> num2; ////// cout << num1 << hangul << num2 << '=' << hand.calc('+',2,4) << endl; ////// //cout << "100 - 8 = " << hand.calc('-',100,8) << endl; //////} ///////////////////////////////////////////1번 ////#include <iostream> ////using namespace std; ////class Circle{ //// ////public: //// int radius=0; //// Circle(int radius=0) { this->radius=radius;} //// int getR() { return radius; } //// void setR(int radius) { this->radius=radius; } //// double getA() { return 3.14*radius*radius; } //// void show1() { cout << "반지름이 " << radius << "인 "; } ////}; ////class NameC : public Circle{ ////string name=" "; ////public: //// NameC(int radius,string name) { this->radius=radius; this->name=name; } //// void show() //// { //// show1(); //// cout << name << endl; //// } ////}; ////int main() ////{ //// NameC waffle(3,"waffle"); //// waffle.show(); ////} //// //#include <iostream> //using namespace std; //class Circle{ //int radius=0; //public: // // Circle(int radius=0) { this->radius=radius;} // int getR() { return radius; } // void setR(int radius) { this->radius=radius; } // double getA() { return 3.14*radius*radius; } //}; //class namedC : public Circle{ // //}; //int main() //{ // int pizza[5]; // for(int i=0;i<5;i++) // { // cin >> pizza[i]; // } //} #include <iostream> using namespace std; int main() { int pizza; string name; cout << "5개의 정수 반지름과 원의 이름을 입력하세요" << endl; for(int i=1;i<=5;i++) { cout << i << ">> "; cin >> pizza >> name; } }
0
0
2
kja090500
2021년 10월 03일
In 소스 코드 제출
//////#include <iostream> ////// //////using namespace std; ////// //////int main() //////{ ////// cout << "Hello world!" << endl; ////// return 0; //////} ///////////////////////////////////////////////////////////////////7 ////#include <iostream> //// ////using namespace std; //// ////class Matrix{ //// ////int a1,a2,a3,a4; //// ////public: //// //// Matrix(int a1=0,int a2=0,int a3=0,int a4=0) //// { //// this->a1=a1; this->a2=a2; this->a3=a3; this->a4=a4; //// } //// //// void show(); //// //// friend Matrix& operator>>(Matrix& op, int* y); //// friend Matrix& operator<<(Matrix& op, int* x); ////}; //// ////void Matrix::show() ////{ //// //// cout << "Matrix= { " << a1 << ' ' << a2 << ' ' << a3 << ' ' << a4 << ' ' << "}" << endl; //// ////} //// ////Matrix& operator>>(Matrix& op, int* y) ////{ //// y[0]=op.a1; //// y[1]=op.a2; //// //// y[2]=op.a3; //// //// y[3]=op.a4; //// //// return op; //// ////} //// ////Matrix& operator<<(Matrix& op,int* x) ////{ //// op.a1 = x[0]; //// op.a2=x[1]; //// op.a3=x[2]; //// op.a4=x[3]; //// //// return op; ////} //// ////int main() //// ////{ //// //// Matrix a(4,3,2,1),b; //// //// int x[4],y[4] = {1,2,3,4}; //// //// a >> x; //// //// b << y; //// //// //// for(int i=0;i<4; i++) //// //// { //// //// cout << x[i] << ' '; //// //// } //// //// cout << endl; //// //// b.show(); //// ////} //// ///* //#include <iostream> //using namespace std; //class Circle //{ // //public: // int radius; // // Circle(int radius=0) // { // this->radius=radius; // } // // void show() // { // cout << "radius= " << radius << "인 원 " << endl; // } // // friend Circle operator+(int n, Circle a); //}; //Circle operator+(int n, Circle a) //{ // Circle c; // c.radius=n+a.radius; // return c; //} //int main() //{ // Circle a(5),b(4); // b = 1 + a; // a.show(); // b.show(); //} //*/ // //#include<iostream> // //class person { //public: // person() { // // } // person(int p) { // // } // char name; // float height, weight, eye; // void talk() {} // void eat() {} // void sleep() {} //}; // //class student : public person { // student() { // // } // student(int k) { // // } // int korean, eng, studntNumber; // // void study() {} //}; // //int main() { // student s(10); // s.st // //} // #include <iostream> #include <string> using namespace std; class point{ int x,y; public: void set(int x,int y) { this->x=x; this->y=y; } void show() { cout << "(" << x << "," << y << ")"<< endl; } }; class Colorprint: public point{ public: void settcol(string color) };
0
0
2
kja090500
2021년 9월 28일
In 소스 코드 제출
//////////#include <iostream> ////////// //////////using namespace std; ////////// //////////int main() //////////{ ////////// cout << "Hello world!" << endl; ////////// return 0; //////////} //////// //////// //////// ////////#include <iostream> ////////using namespace std; ////////class Power{ ////////int kick; ////////int punch; ////////public: //////// Power(int kick=0,int punch=0) { this->kick=kick; this->punch=punch; } //////// void show(); //////// friend Power& operator++(Power& op); //////// friend Power operator++(Power& op,int x); ////////}; ////////void Power::show() ////////{ //////// cout << "kick= " << kick << ',' << "punch= " << punch << endl; ////////} ////////Power& operator++(Power& op) ////////{ //////// op.kick++; //////// op.punch++; //////// return op; ////////} ////////Power operator++(Power& op,int x) ////////{ //////// Power tmp = op; //////// op.kick++; //////// op.punch++; //////// return tmp; ////////} ////////int main() ////////{ //////// Power a(3,5),b; //////// b = ++a; //////// a.show(); b.show(); //////// //////// b= a++; //////// a.show(); b.show(); ////////} ////// ////// //////#include <iostream> //////using namespace std; //////class Power{ //////int kick; //////int punch; //////public: ////// Power(int kick,int punch) { this->kick=kick; this->punch=punch; } ////// void show(); ////// Power& operator<<(int n); //////}; //////void Power::show() //////{ ////// cout << "kick= " << kick << ',' << "punch= " << punch << endl; //////} //////Power& Power::operator<<(int n) //////{ ////// kick+=n; ////// punch+=n; ////// return *this; //////} //////int main() //////{ ////// Power a(1,2); ////// a << 3 << 5 << 6; ////// a.show(); //////} //////////////////////////////////////////////////1 ////#include <iostream> ////using namespace std; ////class Book{ ////string title; ////int price,pages; ////public: //// Book(string title="",int price=0, int pages=0) //// { //// this->title=title; this->price=price; this->pages=pages; //// } //// void show() //// { //// cout << title << ' ' << price << "원 " << pages << " 페이지 " << endl; //// } //// string gettitle() { return title; } //// Book& operator+=(int price1); //// Book& operator-=(int price2); ////}; ////Book& Book::operator+=(int price1) ////{ //// price+=price1; //// return *this; ////} ////Book& Book::operator-=(int price2) ////{ //// price-=price2; //// return *this; ////} ////int main() ////{ //// Book a("청춘",20000,300), b("미래",30000,500); //// a+=500; //// b-=500; //// a.show(); //// b.show(); ////} /////////////////////////////////////////////////3 //#include <iostream> //using namespace std; //class book{ //string title; // //public: // int pages,price; // book(string title="",int pages=0,int price=0) // { // this->title=title; this->pages=pages; this->price=price; // } // void show() // { // cout << title << ' ' << price << "원 " << pages << " 페이지 " << endl; // } // string gettitle() { return title; } //// friend book operator!(s); // //}; // //bool operator!(book &op) { // cout << &op << endl; // if(op.price==0) // return true; // else // return false; //} // //int main() //{ // book Book("벼룩시장",0,50); // cout << &Book << endl; // if(!Book) cout << "공짜다 " << endl; //} /////////////////////////////////////////////////////////5 //#include <iostream> //using namespace std; //class color{ //int r,g,b; //public: // color(int r=0, int g=0, int b=0 ) { this->r=r; this->g=g; this->b=b; } // void show() { cout << r << ' ' << g << ' ' << b << endl; } // color operator+(color op2); // bool operator==(color &op); //}; //color color::operator+(color op2) //{ // color tmp; // tmp.r=this->r+op2.r; // tmp.b=this->b+op2.b; // tmp.g=this->g+op2.g; // return tmp; //} //bool color::operator==(color &op) //{ // if(r==op.r&&g==op.g&&b==op.b) // return true; // else false; //} //int main() //{ // color red(255,0,0), blue(0,0,255),c; // c= red+ blue; // c.show(); // color fuchsia(255,0,255); // if(c==fuchsia) // cout << "보라색 맞음"; // else // cout << "보라색 아님"; //} #include <iostream> using namespace std; class Matrix{ int a1,a2,a3,a4; public: Matrix(int a1=0,int a2=0,int a3=0,int a4=0) { this->a1=a1; this->a2=a2; this->a3=a3; this->a4=a4; } void show(); Matrix& operator<<(Matrix &op,int x1); Matrix& operator>>(Matrix &op,int y1); }; void Matrix::show() { cout << "Matrix= { " << a1 << ' ' << a2 << ' ' << a3 << ' ' << a4 << ' ' << "}" << endl; } Matrix& Matrix::operator<<(Matrix &op,int x1) { x1[0]==op.a1; x1[1]==op.a2; x1[2]==op.a3; x1[3]==op.a4; return *this; } Matrix& Matrix::operator>>(Matrix &op,int y1) { op.a1=y1[0]; op.a2=y1[1]; op.a3=y1[2]; op.a4=y1[3]; return *this; } int main() { Matrix a(4,3,2,1),b; int x[4],y[4] = {1,2,3,4}; a >> x; b << y; for(int i=0;i<4; i++) { cout << x[i] << ' '; } cout << endl; b.show(); }
0
0
3
kja090500
2021년 9월 14일
In 소스 코드 제출
//////////////////////////////#include <iostream> ////////////////////////////// //////////////////////////////using namespace std; ////////////////////////////// //////////////////////////////int main() //////////////////////////////{ ////////////////////////////// cout << "Hello world!" << endl; ////////////////////////////// return 0; //////////////////////////////} //////////////////////////// ////////////////////////////#include <iostream> ////////////////////////////using namespace std; ////////////////////////////class RECT; ////////////////////////////bool equals(RECT r,RECT s); ////////////////////////////class RECT{ ////////////////////////////int width, height; ////////////////////////////public: //////////////////////////// RECT(int width,int height) //////////////////////////// { //////////////////////////// this-> width =width; //////////////////////////// this-> height = height; //////////////////////////// } //////////////////////////// friend bool equals(RECT r,RECT s); ////////////////////////////}; ////////////////////////////bool equals(RECT r,RECT s) ////////////////////////////{ //////////////////////////// if(r.width==s.width&&r.height==s.height) //////////////////////////// { //////////////////////////// return true; //////////////////////////// } //////////////////////////// else return false; ////////////////////////////} ////////////////////////////int main() ////////////////////////////{ //////////////////////////// RECT a(3,4),b(4,5); //////////////////////////// if(equals(a,b)) cout << "equal" << endl; //////////////////////////// else cout << "not equal" << endl; ////////////////////////////} ////////////////////////// ////////////////////////// //////////////////////////#include <iostream> //////////////////////////using namespace std; //////////////////////////class RECT; //////////////////////////class RECTM //////////////////////////{ //////////////////////////public: ////////////////////////// bool equals(RECT r,RECT s); //////////////////////////}; //////////////////////////class RECT{ //////////////////////////int width, height; //////////////////////////public: ////////////////////////// RECT(int width,int height) { this->width=width; this->height=height;} ////////////////////////// friend bool RECTM::equals(RECT r,RECT s); //////////////////////////}; //////////////////////////bool RECTM::equals(RECT r,RECT s) //////////////////////////{ ////////////////////////// if(r.width==s.width&&r.height==s.height) ////////////////////////// { ////////////////////////// return true; ////////////////////////// } ////////////////////////// else return false; //////////////////////////} //////////////////////////int main() //////////////////////////{ ////////////////////////// RECT a(3,4), b(3,4); ////////////////////////// RECTM man; ////////////////////////// ////////////////////////// if(man.equals(a,b)) cout << "equal" << endl; ////////////////////////// else cout << "not equal" << endl; //////////////////////////} //////////////////////// //////////////////////// ////////////////////////#include <iostream> ////////////////////////using namespace std; ////////////////////////class RECT; ////////////////////////class RECTM{ ////////////////////////public: //////////////////////// bool equals(RECT r,RECT s); //////////////////////// void copy(RECT& dest,RECT& src); ////////////////////////}; ////////////////////////class RECT{ ////////////////////////int width,height; ////////////////////////public: //////////////////////// RECT(int width,int height) { this->width=width; this->height=height;} //////////////////////// friend RECTM; ////////////////////////}; ////////////////////////bool RECTM::equals(RECT r,RECT s) ////////////////////////{ //////////////////////// if(r.width==s.width&&r.height==s.height) //////////////////////// { //////////////////////// return true; //////////////////////// } //////////////////////// else return false; //////////////////////// ////////////////////////} ////////////////////////void RECTM::copy(RECT& dest,RECT& src) ////////////////////////{ //////////////////////// dest.width = src.width; dest.height = src.height; ////////////////////////} ////////////////////////int main() ////////////////////////{ //////////////////////// RECT a(3,4),b(3,4); //////////////////////// RECTM man; //////////////////////// man.copy(b,a); //////////////////////// if(man.equals(a,b)) cout << "equal" << endl; //////////////////////// else cout << "not equal" << endl; ////////////////////////} //////////////////////// ////////////////////// //////////////////////#include <iostream> //////////////////////using namespace std; //////////////////////class Power{ //////////////////////int kick; //////////////////////int punch; //////////////////////public: ////////////////////// Power(int kick=0,int punch=0) { this-> kick=kick; this->punch=punch;} ////////////////////// void show(); ////////////////////// Power operator+ (Power op2); ////////////////////// //////////////////////}; //////////////////////void Power::show() //////////////////////{ ////////////////////// cout << "kick= " << kick << ',' << "punch= " << punch << endl; //////////////////////} //////////////////////Power Power::operator+(Power op2) //////////////////////{ ////////////////////// Power tmp; ////////////////////// tmp.kick = this->kick+op2.kick; ////////////////////// tmp.punch = this->punch+op2.punch; ////////////////////// return tmp; //////////////////////} //////////////////////int main() //////////////////////{ ////////////////////// Power a(3,5),b(4,6),c; ////////////////////// c = a+b; ////////////////////// a.show(); ////////////////////// b.show(); ////////////////////// c.show(); //////////////////////} //////////////////// ////////////////////#include <iostream> ////////////////////using namespace std; ////////////////////class Power{ ////////////////////int kick; ////////////////////int punch; ////////////////////public: //////////////////// Power(int kick=0,int punch=0) { this->kick=kick; this->punch=punch;} //////////////////// void show(); //////////////////// bool operator== (Power op2); ////////////////////}; ////////////////////void Power::show() ////////////////////{ //////////////////// cout << "kick= " << kick << ',' << "punch= " << punch << endl; ////////////////////} ////////////////////bool Power::operator==(Power op2) ////////////////////{ //////////////////// if(kick==op2.kick&&punch==op2.punch) return true; //////////////////// else return false; ////////////////////} ////////////////////int main() ////////////////////{ //////////////////// Power a(3,5),b(3,5); //////////////////// a.show(); //////////////////// b.show(); //////////////////// if(a == b) cout << "파워가 같다 " << endl; //////////////////// else cout << "파워가 다르다 " << endl; ////////////////////} //////////////////// //////////////////#include <iostream> //////////////////using namespace std; //////////////////class Power{ //////////////////int kick; //////////////////int punch; //////////////////public: ////////////////// Power(int kick=0,int punch=0) { this->kick=kick; this->punch=punch; } ////////////////// void show(); ////////////////// Power& operator+= (Power op2); //////////////////}; //////////////////void Power::show() //////////////////{ ////////////////// cout << "kick= " <<kick << ',' << "punch= " << punch << endl; //////////////////} //////////////////Power& Power::operator+=(Power op2) //////////////////{ ////////////////// kick= kick + op2.kick; ////////////////// punch = punch +op2.punch; ////////////////// return *this; //////////////////} //////////////////int main() //////////////////{ ////////////////// Power a(3,5),b(4,6),c; ////////////////// a.show(); ////////////////// b.show(); ////////////////// c=a+=b; ////////////////// a.show(); ////////////////// c.show(); //////////////////} //////////////// //////////////// //////////////////#include <iostream> //////////////////using namespace std; //////////////////class Power{ //////////////////int kick; //////////////////int punch; //////////////////public: ////////////////// Power(int kick=0,int punch=0) { this-> kick=kick; this->punch=punch; } ////////////////// void show(); ////////////////// Power operator+ (int op2); //////////////////}; //////////////////void Power::show() //////////////////{ ////////////////// cout << "kick= " << kick << ',' << "punch= " << punch << endl; //////////////////} //////////////////Power Power::operator+(int op2) //////////////////{ ////////////////// Power tmp; ////////////////// tmp.kick = kick+op2; ////////////////// tmp.punch = punch+op2; ////////////////// return tmp; //////////////////} //////////////////int main() //////////////////{ ////////////////// Power a(3,5),b; ////////////////// a.show(); ////////////////// b.show(); ////////////////// b= a+2; ////////////////// a.show(); ////////////////// b.show(); //////////////////} //////////////// //////////////// ////////////////#include <iostream> ////////////////using namespace std; ////////////////class Power{ ////////////////int kick; ////////////////int punch; ////////////////public: //////////////// Power(int kick=0,int punch=0) { this->kick=kick; this->punch=punch; } //////////////// void show(); //////////////// Power& operator++ (); ////////////////}; ////////////////void Power::show() ////////////////{ //////////////// cout << "kick= " << kick << ',' << "punch= " << punch << endl; ////////////////} ////////////////Power& Power::operator++() ////////////////{ //////////////// kick++; //////////////// punch++; //////////////// return *this; ////////////////} ////////////////int main() ////////////////{ //////////////// Power a(3,5),b; //////////////// a.show(); //////////////// b.show(); //////////////// b = ++a; //////////////// a.show(); //////////////// b.show(); ////////////////} //////////////// //////////////// ////////////// //////////////#include <iostream> //////////////using namespace std; //////////////class Power{ //////////////int kick; //////////////int punch; //////////////public: ////////////// Power(int kick=0,int punch=0) { this->kick=kick; this->punch=punch; } ////////////// void show(); ////////////// bool operator! (); //////////////}; //////////////void Power::show() //////////////{ ////////////// cout << "kick= " << kick << ',' << "punch= " << punch << endl; //////////////} //////////////bool Power::operator!() //////////////{ ////////////// if(kick==0&&punch==0) return true; ////////////// else return false; //////////////} //////////////int main() //////////////{ ////////////// Power a(0,0),b(5,5); ////////////// if(!a) cout << "a의 파워는 0" << endl; ////////////// else cout << "a의 파워는 0이 아님 " << endl; ////////////// if(!b) cout << "b의 파워는 0" << endl; ////////////// else cout << "b의 파워는 0이 아님 " << endl; //////////////} //////////// ////////////#include <iostream> ////////////using namespace std; ////////////class Power{ //////////// int kick; //////////// int punch; ////////////public: //////////// Power(int kick=0,int punch=0) { this->kick=kick; this->punch=punch;} //////////// void show(); //////////// Power operator++ (int x); ////////////}; ////////////void Power::show() ////////////{ //////////// cout << "kick= " << kick << ',' << "punch= " << punch << endl; ////////////} ////////////Power Power::operator++(int x) ////////////{ //////////// Power tmp = *this; //////////// kick++; //////////// punch++; //////////// return tmp; ////////////} ////////////int main() ////////////{ //////////// Power a(3,5),b; //////////// a.show(); //////////// b.show(); //////////// b = a++; //////////// a.show(); //////////// b.show(); ////////////} ////////// //////////#include<iostream> ////////// //////////class Power { ////////// int a, b; //////////public: ////////// Power(int x=0, int y=0) { ////////// a = x; ////////// b = y; ////////// } ////////// friend int operator+(Power a, Power b); //////////}; ////////// //////////int operator+(Power a, Power b) { ////////// return a*b; //////////} ////////// //////////int main() { ////////// Power a(10, 20), b(5, 15), c; ////////// //////////} //////// ////////#include <iostream> ////////using namespace std; ////////class Power{ ////////int kick; ////////int punch; ////////public: //////// Power(int kick=0,int punch=0) { this->kick=kick; this->punch=punch; } //////// void show(); //////// friend Power operator+ (int op1,Power op2); ////////}; ////////void Power::show() ////////{ //////// cout << "kick= " << kick << ',' << "punch= " << punch << endl; ////////} ////////Power operator+(int op1,Power op2) ////////{ //////// Power tmp; //////// tmp.kick=op1+op2.kick; //////// tmp.punch=op1+op2.punch; //////// return tmp; ////////} ////////int main() ////////{ //////// Power a(3,5),b; //////// a.show(); //////// b.show(); //////// b = 2+a; //////// a.show(); //////// b.show(); ////////} ////// ////// //////#include <iostream> //////using namespace std; //////class Power{ //////int kick; //////int punch; //////public: ////// Power(int kick=0, int punch=0) { this->kick=kick; this->punch=punch; } ////// void show(); ////// friend Power operator+(Power op1,Power op2); //////}; //////void Power::show() //////{ ////// cout << "kick= " << kick << ',' << "punch= " << punch << endl; //////} //////Power operator+(Power op1,Power op2) //////{ ////// Power tmp; ////// tmp.kick =op1.kick+op2.kick; ////// tmp.punch = op1.punch+op2.punch; ////// return tmp; //////} //////int main() //////{ ////// Power a(3,5),b(4,6),c; ////// c = a+b; ////// a.show(); ////// b.show(); ////// c.show(); //////} //// ////#include <iostream> ////using namespace std; ////class Power{ ////int kick; ////int punch; ////public: //// Power(int kick=0,int punch=0) { this->kick= kick; this->punch=punch; } //// void show(); //// friend Power& operator++(Power& op); //// friend Power operator++(Power& op,int x); ////}; ////void Power::show() ////{ //// cout << "kick= " << kick << ',' << "punch= " << punch << endl; ////} ////Power& operator++(Power& op) ////{ //// op.kick++; //// op.punch++; //// return op; ////} ////Power operator++(Power& op,int x) ////{ //// Power tmp= op; //// op.kick++; //// op.punch++; //// return tmp; ////} ////int main() ////{ //// Power a(3,5),b; //// b= ++a; //// a.show(); //// b.show(); //// //// b= a++; //// a.show(); //// b.show(); //// ////} // //#include <iostream> //using namespace std; //class Power{ //int kick; //int punch; //public: // Power(int kick=0,int punch=0) { this->kick=kick; this->punch=punch; } // void show(); // Power& operator << (int n); //}; //void Power::show() //{ // cout <<"kick= " << kick << ',' << "punch= " << punch << endl; //} //Power& Power::operator<<(int n) //{ // kick += n; // punch += n; // return *this; //} //int main() //{ // int m; // // Power a(1,2); // for(int i=0;i<3;i++) // { // cin >> m; // a << m; // } // // a.show(); //} #include <iostream> using namespace std; class Book{ string title; int price,pages; public: book(string title="",int price=0, int pages=0) {this->title=title; this->pages=pages; this->price=price; } void show() { cout << title << ' ' << price << "원 " << pages << "페이지 " << endl; } string getTitle() { return title; } }; int main() { Book a("명품 C++",30000,500),b("고품 C++",30000,500); if(a==30000) cout << }
0
0
1
kja090500
2021년 9월 12일
In 소스 코드 제출
////////////#include <iostream> //////////// ////////////using namespace std; //////////// ////////////int main() ////////////{ //////////// cout << "Hello world!" << endl; //////////// return 0; ////////////} //////////// ////////////#include <iostream> ////////////#include <string> ////////////using namespace std; ////////////void star(int a=5); ////////////void msg(int id=10, 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(); //////////// 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); //////////} //////// ////////#include <iostream> ////////using namespace std; ////////void fillline(int n=25,char c='*'); //////// ////////void fillline(int n,char c) ////////{ //////// for(int i=0;i<n;i++) //////// cout << c; //////// cout << endl; ////////} ////////int main() ////////{ //////// fillline(); //////// fillline(10,'%'); ////////} ////// //////#include <iostream> //////using namespace std; //////class MV{ //////int *p; //////int size; //////public: ////// MV(int n=100) ////// { ////// p = new int [n]; ////// size = n; ////// cout << size << endl; ////// } ////// ~MV() { delete [] p; } //////}; //////int main() //////{ ////// MV *v1,*v2; ////// v1= new MV(); ////// v2 = new MV(1024); ////// ////// delete v1; ////// delete v2; //////} //// ////#include <iostream> ////using namespace std; ////class Math{ ////public: //// static int abs(int a) { return a>0?a:-a; } //// static int max(int a,int b) { return a>b?a:b; } //// static int min(int a,int b) { return a<b?a:b; } //// ////}; ////int main() ////{ //// cout << Math::abs(-5) << endl; //// cout << Math::max(10,8) << endl; //// cout << Math::min(-3,-8) << endl; ////} // //#include <iostream> //using namespace std; //class C{ //private: // static int numofC; // int radius; //public: // C(int r=1); // ~C() { numofC--;} // double getArea() { return 3.14*radius*radius; } // static int gett() { return numofC; } //}; //C::C(int r) //{ // radius = r; // numofC++; //} //int C::numofC = 0; //int main() //{ // C *p = new C[10]; // cout << "생존하고 있는 원의 개수 " << C::gett() << endl; // // delete [] p; // cout << "생존하고 있는 원의 개수 " << C::gett() << endl; // // C a; // cout << "생존하고 있는 원의 개수 " << C::gett() << endl; // // C b; // cout << "생존하고 있는 원의 개수 " << C::gett() << endl; //} ///////////////////////////////////////////////////////////////////////2번 /*#include <iostream> using namespace std; class P { int id; double weight; string name; public: P(int id1 = 1, double weight1 = 20.5, string name1 = "Grace") { id=id1; weight=weight1; name=name1; } void show() { cout << id << ' ' << weight << ' ' << name << endl; } }; int main() { P grace, ashley(2,20.5,"ashley"), helen(3,32.5,"helen"); grace.show(); ashley.show(); helen.show(); }*/ //////////////////////////////////////////////////////////////////4 /*#include <iostream> using namespace std; class MV{ int *mem; int size; public: MV(int n=100,int val=0); ~MV() { delete [] mem; } }; MV::MV(int n,int val) { mem= new int [n]; size = n; for(int i=0;i<n;i++) { mem[i]=val; } cout << val << ' ' << n << endl; } int main() { MV *v1,*v2; v1= new MV(); v2 = new MV(200,1); delete v1; delete v2; }*/ #include <iostream> #include <string> #include <algorithm> using namespace std; class AU2{ int s1[]; int s2[]; int size; public: static int* concat(int s1[],int s2[], int size); static int* remove(int s1[], int s2[], int size, int &retSize); }; int* AU2::concat(int s1[],int s2[],int size) { int *v = new int[size*2]; for(int i=0; i<5; i++) { v[i] = s1[i]; v[i+5] = s2[i]; } return v; } int* AU2::remove(int s1[],int s2[],int size, int& retSize) { int *z = new int[size]; for(int i=0; i<5; i++) { int j=0; for(j=0; j<5; j++) { if(s1[i]==s2[j]) { break; } } if(j==5) { z[retSize++] = s1[i]; } } return z; } int main() { AU2 AU; int retSize=0; int n=5,s1[5]={},s2[5]={}; cout << "정수를 " << n << " 개 입력하라. 배열 x에 삽입한다>>"; for(int i=0;i<n;i++) { cin >> s1[i]; } cout << "정수를 " << n << " 개 입력하라. 배열 y에 삽입한다> "; for(int i=0;i<n;i++) { cin >> s2[i]; } cout << "합친 정수 배열을 출력한다 " << endl; int *v = AU.concat(s1, s2, 5); for(int i=0; i<10; i++) { cout << v[i] << ' '; } cout << AU.concat(s1,s2,n) << ' '; int *z = AU.remove(s1,s2,n, retSize); cout << "배열 x[]에서 y[]를 뺀 결과를 출력한다. 개수는 " << retSize << endl; for(int i=0;i<retSize;i++) { cout << z[i] << ' '; } } https://docs.microsoft.com/ko-kr/cpp/cpp/main-function-command-line-args
0
0
3
kja090500
2021년 9월 07일
In 소스 코드 제출
//////////////////////////#include <iostream> ////////////////////////// //////////////////////////using namespace std; ////////////////////////// //////////////////////////int main() //////////////////////////{ ////////////////////////// cout << "Hello world!" << endl; ////////////////////////// return 0; //////////////////////////} //////////////////////// ////////////////////////#include <iostream> ////////////////////////#include <cstring> ////////////////////////using namespace std; ////////////////////////class Person ////////////////////////{ //////////////////////// char* name; //////////////////////// int id; ////////////////////////public: //////////////////////// Person(int id, const char* name); //////////////////////// Person(const Person& person); //////////////////////// ~Person(); //////////////////////// void change(const char *name,int id); //////////////////////// void show() //////////////////////// { //////////////////////// cout << id << ',' <<name << endl; //////////////////////// } ////////////////////////}; ////////////////////////Person::Person(int id, const char* name) ////////////////////////{ //////////////////////// this->id=id; //////////////////////// int len = strlen(name); //////////////////////// this->name = new char [len+1]; //////////////////////// strcpy(this->name,name); ////////////////////////} ////////////////////////Person::Person(const Person& person) ////////////////////////{ //////////////////////// this->id=person.id; //////////////////////// int len = strlen(person.name); //////////////////////// this->name = new char [len+1]; //////////////////////// strcpy(this->name,person.name); //////////////////////// cout << "복사생성자 실행 원본 객체의 이름 " << this->name << endl; ////////////////////////} ////////////////////////Person::~Person() ////////////////////////{ //////////////////////// if(name) //////////////////////// delete [ ] name; ////////////////////////} ////////////////////////void Person::change(const char* name,int id) ////////////////////////{ //////////////////////// if(strlen(name)>strlen(this-> name)) //////////////////////// return; //////////////////////// strcpy(this->name,name); //////////////////////// this->id=id; //////////////////////// ////////////////////////} ////////////////////////int main() ////////////////////////{ //////////////////////// Person father(1,"Kitae"); //////////////////////// Person daughter(father); //////////////////////// //////////////////////// cout<< "daughter 객체 생성 이후- ----" << endl; //////////////////////// father.show(); //////////////////////// daughter.show(); //////////////////////// //////////////////////// daughter.change("Grace",2); //////////////////////// cout << "daughter 이름을 Grace로 변경 후 " << endl; //////////////////////// father.show(); //////////////////////// daughter.show(); //////////////////////// //////////////////////// return 0; ////////////////////////} ////////////////////// //////////////////////#include <iostream> //////////////////////#include <cstring> //////////////////////using namespace std; //////////////////////class Person{ ////////////////////// char* name; //////////////////////public: ////////////////////// Person(const char* name); ////////////////////// Person(const Person& person); ////////////////////// ~Person(); ////////////////////// void change(const char* name); ////////////////////// //////////////////////}; //////////////////////Person::Person(const char* name) //////////////////////{ ////////////////////// int len = strlen(name); ////////////////////// this->name = new char [len+1]; ////////////////////// strcpy(this->name,name); //////////////////////} //////////////////////Person::Person(const Person& person) //////////////////////{ ////////////////////// int len = strlen(person.name); ////////////////////// this->name = new char [len+1]; ////////////////////// strcpy(this->name,person.name); //////////////////////} //////////////////////Person::~Person() //////////////////////{ ////////////////////// if(name) ////////////////////// delete [ ] name; //////////////////////} //////////////////////void Person::change(const char* name) //////////////////////{ ////////////////////// if(strlen(name)>strlen(this-> name)) ////////////////////// return; ////////////////////// strcpy(this->name,name); ////////////////////// //////////////////////} //////////////////////void f(Person person) //////////////////////{ ////////////////////// person.change("dummy"); //////////////////////} //////////////////////Person g() //////////////////////{ ////////////////////// Person mother("Jane"); ////////////////////// return mother; //////////////////////} //////////////////////int main() //////////////////////{ ////////////////////// Person father("Kitae"); ////////////////////// Person son=father; ////////////////////// f(father); ////////////////////// g(); //////////////////////} //////////////////// /////////////////////////////////////////////////////#2 //////////////////////#include <iostream> //////////////////////using namespace std; //////////////////////void half(double &n) //////////////////////{ ////////////////////// n=n/2; //////////////////////} //////////////////////int main() //////////////////////{ ////////////////////// double n=20; ////////////////////// half(n); ////////////////////// cout << n; //////////////////////} //////////////////// ///////////////////////////////////////////////////////////#3 //////////////////////#include <iostream> //////////////////////using namespace std; //////////////////////bool bigger(int a, int b, int& big) //////////////////////{ ////////////////////// if(a==b) ////////////////////// return true; ////////////////////// else if(a>b) ////////////////////// { ////////////////////// big=a; ////////////////////// return false; ////////////////////// } ////////////////////// else ////////////////////// { ////////////////////// big=b; ////////////////////// return false; ////////////////////// } //////////////////////} //////////////////////int main() //////////////////////{ ////////////////////// int big=0,a,b; ////////////////////// cin >> a >> b; ////////////////////// if(bigger(a,b,big)==0) ////////////////////// cout << big; //////////////////////} ////////////////////////////////////////////////////6 //////////////////////#include <iostream> //////////////////////#include <cstring> //////////////////////using namespace std; //////////////////////char& find(char a[],char c, bool& success) //////////////////////{ ////////////////////// int len=strlen(a); ////////////////////// for(int i=0;i<len;i++) ////////////////////// { ////////////////////// if(a[i]==c) ////////////////////// { ////////////////////// success=true; ////////////////////// return a[i]; ////////////////////// } ////////////////////// } ////////////////////// //////////////////////} //////////////////////int main() //////////////////////{ ////////////////////// char s[] = "Mike"; ////////////////////// bool b = false; ////////////////////// char& loc = find(s,'M',b); ////////////////////// if(b==false) ////////////////////// { ////////////////////// cout << "M을 발견할 수 없다 " << endl; ////////////////////// return 0; ////////////////////// } ////////////////////// loc = 'm'; ////////////////////// cout << s << endl; //////////////////////} /////////////////////* ////////////////////#include <iostream> ////////////////////using namespace std; ////////////////////class MIS { //////////////////// int *p; //////////////////// int size; //////////////////// int tos; ////////////////////public: //////////////////// MIS(); //////////////////// MIS(int size); //////////////////// MIS(const MIS& s); //////////////////// ~MIS(); //////////////////// bool push(int n); //////////////////// bool pop(int &n); //////////////////// ////////////////////}; ////////////////////MIS::MIS() ////////////////////{ //////////////////// tos=-1; //////////////////// size=0; //////////////////// ////////////////////} ////////////////////MIS::MIS(int size) ////////////////////{ //////////////////// this->size=size; //////////////////// p = new int [size]; //////////////////// tos=-1; ////////////////////} //////////////////// ////////////////////MIS::MIS(const MIS& a) ////////////////////{ //////////////////// this->size=a.size; //////////////////// p = new int [a.size]; //////////////////// this->tos = -1; //////////////////// //atos=-1; ////////////////////} ////////////////////MIS::~MIS() ////////////////////{ ////////////////////// if(p) ////////////////////// delete []size; ////////////////////} ////////////////////bool MIS::push(int n) ////////////////////{ //////////////////// tos++; //////////////////// p[tos]=n; //////////////////// if(tos>size) return false; //////////////////// else return true; ////////////////////} ////////////////////bool MIS::pop(int &n) ////////////////////{ //////////////////// n=p[tos--]; //////////////////// if(tos==-1) return false; //////////////////// else return true; //////////////////// ////////////////////} ////////////////////int main() ////////////////////{ //////////////////// MIS a(10); //////////////////// a.push(10); //////////////////// a.push(20); //////////////////// MIS b = a; //////////////////// b.push(30); //////////////////// //////////////////// int n; //////////////////// a.pop(n); //////////////////// cout << " 스택 a에서 팝한 값 " << n <<endl; //////////////////// b.pop(n); //////////////////// cout << " 스택 b에서 팝한 값 " << n << endl; ////////////////////} ////////////////////*/ ////////////////////#include<iostream> //////////////////// ////////////////////using namespace std; //////////////////// ////////////////////class calculator { ////////////////////public: //////////////////// float sum(int a, int b); //////////////////// float sum(float a, float b); //////////////////// float sum(int a, float b); ////////////////////}; //////////////////// ////////////////////float calculator::sum(int a, int b) { //////////////////// return (float)a+b; ////////////////////} //////////////////// ////////////////////int main() { //////////////////// ////////////////////} //////////////////// ////////////////// ////////////////// //////////////////#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 arr[5]={1,9,-2,8,6}; ////////////////// cout << big(2,3) << endl; ////////////////// cout << big(arr,5); //////////////////} ////////////////#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) ////////////{ //////////// for(int i=0;i<line;i++) //////////// { //////////// for(int j=0;j<10;j++) //////////// { //////////// cout << c; //////////// } //////////// cout << endl; //////////// } ////////////} ////////////int main() ////////////{ //////////// f(); //////////// f('%'); //////////// f('@',5); ////////////} //////////#include <iostream> //////////using namespace std; //////////void filll(int n=25,char c='*') //////////{ ////////// for(int i=0;i<n;i++) ////////// cout << c; ////////// cout << endl; //////////} //////////int main() //////////{ ////////// filll(); ////////// filll(10,'%'); //////////} ////////#include <iostream> ////////using namespace std; ////////class MV{ //////// int *p; //////// int size; ////////public: //////// MV(int n=100) //////// { //////// p=new int [n]; //////// size = n; //////// cout << n << endl; //////// } //////// ~MV() //////// { //////// delete [] p; //////// } ////////}; ////////int main() ////////{ //////// MV *v1,*v2; //////// v1 = new MV(); //////// v2 = new MV(1024); //////// //////// //////// delete v1; //////// delete v2; ////////} ////// //////#include <iostream> //////using namespace std; //////float square(float a) //////{ ////// return a*a; //////} //////double square(double a) //////{ ////// return a*a; //////} //////int main() //////{ ////// cout << square(3.0) << ' '; ////// cout << square(double(3)); //////} ////#include <iostream> ////using namespace std; ////int add(int a,int b) ////{ //// return a+b; ////} ////int add(int a[0],int b[0]) ////{ //// b[0]=b[0]+a[0]; //// return b[0]; ////} ////int main() ////{ //// int s=10,t=20; //// cout << add(s,t); ////} //#include <iostream> //#include <string> //using namespace std; //void msg(int id) //{ // cout << id << endl; //} //void msg(int id,string s) //{ // cout << id << ":" << s << endl; //} //int main() //{ // msg(5,"Goodmorning"); // msg(6); //} //#include <iostream> //using namespace std; //class Math{ //public: // static int abs(int a) { return a>0?a:-a; } // static int max(int a,int b) { return (a>b)?a:b; } // static int min(int a, int b) { return (a>b)?a:b; } //}; //int main() //{ // cout << Math::abs(-5) << endl; // cout << Math::max(10,8) << endl; // cout << Math::min(-3,-8) << endl; //} //#include <iostream> //using namespace std; //class Math{ //public: // static int abs(int a) { // if(a>0) // return -a; // // else // return a; // } // static int max(int a,int b) { // if(a<b) // return b; // else // return a; // } // static int min(int a, int b) { // if(a>b) // return b; // else // return a; } //}; //int main() //{ // cout << Math::abs(-5) << endl; // cout << Math::max(10,8) << endl; // cout << Math::min(-3,-8) << endl; //} #include <iostream> using namespace std; class C{ private: static int num; int radius; public: C(int r=1); ~C() {num--;} double getArea() { return 3.14*radius*radius; } static int getnum() { return num; } }; C::C(int r) { radius = r; num++; } int C::num = 0; int main() { C *p=new C[10]; cout << "생존하고 있는 원의 개수 " }
0
0
1
kja090500
2021년 8월 31일
In 소스 코드 제출
//////#include <iostream> ////// //////using namespace std; ////// //////int main() //////{ ////// cout << "Hello world!" << endl; ////// return 0; //////} //// ////#include <iostream> ////#include <cstring> ////using namespace std; ////class Person ////{ //// char* name; //// int id; ////public: //// Person(int id, const char* name); //// Person(const Person& person); //// ~Person(); //// void change(const char *name,int id); //// void show() //// { //// cout << id << ',' <<name << endl; //// } ////}; ////Person::Person(int id, const char* name) ////{ //// this->id=id; //// int len = strlen(name); //// this->name = new char [len+1]; //// strcpy(this->name,name); ////} ////Person::Person(const Person& person) ////{ //// this->id=person.id; //// int len = strlen(person.name); //// this->name = new char [len+1]; //// strcpy(this->name,person.name); //// cout << "복사생성자 실행 원본 객체의 이름 " << this->name << endl; ////} ////Person::~Person() ////{ //// if(name) //// delete [ ] name; ////} ////void Person::change(const char* name,int id) ////{ //// if(strlen(name)>strlen(this-> name)) //// return; //// strcpy(this->name,name); //// this->id=id; //// ////} ////int main() ////{ //// Person father(1,"Kitae"); //// Person daughter(father); //// //// cout<< "daughter 객체 생성 이후- ----" << endl; //// father.show(); //// daughter.show(); //// //// daughter.change("Grace",2); //// cout << "daughter 이름을 Grace로 변경 후 " << endl; //// father.show(); //// daughter.show(); //// //// return 0; ////} // //#include <iostream> //#include <cstring> //using namespace std; //class Person{ // char* name; //public: // Person(const char* name); // Person(const Person& person); // ~Person(); // void change(const char* name); // //}; //Person::Person(const char* name) //{ // int len = strlen(name); // this->name = new char [len+1]; // strcpy(this->name,name); //} //Person::Person(const Person& person) //{ // int len = strlen(person.name); // this->name = new char [len+1]; // strcpy(this->name,person.name); //} //Person::~Person() //{ // if(name) // delete [ ] name; //} //void Person::change(const char* name) //{ // if(strlen(name)>strlen(this-> name)) // return; // strcpy(this->name,name); // //} //void f(Person person) //{ // person.change("dummy"); //} //Person g() //{ // Person mother("Jane"); // return mother; //} //int main() //{ // Person father("Kitae"); // Person son=father; // f(father); // g(); //} /////////////////////////////////#2 //#include <iostream> //using namespace std; //void half(double &n) //{ // n=n/2; //} //int main() //{ // double n=20; // half(n); // cout << n; //} ///////////////////////////////////////#4 //#include <iostream> //using namespace std; //bool bigger(int a, int b, int& big) //{ // if(a==b) // return true; // else if(a>b) // { // big=a; // return false; // } // else // { // big=b; // return false; // } //} //int main() //{ // int big=0,a,b; // cin >> a >> b; // if(bigger(a,b,big)==0) // cout << big; //} /////////////////////////////////////////////////////////////////#6 //#include <iostream> //#include <cstring> //using namespace std; //char& find(char a[],char c, bool& success) //{ // int len=strlen(a); // for(int i=0;i<len;i++) // { // if(a[i]==c) // { // success=true; // return a[i]; // } // } // //} //int main() //{ // char s[] = "Mike"; // bool b = false; // char& loc = find(s,'M',b); // if(b==false) // { // cout << "M을 발견할 수 없다 " << endl; // return 0; // } // loc = 'm'; // cout << s << endl; //} #include <iostream> using namespace std; class MIS{ int *p; int size; int tos; public: MIS(); MIS(int size); MIS(const MIS& s); ~MIS(); bool push(int n); bool pop(int &n); }; MIS::MIS() { size=0; tos=0; p= new int [size]; } MIS::MIS(int size) { this->size=size; } MIS::MIS(const MIS& s) { s=s.size; } MIS::~MIS(){ } bool MIS::push(int n) { } bool MIS::pop(int &n) { } int main() { MIS a(10); a.push(10); a.push(20); MIS b = a; b.push(30); int n; a.pop(n); cout << "스택 a에서 팝한 값 " << n << endl; cout << " 스택 b에서 팝한 값" << n << endl; }
0
0
1
kja090500
2021년 8월 26일
In 소스 코드 제출
////////////////////#include <iostream> //////////////////// ////////////////////using namespace std; //////////////////// ////////////////////int main() ////////////////////{ //////////////////// cout << "Hello world!" << endl; //////////////////// return 0; ////////////////////} //////////////////#include <iostream> //////////////////using namespace std; //////////////////class Circle{ //////////////////int radius; //////////////////public: ////////////////// Circle() {radius=1;} ////////////////// Circle(int r) {this->radius=r;} ////////////////// void sett(int radius) {this->radius=radius;} ////////////////// double getArea() {return 3.14*radius*radius;} //////////////////}; //////////////////Circle getC() //////////////////{ ////////////////// Circle tmp(30); ////////////////// return tmp; //////////////////} //////////////////int main() //////////////////{ ////////////////// Circle c; ////////////////// cout << c.getArea() << endl; ////////////////// ////////////////// c=getC(); ////////////////// cout << c.getArea() << endl; //////////////////} ////////////// ////////////////#include <iostream> ////////////////using namespace std; ////////////////int main() ////////////////{ //////////////// cout << "i" << '\t' //////////////// //////////////// //////////////// ////////////////} ////////////////*/ //////////////// ////////////////#include<stdio.h> //////////////// ////////////////int main() { //////////////// char word[100]; //////////////// //////////////// scanf("%s", word); //////////////// printf("%s", word); ////////////////} //////////////// ////////////////// char &find = 'S'; ////////////////// &s[0] = 'S'; //////////////#include <iostream> //////////////using namespace std; //////////////int main() //////////////{ ////////////// cout << "i" << '\t' << "n" << '\t' << "refn" << endl; ////////////// int i =1; ////////////// int n=2; ////////////// int &refn = n; ////////////// n=4; ////////////// refn++; ////////////// cout << i << '\t' << n << '\t' << refn << endl; ////////////// ////////////// refn = i; ////////////// refn++; ////////////// cout << i << '\t' << n << '\t' <<refn << endl; ////////////// ////////////// int *p=&refn; ////////////// *p=20; ////////////// cout << i << '\t' << n << '\t' << refn << endl; //////////////} ////////////#include <iostream> ////////////using namespace std; ////////////class C{ ////////////int radius; ////////////public: //////////// C() { radius = 1;} //////////// C(int r) { radius = r;} //////////// void sett(int r) { radius = r;} //////////// double getArea() { return 3.14*radius*radius;} ////////////}; ////////////int main() ////////////{ //////////// C c; //////////// C &refc = c; //둘이 주소까지 같아짐. //////////// refc.sett(10); //////////// cout << refc.getArea() << " " << c.getArea(); ////////////} //////////#include <iostream> //////////using namespace std; //////////bool average(int a[],int size,int& avg) //////////{ ////////// if(size <=0) ////////// { ////////// return false; ////////// } ////////// int sum=0; ////////// for(int i=0;i<size;i++) ////////// { ////////// sum +=a[i]; ////////// } ////////// avg = sum/size; ////////// return true; //////////} //////////int main() //////////{ ////////// int x[] = {0,1,2,3,4,5}; ////////// int avg; ////////// if(average(x,6,avg)) cout << "평균은 " << avg << endl; ////////// else cout << "매개변수 오류 " << endl; ////////// ////////// if(average(x,-2,avg)) cout << "평균은 " << avg << endl; ////////// else cout << "매개변수 오류 " << endl; //////////} ////////#include <iostream> ////////using namespace std; ////////class C{ ////////private: //////// int radius; ////////public: //////// C(); //////// C(int r); //////// ~C(); //////// double getA() {return 3.14*radius*radius;} //////// int getR() {return radius;} //////// void sett(int radius) {this->radius=radius;} //////// ////////}; ////////C::C() ////////{ //////// radius = 1; //////// cout << "생성자 실행 radius = " << radius << endl; ////////} ////////C::C(int r) ////////{ //////// this->radius = r; //////// cout << "생성자 실행 radius = " << radius << endl; ////////} ////////C::~C() ////////{ //////// cout << "소멸자 실행 radius = " << radius << endl; ////////} ////////void increase(C &c) ////////{ //////// int r = c.getR(); //////// c.sett(r+1); ////////} ////////int main() ////////{ //////// C waffle(30); //////// increase(waffle); //////// cout << waffle.getA() << endl; ////////} //////#include <iostream> //////using namespace std; //////class C{ //////int radius; //////public: ////// C() {radius=1;} ////// C(int r) {this->radius=r;} ////// void sett(int r) {this->radius=r;} ////// double getA() {return 3.14*radius*radius;} //////}; //////void read(C &donut1) //////{ ////// int r; ////// cout << "정수 값으로 반지름을 입력하세요>> "; ////// cin >> r; ////// donut1.sett(r); //////} //////int main() //////{ ////// C donut; ////// read(donut); ////// cout << "donut의 면적 = " << donut.getA() << endl; //////} ////// ////// //////#include <iostream> //////using namespace std; //////char& find(char s[],int index) //////{ ////// return s[index]; //////} //////int main() //////{ ////// char name[] = "Mike"; ////// cout << name << endl; ////// ////// find(name,0) = 'S'; ////// cout << name << endl; ////// ////// char& ref = find(name,2); ////// ref='t'; ////// cout << name << endl; ////// //////} ////#include <iostream> ////using namespace std; ////class C{ ////private: //// int radius; ////public: //// C(const C& c); //// C() { radius = 1;} //// C(int r) { this->radius = r;} //// double getArea() {return 3.14*radius*radius;} ////}; ////C::C(const C& c) ////{ //// radius=c.radius; //// cout << "복사 생성자 실행 radius = " << radius << endl; //// ////} ////int main() ////{ //// C src(30); //// C dest(src); //// //// cout << "원본의 면적 = " << src.getArea() << endl; //// cout << "사본의 면적 = " << dest.getArea() << endl; ////} //#include <iostream> //#include <cstring> //using namespace std; //class Person{ //char* name; //int id; //public: // Person(int id,const char* name); // ~Person(); // void changeName(const char *name); // void show() {cout << id << ',' << name << endl;} //}; //Person::Person(int id,const char* name) //{ // this->id=id; // int len = strlen(name); // this->name = new char[len+1]; // strcpy(this->name,name); //} //Person::~Person() //{ // if(name) // delete [] name; //} //void Person::changeName(const char* name) //{ // if(strlen(name)>strlen(this->name)) // return; // strcpy(this->name,name); //} //int main() //{ // Person father(1,"Kitea"); // Person daughter(father); // // cout << "daughter 객체 생성 직후 ---" << endl; // // father.show(); // daughter.show(); // // daughter.changeName("Grace"); // cout << "daughter 이름을 Grace로 변경한 후 ---" << endl; // father.show(); // daughter.show(); // // return 0; //} #include <iostream> #include <cstring> using namespace std; class Person { char* name; int id; public: Person(int id,const char* name); Person(const Person& person); ~Person(); void changeName(const char *name); void show() { cout << id << ',' << name << endl;} }; Person::Person(int id,const char* name) { this->id=id; int len = strlen(name); this->name = new char[len+1]; strcpy(this->name,name); } Person::Person(const Person& person) { this->id=person.id; int len = strlen(person.name); this->name = new char [len+1]; strcpy(this->name,person.name); cout << "복시 생성자 실행. 원본 객체의 이름 " << this->name << endl; } Person::~Person() { if(name) delete [ ] name; } void Person::changeName(const char* name) { if(strlen(name)>strlen(this->name)) return; strcpy(this->name,name); } int main() { Person father(1,"Kitae"); Person daughter(father); cout << "daughter 객체 생성 직후 " << endl; father.show(); daughter.show(); daughter.changeName("Grace"); cout << "daughter 이름 변경 후 " << endl; father.show(); daughter.show(); return 0; }
0
0
1
kja090500
2021년 8월 24일
In 소스 코드 제출
////////#include <iostream> //////// ////////using namespace std; //////// ////////int main() ////////{ //////// cout << "Hello world!" << endl; //////// return 0; ////////} //////#include <iostream> ////// //////#include <string.h> ////// //////#include <ctype.h> ////// ////// //////using namespace std; ////// //////class histogram{ ////// //////public: ////// ////// void put(string str); ////// ////// void putc(char c); ////// ////// void print(); ////// ////// //////}; ////// //////void histogram::put() ////// //////{ ////// //////} ////// //////void histogram::putc() ////// //////{ ////// ////// //////} ////// //////int main() ////// //////{ ////// ////// histogram histo; ////// ////// string str2; ////// ////// getline(cin,str2); ////// ////// int len; ////// ////// len=str2.length(); ////// ////// ////// if(isalpha(str2)) ////// ////// { ////// histo.put(); ////// } ////// ////// else histo.putc(); ////// ////// for(int i=0;i<len;i++) ////// ////// { ////// ////// str2[i]=tolower(str2[i]); ////// ////// } ////// ////// histogram elvisHisto() ////// ////// cout << str2; ////// //////} ////#include <iostream> ////#include <string.h> ////using namespace std; ////class histogram ////{ //// string arr; //// int h[26] = {}; ////public: //// histogram(string arr){this->arr=arr;} //// histogram() {this->arr ="";} //// void put(string his); //// void putc(char hh); //// void print(); ////}; ////void histogram::put(string his) ////{ //// this->arr.append(his); //// ////} ////void histogram::putc(char hh) ////{ //// char buf[]={hh,'\0'}; //// this->arr.append(buf); ////} ////void histogram::print() ////{ //// for(int i = 0; i<26; i++) //// { //// h[i]=0; //// } //// cout << arr << endl; //// for(int i = 0; i<arr.length(); i++) //// { //// if(isalpha(arr[i])) //// { //// char c = tolower(arr[i]); //// h[c-'a']++; //// } //// } //// int n=0; //// for(int i=0;i<26;i++) //// { //// n+=h[i]; //// //// } //// cout << "총 알파벳 수 " << n << endl; //// for(int i = 0; i <26; i++) //// { //// cout << (char)(i+'a') << "(" << h[i] << ") " << ": "; //// for(int j=0; j<h[i]; j++) //// { //// cout << '*'; //// } //// cout << endl; //// } ////} ////int main() ////{ //// histogram elvisHisto("Wise men say, only fools rush in But I can't help, "); //// elvisHisto.put("falling in love with you"); //// elvisHisto.putc('-'); //// elvisHisto.put("Elvis Presley"); //// elvisHisto.print(); //// ////} //// //// #include <iostream> using namespace std; class C{ private: int radius; public: C(); C(int ra); ~C(); double getArea() { return 3.14*3.14*radius;} int getRadius() { return radius;} void sett(int radius) {this ->radius=radius;} }; C::C() { radius=1; cout << "생성자 실행 radius = " << radius << endl; } C::C(int ra) { this->radius=ra; cout << "생성자 실행 radius = " << radius << endl; } C::~C() { cout << "소멸자 실행 radius = " << radius << endl; } void increase(C c) { int r=c.getRadius(); c.sett(r+1); } int main() { C waffle(30); increase(waffle); cout << waffle.getRadius() << endl; } //#include <iostream> //using namespace std; //void swap(int a,int b) //{ // int tmp; // tmp=a; // a=b; // b=tmp; //} //int main() //{ // int n=9,m=2; // swap(m,n); // cout << m << ' ' << n; //}
0
0
2
kja090500
2021년 8월 19일
In 소스 코드 제출
//#include <iostream> // //using namespace std; // //int main() //{ // cout << "Hello world!" << endl; // return 0; //} /* #include <iostream> #include <string.h> using namespace std; class Person { string name; string tel; public: Person() { name=" "; tel=" "; } ~Person() {} string getname() { return name; } string gettel() { return tel; } void sett(string name1, string tel1) { name=name1; tel=tel1; } }; int main() { Person *parr = new Person [3]; string name; string tel; for(int i=0; i<3; i++) { cout << "사람 " << i+1 << "<<"; cin >> name >> tel; parr[i].sett(name,tel); } cout << "모든 사람의 이름은 "; for(int i=0; i<3; i++) { cout << parr[i].getname() << ' ';////그냥 getname 만 쓰는거 아님. } cout << "전화번호 검색합니다. 이름을 입력하세요>> "; cin >> name; //// 새로 이름 받기 for(int i=0;i<3;i++) { if(name==parr[i].getname()) ////parr에 저장해둔 이름이랑 비교 { cout << parr[i].gettel(); ////new 써서 화살표가 아니라 점써야됨 break; } } }*/ /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #include <iostream> using namespace std; class Container { int size; public: Container() { size=10; } void fill(); void consume(); int getSize(); }; void Container::fill() { size=10; } void Container::consume() { size--; } int Container::getSize() { return size; } class CVM { Container tong[3]; void fill(); void selectA(); void selectE(); void selectSC(); void show(); public: void run(); }; void CVM::fill() { tong[0].fill(); tong[1].fill(); tong[2].fill(); cout << "커피 " << tong[0].getSize() << "물" << tong[1].getSize() << "설탕 " << tong[2].getSize(); } void CVM::selectA() { tong[0].consume(); tong[0].consume(); tong[1].consume(); } void CVM::selectE() { tong[0].consume(); tong[1].consume(); } void CVM::selectSC() { tong[0].consume(); tong[1].consume(); tong[1].consume(); tong[2].consume(); } void CVM::show() { cout << "커피 " << tong[0].getSize() << "물" << tong[1].getSize() << "설탕 " << tong[2].getSize(); } void CVM::run() { int n; cout << "커피 자판기를 작동합니다." << endl; for(;;) { cout << "메뉴를 눌러주세요(1:에스프레소 2:아메리카노 3:설탕커피 4:잔량보기 5:채우기)>>"; cin >> n; if(n==1) { if(tong[0].getSize()!=0&&tong[1].getSize()!=0) { selectE(); cout << "에스프레소 드세요 "; } } if(n==2) { if(tong[0].getSize()!=0&&tong[1].getSize()<=1) { selectA(); cout << "아메리카노 드세요 "; } } if(n==3) { if(tong[0].getSize()!=0&&tong[2].getSize()<=1&&tong[3].getSize()!=0) { selectSC(); cout << "설탕커피 드세요 "; } } if(n==4) { show(); } if(n==5) { fill(); } } } int main() { CVM coffee; coffee.run(); }+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ #include <iostream> #include <string.h> #include <ctype.h> using namespace std; class histogram{ public: void put(string str); void putc(char c); void print(); }; /*void histogram::put() { } void histogram::putc() { }*/ int main() { histogram histo; string str2; getline(cin,str2); int len; len=str2.length(); if(isalpha(str2)) { histo.put(); } else histo.putc(); for(int i=0;i<len;i++) { str2[i]=tolower(str2[i]); } histogram elvisHisto() cout << str2; } //https://blockdmask.tistory.com/448
0
0
6
kja090500
2021년 8월 17일
In 소스 코드 제출
////////#include <iostream> //////// ////////using namespace std; //////// ////////int main() ////////{ //////// cout << "Hello world!" << endl; //////// return 0; ////////} //////#include <iostream> //////using namespace std; //////class color{ //////int r,g,b; //////public: ////// color() {r=g=b=0;} ////// color(int red,int blue,int green) {r=red; b= blue; g=green;} ////// void sett(int red,int blue,int green) {r=red; b= blue; g=green;} ////// void show() {cout << r << ' ' << g << ' ' << b << endl; } //////}; //////int main() //////{ ////// color screencolor(255,0,0); ////// color *p; ////// p = &screencolor; ////// p->show(); ////// color colors[3]; ////// colors[0].sett(255,0,0); ////// colors[1].sett(0,255,0); ////// colors[2].sett(0,0,255); ////// ////// for(int i=0;i<3;i++) ////// { ////// colors[i].show(); ////// } //////} //// ////#include <iostream> ////#include <string.h> ////using namespace std; //// ////int main() ////{ //// string s; //// getline(cin,s,'\n'); //// int num=0,start=0; //// char a='a'; //// for(int i=0;i<s.length();i++) //// { //// if(s[i]=='a') //// { //// num++; //// } //// } //// while(true) //// { //// int Index = s.find(a,start); //// start- //// } //// cout << "개수는 " << num << endl; //// ////} //#include <iostream> //using namespace std; //class Sample{ //int *p; //int size; //public: // Sample(int n) { // size = n; p=new int [n]; // } // void read(); // void write(); // int big(); // ~Sample(); //}; //void Sample::read() //{ // for(int i=0;i<10;i++) // { // cin >> p[i]; // } //} //void Sample::write() //{ // for(int i=0;i<10;i++) // { // cout << p[i] << ' '; // } //} //int Sample::big() //{ // int tmp; // for(int i=0;i<10;i++) // { // if(p[i]>p[i+1]) // { // tmp=p[i]; // p[i]=p[i+1]; // p[i+1]=tmp; // } // } // return tmp; //} //Sample::~Sample() //{ // //} //int main() //{ // Sample s(10); // s.read(); // s.write(); // cout << "가장 큰 수는 " << s.big() << endl; //} /*1346891113*/ /* #include <iostream> #include <string> using namespace std; int main() { string s; getline(cin,s,'\n'); int len = s.length(); for(int i=0;i<len;i++) { while(len-i!=0) { string first = s.substr(len-i,len-i+1); string sub = s.substr(len-i-2,len-i-1); s=sub+first; cout << s << endl; } } }*/ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #include<iostream> #include<string> using namespace std; string RS(string src, int len) { string re =""; for(int i=0; i<len; i++) { re += src.substr(len-i-1,1); } //re+=src.substr(len-i-1,1); return re; } int main() { string ori; getline(cin,ori); ori = RS(ori, ori.size()); cout << ori <<endl; return 0; } ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* #include<iostream> #include<string> using namespace std; int main() { string str = "HELLOWORLD"; str += str[0]; str += str[1]; cout << str << endl; } */ /*#include <iostream> using namespace std; class ci{ public: int radius; public: ci(){radius=1;} ~ci() { } void sett(int r) {radius = r;} double getArea() {return 3.14*radius*radius;} }; int main() { cout << "원의 개수: "; int n,radius; cin >> n; ci *parr = new ci [n]; for(int i=0;i<n;i++) { cout << "원 " << i+1 << ":"; cin >> radius; parr[i].sett(radius); } int cnt=0; ci* p=parr; for(int i=0;i<n;i++) { if(p->getArea()>100) cnt++; } cout << cnt; }*/
0
0
5
kja090500
2021년 8월 12일
In 소스 코드 제출
//////////////////////////#include <iostream> ////////////////////////// //////////////////////////using namespace std; ////////////////////////// //////////////////////////int main() //////////////////////////{ ////////////////////////// cout << "Hello world!" << endl; ////////////////////////// return 0; //////////////////////////} ////////////////////////#include <iostream> ////////////////////////using namespace std; ////////////////////////class Circle{ ////////////////////////int radius; ////////////////////////public: //////////////////////// Circle() {radius = 1;} //////////////////////// Circle(int r) { radius = r; } //////////////////////// double getArea(); ////////////////////////}; ////////////////////////double Circle::getArea() ////////////////////////{ //////////////////////// return 3.14*radius*radius; ////////////////////////} ////////////////////////int main() ////////////////////////{ //////////////////////// Circle donut; //////////////////////// Circle pizza(10); //////////////////////// cout << donut.getArea() << endl; //////////////////////// Circle *p; //////////////////////// p = &donut; //////////////////////// cout << p->getArea() << endl; //////////////////////// cout << (*p).getArea() << endl; //////////////////////// //////////////////////// p = &pizza; //////////////////////// cout << p->getArea() << endl; //////////////////////// cout << (*p).getArea() << endl; ////////////////////////} ////////////////////// //////////////////////#include <iostream> //////////////////////using namespace std; //////////////////////class Circle{ //////////////////////int radius; //////////////////////public: ////////////////////// Circle() {radius = 1;} ////////////////////// Circle(int r) {radius = r;} ////////////////////// double getArea(); //////////////////////}; //////////////////////double Circle::getArea() //////////////////////{ ////////////////////// return 3.14*radius*radius; //////////////////////} //////////////////////int main() //////////////////////{ ////////////////////// Circle donut; ////////////////////// Circle pizza(10); ////////////////////// cout << donut.getArea() << endl; ////////////////////// Circle *p; ////////////////////// p = &donut; ////////////////////// cout << p->getArea() << endl; ////////////////////// cout <<(*p).getArea() << endl; ////////////////////// p = &pizza; ////////////////////// cout << p->getArea() <<endl; ////////////////////// cout << (*p).getArea() <<endl; //////////////////////} //////////////////// ////////////////////#include <iostream> ////////////////////using namespace std; ////////////////////class Circle{ ////////////////////int radius; ////////////////////public: //////////////////// Circle(){ radius = 1;} //////////////////// Circle(int r) {radius = r;} //////////////////// void setRadius(int r) {radius = r;} //////////////////// double getArea(); ////////////////////}; ////////////////////double Circle::getArea() ////////////////////{ //////////////////// return radius*3.14*radius; ////////////////////} ////////////////////int main() ////////////////////{ //////////////////// Circle arr[3]; //////////////////// arr[0].setRadius(10); //////////////////// arr[1].setRadius(20); //////////////////// arr[2].setRadius(30); //////////////////// for(int i=0;i<3;i++) //////////////////// { //////////////////// cout << "Circle " << i << "의 면적은 " << arr[i].getArea() <<endl; //////////////////// } //////////////////// Circle *p; //////////////////// p = arr; //////////////////// for(int i=0;i<3;i++) //////////////////// { //////////////////// cout << "Circle " << i << "의 면적은 " << p->getArea() <<endl; //////////////////// p++; //////////////////// } ////////////////////} //////////////////// ////////////////// //////////////////#include <iostream> //////////////////using namespace std; //////////////////class Circle{ //////////////////int radius; //////////////////public: ////////////////// Circle() {radius = 1;} ////////////////// Circle(int r) {radius = r;} ////////////////// void sett(int r ) { radius = r;} ////////////////// double getArea(); //////////////////}; //////////////////double Circle::getArea() //////////////////{ ////////////////// return 3.14*radius*radius; //////////////////} //////////////////int main() //////////////////{ ////////////////// Circle arr[3] = {Circle(10),Circle(20),Circle()}; ////////////////// for(int i=0;i<3;i++) ////////////////// { ////////////////// cout<< "Circle " << i << "의 면적은 " << arr[i].getArea() <<endl; ////////////////// } //////////////////} //////////////// ////////////////#include <iostream> ////////////////using namespace std; ////////////////class Circle{ ////////////////int radius; ////////////////public: //////////////// Circle() {radius = 1;} //////////////// Circle(int r) {radius = r;} //////////////// void sett(int r) {radius = r;} //////////////// double getArea(); ////////////////}; ////////////////double Circle::getArea() ////////////////{ //////////////// return 3.14*radius*radius; ////////////////} ////////////////int main() ////////////////{ //////////////// Circle arr[3] = {Circle(10), Circle(20), Circle()}; //////////////// for(int i=0;i<3;i++) //////////////// { //////////////// cout << "Circle " << i << "의 면적은 " << arr[i].getArea() << endl; //////////////// } ////////////////} ////////////// //////////////#include <iostream> //////////////using namespace std; //////////////class Circle{ //////////////int radius; //////////////public: ////////////// Circle() { radius = 1;} ////////////// Circle(int r) {radius = r;} ////////////// void sett(int r){radius = r;} ////////////// double getArea(); //////////////}; //////////////double Circle::getArea() //////////////{ ////////////// return 3.14*radius*raidus; //////////////} //////////////int main() //////////////{ ////////////// Circle C[2][3]; ////////////// C[][].sett() ////////////// C[][].sett() ////////////// C[][].sett() ////////////// C[][].sett() ////////////// C[][].sett() //////////////} ////////////#include <iostream> ////////////using namespace std; ////////////int main() ////////////{ //////////// int *p; //////////// p = new int; //////////// if(!p) //////////// { //////////// cout << "메모리를 할당할 수 없습니다 "; //////////// return 0; //////////// } //////////// *p=5; //////////// int n = *p; //////////// cout << "*p = " << *p << endl; //////////// cout << "n = " << n <<endl; //////////// delete p; //////////// ////////////} //////////// ////////// ////////// //////////#include <iostream> //////////using namespace std; //////////int main() //////////{ ////////// cout << " 입력할 정수의 개수는? "; ////////// int n; ////////// cin >> n; ////////// if(n<=0) return 0; ////////// int *p = new int[n]; ////////// if(!p) ////////// { ////////// cout << "메모리를 할당할 수 없습니다."; ////////// return 0; ////////// } ////////// for(int i=0;i<n;i++) ////////// { ////////// cout <<i+1 << "번째 정수: "; ////////// cin >>p[i]; ////////// } ////////// int sum=0; ////////// for(int i=0;i<n;i++) ////////// { ////////// sum+=p[i]; ////////// ////////// } ////////// cout << "평균 =" << sum/n << endl; ////////// delete [] p; //////////} //////// ////////#include <iostream> ////////using namespace std; ////////class Circle{ ////////int radius; ////////public: //////// Circle(); //////// Circle(int r); //////// ~Circle(); //////// void sett(int r) {radius = r;} //////// double getArea(); ////////}; ////////Circle::Circle() ////////{ //////// radius = 1; //////// cout << "생성자 실행 radius " << radius << endl; ////////} ////////Circle::Circle(int r) ////////{ //////// radius = r; //////// cout << "생성자 실행 radius " << radius << endl; ////////} ////////Circle::~Circle() ////////{ //////// cout << "소멸자 실행 radius " << radius << endl; ////////} ////////double Circle::getArea() ////////{ //////// return 3.14*radius*radius; ////////} ////////int main() ////////{ //////// Circle *p,*q; //////// p = new Circle; //////// q = new Circle(30); //////// cout << p->getArea() <<endl << q->getArea() << endl; //////// delete p; //////// delete q; ////////} //////// ////// //////#include <iostream> //////using namespace std; //////class Circle{ //////int radius; //////public: ////// Circle(); ////// Circle(int r); ////// ~Circle(); ////// void sett(int r) {radius = r;} ////// double getArea(); //////}; //////Circle::Circle() //////{ ////// radius = 1; ////// cout << "생성자 실행 radius " << radius << endl; //////} //////Circle::Circle(int r) //////{ ////// radius = r; ////// cout << "생성자 실행 radius " << radius << endl; //////} //////Circle::~Circle() //////{ ////// cout << "소멸자 실행 radius " << radius << endl; //////} //////double Circle::getArea() //////{ ////// return 3.14*radius*radius; //////} //////int main() //////{ ////// Circle *parr = new Circle[3]; ////// ////// parr[0].sett(10); ////// parr[1].sett(20); ////// parr[2].sett(30); ////// ////// for(int i=0;i<3;i++) ////// { ////// cout << parr[i].getArea() << endl; ////// } ////// Circle *p =parr; ////// for(int i=0;i<3;i++) ////// { ////// cout << p->getArea() <<endl; ////// p++; ////// } ////// delete [] parr; //////} ////#include <iostream> ////#include <string.h> ////using namespace std; ////int main() ////{ //// string str; //// string ad("서울시 성북구 삼선동 389"); //// string copyad(ad); //// //// char text[] = {'L','O','V','E',' ','C','+','+'}; //// string title(text); //// //// cout << str << endl; //// cout << ad << endl; //// cout << copyad << endl; //// cout << title << endl; ////} // //#include <iostream> //#include <string.h> //using namespace std; //int main() //{ // string names[5]; // // for(int i=0;i<5;i++) // { // cout << "이름 >> "; // getline(cin,names[i],'\n'); // } // string latter = names[0]; // for(int i=1;i<5;i++) // { // if(latter< names[i]) // { // latter = names[i]; // } // } // cout <<latter << endl; //} // /*1346891113*/ #include <iostream> using namespace std; class Color{ int r,g,b; public: Color(){r=g=b=0;} Color(int re,int bl,int gr){r=re; g=gr; b= bl;} void sett(int re,int bl,int gr) {r=re;g=gr;b=bl;} void show() {cout << r << ' ' << g << ' ' << b << ' ';} }; int main() { Color *screenC(255,0,0); Color *p; p = new screenC; cout << screenC.show() << endl; Color *colors = new Color[3]; p = new colors; colors[0].sett(255,0,0); colors[1].sett(0,255,0); colors[2].sett(0,0,255); cout << p.show() <<endl; cout << p.show() << endl; cout << p.show() << endl; }
0
0
10
kja090500
2021년 8월 10일
In 소스 코드 제출
////////#include <iostream> //////// ////////using namespace std; //////// ////////int main() ////////{ //////// cout << "Hello world!" << endl; //////// return 0; ////////} //////#include <iostream> //////using namespace std; //////class Tower{ //////public: ////// int high; ////// Tower(); ////// Tower(int h); ////// int gethigh(); //////}; //////Tower::Tower():Tower(1){} //////Tower::Tower(int h) //////{ ////// high = h; //////} //////int Tower::gethigh() //////{ ////// return high; //////} //////int main(){ ////// ////// Tower myTower; ////// Tower seoulTower(100); ////// cout << "높이는 " << myTower.gethigh() << "미터" << endl; ////// cout << "높이는 " << seoulTower.gethigh() << "미터" << endl; ////// return 0; //////} /////* ////#include <iostream> ////using namespace std; ////class Account ////{ ////public: //// Account(string name,int id2,int balance2); //// string getOwner(); //// string name1; //// int inquiry(); //// int withdraw(int b); //// int deposit(int a); //// int id1; //// int balance = 0; //// ////}; ////Account::Account(string name2,int id2, int balance2) ////{ //// name1 = name2; //// id1 = id2; //// balance = balance2; ////} ////int Account::deposit(int a) ////{ //// balance += a; ////} ////int Account::withdraw(int b) ////{ //// balance -=b; ////} ////string Account::getOwner() ////{ //// return name1; ////} ////int Account::inquiry() ////{ //// return balance; ////} ////int main() ////{ //// Account a("kitae",1,5000); //// a.deposit(50000); //// cout << a.getOwner() << "의 잔액은 " << a.inquiry() << endl; //// int money = a.withdraw(20000); //// cout << a.getOwner() << "의 잔액은 " << a.inquiry() << endl; ////} ////*/ /////* ////#include <iostream> ////#include <ctime> ////#include <cstdlib> ////#include <time.h> //// ////using namespace std; ////class Random{ ////public: //// Random(); //// int next(); //// int nextInRange(int a, int b); ////}; ////Random::Random() { //// srand(time(NULL)); ////} //// ////int Random::next() { //// return rand() % RAND_MAX; ////} ////int Random::nextInRange(int a,int b) ////{ //// return rand() % (b-a+1) + a; ////} ////int main() ////{ //// Random r; //// cout << "-- 0에서 " << RAND_MAX << "까지의 랜덤 정수 10 개 " << endl; //// for(int i=0;i<10;i++) //// { //// int n = r.next(); //// cout << n << ' '; //// } //// cout << endl << endl << "-- 2에서 " << " 4 까지의 랜덤 정수 10 개 " << endl; //// for(int i=0;i<10;i++) //// { //// int n = r.nextInRange(2,4); //// cout << n << ' '; //// } //// cout << endl; ////} ////*/ //// ////#include <iostream> ////#include <ctime> ////#include <cstdlib> ////#include <time.h> ////using namespace std; ////class Random{ ////public: //// Random(); //// int next(); //// int nextInRange(int a,int b); //// ////}; ////Random::Random() ////{ //// srand(time(NULL)); ////} ////int Random::next() ////{ //// return rand() % RAND_MAX; ////} ////int Random::nextInRange(int a,int b) ////{ //// return rand() % (b-a+1) + a; ////} ////int main() ////{ //// int num1=0,num2=0; //// Random r; //// cout << "-- 0에서 " << RAND_MAX << "까지의 랜덤 정수 10 개 " << endl; //// for(int i=0;i<100;i++) //// { //// int n = r.next(); //// if(n%2 == 0) //// { //// cout << n << ' '; //// num1++; //// if(num1 == 10) break; //// } //// } //// cout << endl << endl << "-- 2에서 " << " 9 까지의 랜덤 정수 10 개 " << endl; //// for(int i=0;i<100;i++) //// { //// int n = r.nextInRange(2,9); //// if(n%2 != 0) //// { //// cout << n << ' '; //// num2++; //// if(num2 == 10) break; //// } //// } //// cout << endl; ////} // //#include<iostream> // //#define ACER (X*Y)+Z/SQR // //using namespace std; // //class flower { //public: // int a; // flower(); //}; // //flower::flower() { // cout << "^^" << endl; //} //int main() { // const int a = 1234; // cout << a << endl; // // flower *t = new flower[10]; // t[0].a = ACER; // // cout << t[0].a << endl; // // // flower mintChoco; // flower *p = &mintChoco; // p->a = 10; // // cout << mintChoco.a << endl; // // flower a; // flower arr[10]; // // arr[0].a = 10; // arr[1].a = 20; //*/ //} /* #include <iostream> using namespace std; class Circle { int radius; public: Circle(){ radius = 1;} Circle(int r) { radius = r; } double getArea(); }; double Circle::getArea() { return 3.14*radius*radius; } int main() { Circle donut; Circle pizza(30); cout << donut.getArea() << endl; Circle *p; p = &donut; cout << p->getArea() << endl; cout << (*p).getArea()<< endl; p = &pizza; cout << p->getArea() << endl; cout << (*p).getArea() << endl; }*/ #include <iostream> using namespace std; class Circle{ int radius; public: Circle(); Circle };
0
0
1

kja090500

더보기
주소 : 경기도 용인시 광교중앙로 302 블루 스퀘어 602호
연락처 : 031) 216 - 1546 ,     031) 215 - 1546
사업자등록번호 : 465-92-00916
​학원 등록 제 4603호
bottom of page