Docsity

TCP1121 Computer Programming: C++ Fundamentals and Advanced Topics, Lecture notes of Computer Programming

Partial preview of the text

Download TCP1121 Computer Programming: C++ Fundamentals and Advanced Topics and more Lecture notes Computer Programming in PDF only on Docsity!

Welcome to…

TCP1121 Computer Programming

Teaching Staffs

• Ms. Chong Siew Chin (TMB 05)

– Email: [email protected]

– Office: ITAR 2014

• Mr. Rouzbeh Behnia (TMB 06)

– Email: [email protected]

– Office: ITAR 0005

• Ms. Ho Yen Li

– Email: [email protected]

– Office: ITAR 3077

Week Lectures Code Topics Book Chapter s 1 Lec01 C++ Fundamentals (pt 1) 1- 2 Lec02 C++ Fundamentals (pt 2) 1- 3 Lec03 Arrays and Pointers (pt1) 7 4 Lec04 Arrays and Pointers (pt2) 7 5 Lec05 Functions (pt 1) 4- 6 Lec06 Functions (pt 2) 4- 7 Lec07 Defining Classes (pt 1) 10- 8 Lec08 Defining Classes (pt 2) 10- 9 Lec09 Dynamic Memory Allocation 9 10 Lec10 Inheritance and Polymorphism (pt 1) 15 11 Lec11 Inheritance and Polymorphism (pt 2) 15 12 Lec12 Advanced Topic

13 Lec13 File Handling 6 14 Lec14 Presentation Textbook (^) Walter Savitch. (2011). Problem Solving with C++ (9th ed.). Addison Wesley. Reference Book (if any) 1. Tony Gaddis, Judy Walters, Godfrey Muganda. (2011). Starting out with C++: Early Objects (7th ed.). Addison Wesley.

  1. Paul Deitel, Harvey Deitel. (2011). C++ How to Program (8th ed.). Prentice Hall.
  2. Y. Daniel Liang. (2013). Introduction to Programming with C++ (3rd ed.). Prentice Hall. Software (if any) Code::Blocks

Lecture sessions: 2 hrs + 1 hr

Lab sessions: 2 hrs

Lecture 1

C++ Fundamentals

1.1 Introduction to C++ 1.2 Structure chart, Flowchart and Pseudo code 1.3 Debugging and documentation techniques 1.4 Variables and Assignments 1.5 Input and Output 1.6 Data Types and Expressions

C++ program Basic C++ structure

  • (^) A normal C++ programs has 3 components
    1. Preprocessor
    2. User defined
    3. Main function
      1. Preprocessor e.g.: #include Usually used to indicate other files (libraries) to compile and defining constants
  1. User defined (function, class, etc) e.g.: void printHello () { cout << “Hello”; } Used when user requires creation of problem specific solution
  2. Main function e.g.: int main() {…} Every program in C++ must have one and only one main function

A Simple C++ Program  (^) A simple C++ program begins this way #include using namespace std; int main() {  (^) And ends this way return 0; }

My first program in C++ // my first program in C+ + #include using namespace std; int main () { cout << "Hello World!"; return 0; Hello World! a comment line a pound sign (#) is a directive for the preprocessor. It is not executable code but indications for the compiler. tells the compiler's preprocessor to include the iostream standard header file. Corresponds to the beginning of the main function declaration. The main function is the point where all C++ programs begin their execution. cout is the standard output stream in C++ to terminate a program

Layout of a Simple C++ Program #include using namespace std; int main() { variable_declarations statement_ statement_ … statement_last return 0; }

Program Layout (2/2)

 Variables are declared before they are used

 Typically variables are declared at the beginning of

the program

 Statements (not always lines) end with a semi-colon

 Include Directives

#include

 Tells compiler where to find information about items

used in the program

 iostream is a library containing definitions of cin and cout

Program Layout

using namespace std;

 Tells the compiler to use names in iostream in

a “standard” way

 To begin the main function of the program

int main()

 To end the main function

return 0;

 Main function ends with a return statement

Running a C++ Program  (^) C++ source code is written with a text editor  (^) The compiler on your system converts source code to object code.  (^) The linker combines all the object code into an executable program.

Run a Program  (^) Write code  (^) Compile the code  (^) Fix any errors the compiler indicates and re-compile the code  (^) Run the program Now you know how to run a program on your system

1.2 Structure Chart, Flowchart

and Pseudo Code

Program Design  (^) Programming is a creative process  (^) No complete set of rules for creating a program  (^) There are many ways to solve the same problem  (^) Each student will have their own unique style  (^) Program Design Process

  1. Problem Solving Phase
    • (^) Result is an algorithm that solves the problem
  2. Implementation Phase
    • (^) Result is the algorithm translated into a programming language