💻 개발 & CS시스템 임베디드

시스템 프로그래밍 프로젝트 #5

문제 : 입력 파일 : [sample.txt 0.00MB](https://blog.kakaocdn.net/dna/rQmDA/btqBh0wGGuo/AAAAAAAAAAAAAAAAAAAAAOJH_v7vkHkLQ6qLzsNnWwGtEpIuLXHhdgVHWZ1_bdfn/sample.txt?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&expires=1788188399&allow_ip=&allow_referer=&signature=g2umKymX%2Fy9G6jLj7w3iVVcqUKc%3D&attach=1&knm=tfile.txt) 실행결과 : 소스코드 : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 #include<stdio.h> #include<string.h> #include<stdlib.h> int len=0; void print_len_word(char *bp){ int i; for(i=0; bp[i]!='\0'; i++) // bp 배열의 끝이 나올때까지 loop if(bp[i]=='\n') bp[i] = '\0'; // bp[i]가 개행문자이면 그곳을 NULL로 바꿈 printf("%.2X: %s\n", len, bp); len += strlen(bp); } int main() { char buf[80]; FILE* fp; if(!(fp = fopen("test1.txt", "r"))) { printf("file not open\n"); exit(1); } while(fgets(buf, sizeof(buf), fp) != NULL) print_len_word(buf); fclose(fp); printf("%X", len); return 0; } 설명 : ...

2019년 11월 23일 · 1 분 · Sobamemil
💻 개발 & CS시스템 임베디드

시스템 프로그래밍 프로젝트 #6

문제 : 입력 데이터 : [Command.txt 0.00MB](https://blog.kakaocdn.net/dna/bnbU30/btqBgeimBnY/AAAAAAAAAAAAAAAAAAAAAAPakDbTA4jf0WyG_DmDE76emfyLiazho4x1advtOToN/Command.txt?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&expires=1788188399&allow_ip=&allow_referer=&signature=2iAm290NW4CFkRgpHKAQHRqBvxw%3D&attach=1&knm=tfile.txt) 실행 결과 : 코드 : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 #include<stdio.h> #include<string.h> #include<stdlib.h> void PrintAssm(char* name_buf, int name_size); struct OPTAB{ char name[8]; int len; } Wordtab[] = { {"LDA", 3}, {"STA", 4}, {"ADD", 5}, {"TIX", 2}, {"CMP", 6} }; int main() { char name_buf[8]; int wordtab_size = sizeof(Wordtab)/12; // Wordtab에 정의된 단어 갯수, 12 = size of char[8] + int FILE* fp; if((fp = fopen("Command.txt", "r"))==NULL) { printf("file not found...\n"); exit(1); } while(fgets(name_buf, sizeof(name_buf), fp) != NULL) { // fgets() 함수는 scanf나 gets()와는 달리 뒤에 개행문자가 붙는다 if(name_buf[0] == '\n') // name_buf 배열 맨 처음이 개행문자이면 메시지 출력 없이 무시 continue; if(name_buf[strlen(name_buf) - 1] == '\n') // name_buf 배열 맨 끝이 개행문자이면 name_buf[strlen(name_buf) - 1] = '\0'; // naem_buf 배열 맨 끝에 붙은 개행문자 제거 PrintAssm(name_buf, wordtab_size); } fclose(fp); } void PrintAssm(char* name_buf, int wordtab_size){ static int k=1; // 줄 번호를 나타내는 변수 static int loc=0; // 단어의 시작 위치를 나타내는 변수 int i, res=-1; for(i=0; i<wordtab_size; i++){ res = strcmp(name_buf, Wordtab[i].name); // strcmp : 두 문자열이 같으면 0 리턴 if(res==0){ break; } } if(i==wordtab_size){ printf(" Undefined word\n"); // Wordtab 배열 안에 정의되어 있지 않는 명령어면 출력하고 단어 무시 } else{ if(k < 10) printf(" "); printf("%d, %.2X, %s, %.2d\n", k, loc, Wordtab[i].name, Wordtab[i].len); loc += Wordtab[i].len; // 단어의 해당길이를 더해서 다음 시작 위치를 알려줌 k++; } } 설명 : ...

2019년 11월 21일 · 2 분 · Sobamemil
💻 개발 & CSC++ 프로그래밍

명품 C++ programming 실습 문제 9장 8번

문제 : 사각형에 내접하는 도형을 표현하기 위한 Shape 클래스가 있다. 1 2 3 4 5 6 7 8 9 class Shape { protected: string name; // 도형의 이름 int width, height; // 도형이 내접하는 사각형의 너비와 높이 public: Shape(string n="", int w=0, int h=0) { name = n; width = w; height = h; } virtual double getArea() { return 0; } // dummy 값 리턴 string getName() { return name; } // 이름 리턴 }; 문제 7에 주어진 Shape 클래스를 추상 클래스로 만들고 문제 7을 다시 작성하라. ...

2019년 11월 21일 · 2 분 · Sobamemil
💻 개발 & CSC++ 프로그래밍

명품 C++ programming 실습 문제 9장 7번

문제 : 사각형에 내접하는 도형을 표한하기 위한 Shape 클래스가 있다. 1 2 3 4 5 6 7 8 9 class Shape { protected: string name; // 도형의 이름 int width, height; // 도형이 내접하는 사각형의 너비와 높이 public: Shape(string n="", int w=0, int h=0) { name = n; width = w; height = h; } virtual double getArea() { return 0; } // dummy 값 리턴 string getName() { return name; } // 이름 리턴 }; Shape 클래스를 상속받아 타원을 표현하는 Oval, 사각형을 표현하는 Rect, 삼각형을 표현하는 Triangular 클래스를 작성하라. main()을 작성하고 실행하면 다음과 같다. ...

2019년 11월 21일 · 2 분 · Sobamemil
💻 개발 & CSC++ 프로그래밍

명품 C++ programming 실습 문제 9장 6번

문제 : 다음 AbstractStack은 정수 스택 클래스로서 추상 클래스이다. 1 2 3 4 5 6 7 class AbstrackStack { public: virtual bool push(int n) = 0; // 스택에 n을 푸시한다. 스택이 full이면 false 리턴 virtual bool pop(int& n) = 0; // 스택에서 팝한 정수를 n에 저장하고 스택이 empty이면 false 리턴 virtual int size() = 0; }; 이를 상속받아 정수를 푸시, 팝하는 IntStack 클래스를 만들고 사용 사례를 보여라. 목적 및 힌트 : ...

2019년 11월 21일 · 2 분 · Sobamemil
💻 개발 & CSC++ 프로그래밍

명품 C++ programming 실습 문제 9장 5번

문제 : 디지털 회로에서 기본적인 게이트로 OR 게이트, AND 게이트, XOR 게이트 등이 있다. 이들은 각각 두 입력 신호를 받아 OR 연산, AND 연산, XOR 연산을 수행한 결과를 출력한다. 이 게이트들을 각각 ORGate, XORGate, ANDGate 클래스로 작성하고자 한다. ORGate, XORGate, ANDGate 클래스가 AbstractGatef를 상속받도록 작성하라. 1 2 3 4 5 6 7 class AbstractGate { // 추상 클래스 protected: bool x, y; public: void set(bool x, bool y) { this->x = x; this->y = y; } virtual bool operation()=0; }; ANDGate, ORGate, XORGate를 활용하는 사례와 결과는 다음과 같다. ...

2019년 11월 21일 · 2 분 · Sobamemil
💻 개발 & CSC++ 프로그래밍

명품 C++ programming 실습 문제 9장 4번

문제 : 다음 추상 클래스 LoopAdder가 있다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 class LoopAdder { // 추상 클래스 string name; // 루프의 이름 int x, y, sum; // x에서 y까지의 합은 sum void read(); // x, y 값을 읽어드리는 함수 void write(); // sum을 출력하는 함수 protected: LoopAdder(string name="") { // 루프의 이름을 받는다. 초깃값은 "" this->name = name; } int getX() { return x; } int getY() { return y; } virtual int calculate() = 0; // 순수 가상 함수. 루프를 돌며 합을 구하는 함수 public: void run(); // 연산을 진행하는 함수 }; void LoopAdder::read() { // x, y 입력 cout << name << ":" << endl; cout << "처음 수에서 두번째 수까지 더한다. 두 수를 입력하세요 >> "; cin >> x >> y; } void LoopAdder::write() { // 결과 sum 출력 cout << x << "에서 " << y << "까지의 합 = " << sum << " 입니다" << endl; } void LoopAdder::run() { read(); // x, y를 읽는다 sum = calculate(); // 루프를 돌면서 계산한다. write(); // 결과 sum을 출력한다. } LoopAdder 클래스를 상속받아 다음 main() 함수와 실행 결과처럼 되도록 WhileLoopAdder, DoWhileLoopAdder 클래스를 작성하라. while 문, do-while 문을 이용하여 합을 구하도록 calculate() 함수를 각각 작성하면 된다. ...

2019년 11월 21일 · 3 분 · Sobamemil
💻 개발 & CSC++ 프로그래밍

명품 C++ programming 실습 문제 9장 3번

문제 : 다음 추상 클래스 LoopAdder가 있다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 class LoopAdder { // 추상 클래스 string name; // 루프의 이름 int x, y, sum; // x에서 y까지의 합은 sum void read(); // x, y 값을 읽어 들이는 함수 void write(); // sum을 출력하는 함수 protected: LoopAdder(string name="") { // 루프의 이름을 받는다. 초깃값은 "" this->name = name; } int getX() { return x; } int getY() { return y; } virtual int calculate() = 0; // 순수 가상 함수. 루프를 돌며 합을 구하는 함수 public: void run(); // 연산을 진행하는 함수 }; void LoopAdder::read() { // x, y 입력 cout << name << ":" << endl; cout << "처음 수에서 두번째 수까지 더한다. 두 수를 입력하세요 >> "; cin >> x >> y; } void LoopAdder::write() { // 결과 sum 출력 cout << x << "에서 " << y << "까지의 합 = " << sum << " 입니다" << endl; } void LoopAdder::run() { read(); // x, y를 읽는다 sum = calculate(); // 루프를 돌면서 계산한다. write(); // 결과 sum을 출력한다. } LoopAdder 클래스를 상속받아 다음 main() 함수와 실행 결과처럼 되도록 ForLoopAdder 클래스를 작성하라. ForLoopAdder 클래스의 calculate() 함수는 for 문을 이용하여 합을 구한다. ...

2019년 11월 21일 · 3 분 · Sobamemil
💻 개발 & CSC++ 프로그래밍

명품 C++ programming 실습 문제 9장 2번

문제 : 다음은 단위를 변환하는 추상 클래스 Converter이다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 class Converter { protected: double ratio; virtual double convert(double src)=0; // src를 다른 단위로 변환한다. virtual string getSourceString()=0; // src 단위 명칭 virtual string getDestString()=0; // dest 단위 명칭 public: Converter(double ratio) { this->ratio = ratio; } void run(){ double src; cout << getSourceString() << "을 " << getDestString() << "로 바꿉니다. "; cout << getSourceString() << "을 입력하세요>> "; cin >> src; cout << "변환 결과 : " << convert(src) << getDestString() << endl; } }; Converter 클래스를 상속받아 km를 mile(마일)로 변환하는 KmToMile 클래스를 작성하라. main() 함수와 실행 결과는 다음과 같다. ...

2019년 11월 20일 · 2 분 · Sobamemil
💻 개발 & CSC++ 프로그래밍

명품 C++ programming 실습 문제 9장 1번

문제: 다음은 단위를 변환하는 추상 클래스 Converter이다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #include using namespace std; class Converter { protected: double ratio; virtual double convert(double src)=0; // src를 다른 단위로 변환한다. virtual string getSourceString()=0; // src 단위 명칭 virtual string getDestString()=0; // dest 단위 명칭 public: Converter(double ratio) { this->ratio = ratio; } void run(){ double src; cout << getSourceString() << "을 " << getDestString() << "로 바꿉니다. "; cout << getSourceString() << "을 입력하세요>> "; cin >> src; cout << "변환 결과 : " << convert(src) << getDestString() << endl; } }; Converter 클래스를 상속받아 달러를 원화로 환산하는 WonToDollar 클래스를 작성하라. main() 함수와 실행 결과는 다음과 같다. ...

2019년 11월 20일 · 2 분 · Sobamemil