Click here to load reader

Lesson 1 Introduction

  • View
    51

  • Download
    0

Embed Size (px)

DESCRIPTION

Lesson 1 Introduction. James C.C. Cheng Department of Computer Science National Chiao Tung University. Introduction to Computer and Program Design. About Me. 鄭昌杰 Cheng, Chang-Chieh Ph.D. Candidate, department of Computer Science, NCTU Email: [email protected] Office: - PowerPoint PPT Presentation

Text of Lesson 1 Introduction

  • Lesson 1IntroductionIntroduction to Computer and Program Design

    James C.C. ChengDepartment of Computer ScienceNational Chiao Tung University

  • About Me Cheng, Chang-ChiehPh.D. Candidate, department of Computer Science, NCTUEmail: [email protected]:704 (Room 704, MISRC, NCTU)Tel: 03-5712121 # 59268

    *

  • *SyllabusIntroductionC language overviewData Types and VariablesOperators and ExpressionsStatementsPointers, Arrays and Memory ManagementFunctions Standard I/OString processingCustom data type

  • Scoring () 25% () 25% 25%() 25%

    *

  • Why should I take this course? Every thing is computerTo learn the programming technique, becauseyou can design a valuable and interesting computer programthe number of experiment results could be very large.you have to control the instruments by computer

    *

  • *Why should I learn the C and C++For basic computer concepts learningTo design a high performance program Windows programmingGUI (graphical user interface) application softwareMobile software developmentiPhone, iPad iOS applications (apps)Xcode with C++ or Objective CAndroid applicationsGUI JAVAKernel C++

  • *TextbooksC How to program, 6ed By P.J. Deitel & H.M. DeitelPublisher: Prentice Hall Features:Chapter 1: Introduction to computersPlenty exercises

  • *TextbooksThe C programming Language, 2ed Authors: Brian W. Kernighan and Dennis M. RitchiePublisher: Prentice Hall Features:Introduction to the C languageThe first book on C languageAuthors are the creators of C

  • *TextbooksC++ Primer, 4ed By Stanley B. Lippman, Jose Lajoie, Barbara E. Moo Publisher: Addison WesleyFeatures:Introduction to OOP:

  • *Reference BooksThinking in C++ Volume 1 & Volume 2 , 2edby Bruce Eckel, Chuck AllisonFree Electronic Book, http://www.mindviewinc.com/Index.phpFeatures:C++ and OOP

  • *Reference BooksThe C++ Standard Library - A Tutorial and ReferenceBy Nicolai M. JosuttisPublisher: Addison-Wesley Feature:STL tool book :C++

  • *Internet ResourcesMSDN, Microsoft Developer Networkhttp://msdn.microsoft.com/Cplusplus.comhttp://www.cplusplus.com/C++ wikiLink:http://www.cppreference.com/wiki/chm version: http://www.cppreference.com/wiki/_media/about/cppreferencecom_feb09.zipGoogle, Yahoo and programming forums (PTT/Programming)

  • What is a computer?A machine designed to solve some problem.A programmable machineIt can execute a sequence of instructions Mostly, it is a digital system ( binary system): 0/1, true/false, turn on/turn off.It has data storage devicesNon-volatile data storage devices :Punched cards, magnetic tapes, magnetic disks, optical disk, ROM Volatile data storage devices:Transistors, registers, memory, RAM, SDRAM, DDRA communication deviceI/O ports, RS-232, LPT, IDE, SATA, USBEthernet, Internet*

  • *Computer OrganizationAll computers consist of six components

  • *Computer OrganizationThe motherboard of ?Memory 256 MB XDR CPU: Cell Processor PowerPC-base Core 3.2GHz with Northbridge = Memory controllerGPU(Graphics Processing Unit): RSX 550MHz I/O: USB,Sound, Southbridge = I/O controller: Wikipedia

  • Computer OrganizationDesktop motherboard: ASUS P8P67 *I/O: USB, Sound, Network cable CPU socket Intel i7/i5 (LGA1155)Memory socketPower socketSATA socketsPCI slotsPCIe slotsPower socket for CPU: ASUS

  • *Computer OrganizationMemory accessCPUMemoryAddress busData bus Bus: A bundle of electronic signal wires. In 32-bit computer, the bus consists of 32 wires In 64-bit computer, the bus consists of 64 wires

  • Quiz(desktop), ()?*

  • What is programming? (Source code) Machine code 0 1(compile)Program language (( low-level)( high-level)):AssemblyCC++JAVADelphi (Pascal)Microsoft BasicSQL

    *

  • *Programming Flow

  • *C++ IDEDev C++http://www.bloodshed.net/devcpp.htmlGCC-based compilerGCC: GNU Compiler Collection(Open source), (editor) (debugger)

  • *C++ IDECode::Blockshttp://www.codeblocks.org/ Multiple compiler support:GCC (MingW / GNU GCC)MSVC++...and more(Open source), (debugger)

  • *C++ IDEVisual StudioC++ Visual Basic, C# and J#.C++ compiler MS C++ v6.0, VS MFC (Microsoft Foundation Classes) .MFC: !VS 7.0~ use the .NET Framework.Visual Studio Express:

  • *C++ IDEEmbarcadero C++ Builder XE2 (2011)Based on Turbo C++ (1991~2006)HistoryBorland C++ Builder (1997~2006)CodeGear C++ Builder (2006~2008)Embarcadero C++ Builder (2008~)indows MacOS X

  • *C++ IDEQThttp://qt.nokia.com/products/Based on MinGW (Minimalist GNU for Windows)(source code cross-platform)Microsoft WindowsX-WindowsMac OSiOSAndroid

  • The History of the C LanguageC language is created by Dennis Ritchie between 1969 -1972 1989, ANSI C891990, ISO C90 C89 C90 (C89 = C90) 1999, C99 2011, C11C89 is the main development tool in the most embedded systemsBecause C89 is simple, light weight, and high efficient

    *ANSI: American National Standards InstituteISO: International Organization for Standardization Dennis Ritchie 1941-2011: Wikipedia

  • The History of the C++ Language1979, Bjarne Stroustrup develops the C with Classes languageC language with object-oriented programming1983, the C with Classes the C++ language1998, 1st standard version: C++982003, 2nd standard version: C++032011, 3rd standard version: C++11

    *

  • Programming and CodingC *#include #include int main(){ int x = 0; scanf("%d", &x); x = 1 + 2 * 3 / 4; printf ("%d\n", x); system("pause"); return 0;}

  • Programming and CodingC *#include // stdlib.h#include // stdin.h/* C89-style . C89 ! Why? */int main()/*: return_type function_name ( arguments_list ) */{ //main int x = 0; // scanf("%d", &x); // scanf: (standard input device) x = 1 + 2 * 3 / 4; // 1 + 2 * 3 / 4x printf ("%d\n", x); // printf: (standard output device) system("pause"); // ! return 0; /* */}

  • Programming and Coding#include directive()#include The path of SourceFile isDefault_Include_Path/SourceFileThe setting of Default_Include_PathTools / Compiler Options / Directories / C includes #include SourceFile Compiler searches the SourceFile if it is an absolute pathCompiler searches the SourceFile in the current directory if SourceFile is just a filename

    *

  • Programming and CodingCommentsSingle line comment //c89 block comment /* */c89 block comment : *#include #include int main(){ /* int x; /* x = 1 + 2 * 3 / 4; printf ("%d\n", x); */ printf ("Bye!\n", x);*/ system("pause"); return 0;}

  • Programming and Coding block comment*#include #include int main() {#if 0 int x; #if 0 x = 1 + 2 * 3 / 4; printf ("%d\n", x); #endif printf ("Bye!\n", x); #endifsystem("pause"); return 0;}

  • Programming and CodingThe main function C main function . main function (return type and the arguments list ) Simple type of the main function:

    Complete types of the main function:

    *int main( ) {}int main( void ) { // void means empty }int main( int argc, char *argv[ ] ) { } // For UNIX

  • Programming and Coding Variables: (compiler) Ex:

    *int x;// Declare an integerfloat y;// Declare a 32-bit floating-point numberdouble z; // Declare a 64-bit floating-point numberunsigned integer i;// Declare an unsigned integerchar c;// Declare a 8-bit characterchar S[100];// Declare a 100 characters text stringint x;// Declare an integerint x;// Error! Redeclaration of x!float x; // Error! Redeclaration of x!

  • Programming and Coding Multiple variables declaration:

    (initialization)

    *int a, b ,c;// Declare three integersfloat x, y, z, w; // Declare four 32bit floating-point numbersint a = 0, b = 1, c;// a = 0 and b = 1 but c = ?float x = 1.2f, y, z, w = 1.0f;// x = 1.2 and w = 1.0 but y and z = ?// 1.2f means 1.2 is a 32-bit floating-point number// 1.2 means 1.2 is a 64-bit floating-point numberChar S[100] = {0}; // All characters are zero

  • Programming and CodingStatements and Expressions Expressions (variables), (constants), (operators) (function calls) (value). Statements (tokens), (expressions), . (;)*int x;// A declaration statement

    x = 1 + 2 * 3 / 4; /* An assignment statement 1+2*3/ 4 is an expression */

    x = printf("Hello\n"); /*An assignment statement printf("Hello\n"); is an expression */

  • Programming and Coding(L-value)(R-value) !L-value: constantR-value: (),

    *int x, y;x = 1 + 2 * 3 / 4; // x: L-value; 1+2*3/4: R-valuey = x; // y: L-value; x: R-value 1+2*3/4 = y;// error! 1+2*3/4 cannot be a L-valuex+1 = y;// error! x+1 cannot be a L-valueint *p;// p int// p , (pointer)p = x; // error! p x

  • C/C++ Operators - 1*(listed by Wikipedia)

    PrecedenceOperatorDescriptionAssociativity1(highest)::Scope resolution (C++ only)Left-to-right2++Suffix increment--Suffix decrement()Function call[]Array subscripting.Element selection by reference->Element selection through pointertypeid()Run-time type information (C++ only) const_castType cast (C++ only) dynamic_castType cast (C++ only)reinterpret_castType cast (C++ only)static_castType cast (C++ only)3++Prefix incrementRight-to-left--Prefix decrement+Unary plus-Unary minus!Logical NOT~Bitwise NOT(type)Type cast*Indirection (dereference)&Address-ofsizeofSize-ofnew, new[]Dynamic memory allocation (C++ only)delete, delete[]Dynamic memory deallocation (C++ only)

  • C/C++ Operators - 2*(listed by Wikipedia)

    PrecedenceOperatorDescriptionAssociativity4.*Pointer to member (C++ only)Left-to-right->*Poi

Search related