Download presentation
Presentation is loading. Please wait.
Published by태승 양 Modified 8년 전
1
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 실 습실 습 1
2
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 2 목적 1. 실습에 사용할 C++ 환경 익히기 2. 프로그램 설계 & 알고리즘 개발 기초 이해 3. C++ 프로그램 열기 / 컴파일 / 실행하기 4. 구문 / 실행 오류를 가진 프로그램 수정하기 5. 논리 오류를 가진 프로그램 수정하기 6. 작은 프로그램의 독립적인 개발과 실행
3
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 3 실습환경 Compiler(Integrated Dev. Environment) - Microsoft Visual C++ 6.0 - Borland C++ - Gcc (UNIX)
4
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 4 Microsoft Visual C++ 6.0
5
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 5 Lab 1.1 First C++ Program Exercise 1: Logon Exercise 2: http://ce.kyungil.ac.kr/~kykim/OOP2009/Lab 에서 download firstprog.cpp Exercise 3: firstprog.cpp 를 컴파일 Exercise 4: 실행 후 화면에 출력되는 것은 ?http://ce.kyungil.ac.kr/~kykim/OOP2009/Lab // This is the first program that just writes out a simple message. // Place your name(student ID) here #include // needed to do C++ I/O using namespace std; int main () { cout << "Now is the time for all good men" << endl; cout << "to come to the aid of their party." << endl; return 0; } firstprog.cpp
6
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 6 Lab 1.2 Compiling a Program with a Syntax Error Exercise 1: http://ce.kyungil.ac.kr/~kykim/OOP2009/Lab 에서 download semiprob.cpp Exercise 2: semiprob.cpp 를 컴파일 오류 메시지는 ? semiprob.cpp(12) : error C2146: syntax error : missing ';' before identifier 'cout' Exercise 3: 오류를 수정하고 다시 컴파일 오류가 없다면 실행시키고 입력 값으로 9 를 입력하고 출력되는 결과는 ? Exercise 4: 입력 값으로 다른 값을 사용하여 실행한 후 출력 결과를 말해보시오.http://ce.kyungil.ac.kr/~kykim/OOP2009/Lab
7
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 7 // This program demonstrates a compile error. // Place your name(student ID) here #include using namespace std; int main() { double number; double total; cout << "Today is a great day for lab." cout << endl << "Let's start off by typing a number of your choice." << endl; cin >> number; total = number * 2; cout << total << " is twice the number you typed." << endl; return 0; } semiprob.cpp 오류
8
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 8 Lab 1.3 Running a Program with a Run-Time Error Exercise 1: http://ce.kyungil.ac.kr/~kykim/OOP2009/Lab 에서 download runprob.cpp Exercise 2: runprob.cpp 를 컴파일 구문오류가 없음을 확인 ! Exercise 3: 프로그램 실행 실행 오류 수정 후 ( 분모의 0 2) Exercise 4: 다시 컴파일, 실행 입력 값으로 9 를 입력하고 출력 결과를 말해볼 것. Exercise 5: 입력 값으로 다른 값을 사용하여 실행한 후 출력 결과를 말해보시오.http://ce.kyungil.ac.kr/~kykim/OOP2009/Lab
9
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 9 // This program will take a number and divide it by 2. #include using namespace std; int main() { double number; int divider; divider = 0; cout << "Hi there!" << endl; cout << "Please input a number and then hit return." << endl; cin >> number; number = number / divider; cout << "Half of your number is " << number << endl; return 0; } runprob.cpp
10
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 10 Lab 1.4 Working with Logic Errors (swap two values) Exercise 1: http://ce.kyungil.ac.kr/~kykim/OOP2009/Lab 에서 download logicprob.cpp Exercise 2: logicprob.cpp 를 컴파일 구문오류가 없음을 확인 ! Exercise 3: 프로그램 실행, 실행 오류 확인 ! 출력 값 확인 ? Exercise 4: 구문 오류 (X), 실행 오류 (X) 논리 오류 not easy to findhttp://ce.kyungil.ac.kr/~kykim/OOP2009/Lab
11
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 11 // This program takes two values from the user and then swaps them // before printing the values. The user will be prompted to enter // both numbers. #include using namespace std; int main() { double firstNumber; double secondNumber; //Prompt user to enter the first number. cout << "Enter the first number" << endl; cout << "Then press the ENTER key" << endl; cin >> firstNumber; // Prompt user to enter the second number. cout << "Enter the second number" << endl; cout << "Then press the ENTER key" << endl; cin >> secondNumber; logicprob.cpp
12
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 12 // Echo the input. cout << endl << "You input the numbers as " << firstNumber << " and " << secondNumber << endl; // Now we will swap the two values. firstNumber = secondNumber; secondNumber = firstNumber; // Output the values. cout << "After swapping, the values of the two numbers are " << firstNumber << " and " << secondNumber << endl; return 0; }
13
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 13 Lab 1.5: Writing Your First Program Exercise 1: 여행거리에 대한 실수 값을 킬로미터 단위로 입력 받아 마일로 변환하는 프로그램 (kilometer.cpp) 을 작성하라. 단 1 km = 0.621 miles Exercise 2: kilometer.cpp 를 컴파일하고 구문 오류가 없을 때까지 수정 및 재컴파일하라. Exercise 3: 실행하고 그 결과를 기대치와 비교하여 보라. 논리적인 오류가 있다면 수정하고 다시 실행하여 보자. 올바른 결과가 출력될 때까지 이 과정을 반복하여 보자 Note: The program in that lab uses everything needed to complete Lab 1.5: an introductory comment, required preprocessor directives, a main function with a return statement, input and output statements, simple computation, and an optional) ssignment statement.
Similar presentations