25
CS2400 Lecture 1 -1- ©2017 David M. Chelberg Lecture 1: CS2400 Introduction to Computer Science • Introduction to the course • Introduction to computers • Ethics • Programming • C++

Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

  • Upload
    lamnhi

  • View
    222

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -1- ©2017 David M. Chelberg

Lecture 1: CS2400 Introduction to Computer Science • Introduction to the course • Introduction to computers • Ethics • Programming • C++

Page 2: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -2- ©2017 David M. Chelberg

Computer Science What is computer science?

• Using computers • Mathematics/Logic • Science • Engineering • Communication • Everything? Multidisciplinary!

Why do you study it? To Solve Problems!

Page 3: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -3- ©2017 David M. Chelberg

A Brief History of Computer Science • Abacus 1000 BC • Napier's Bones AD 1614 • Slide Rule 1700's • Mechanical Adding Machines 1800's • Tabulating Machines (early IBM) 1930 • Vacuum Tubes ENIAC 1945 • Machine Language • Transistors/Magnetic Core 1950's-1960's • Assemblers/Compilers UNIVAC 1 IBM 704

Page 4: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -4- ©2017 David M. Chelberg

• IC's OS/Timesharing 1960's-1970's • Supercomputers • Microprocessors 1980's/ Workstations • Networking, WWW, Nintendo 64, etc.

Page 5: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -5- ©2017 David M. Chelberg

Three classes of Computers: • PCs • Workstations • Mainframes

Page 6: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -6- ©2017 David M. Chelberg

Main Components of a Computer • Input devices • Output devices • Secondary Memory • Main Memory • CPU ° Arithmetic/logic Unit ° Control Unit

Page 7: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -7- ©2017 David M. Chelberg

Memory What is memory? bit - binary digit bytes - an 8-bit portion of memory address memory location - a group of memory that holds a datum

Page 8: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -8- ©2017 David M. Chelberg

Codes A code is a way of representing data in the computer. Example ASCII (American Standard Code for Information Interchange) - the letter A is represented as: 01000001 But this is also the code for the number 65.

Page 9: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -9- ©2017 David M. Chelberg

Secondary Memory The memory that we have been talking about so far is the main memory, used to execute computer programs. There is also secondary memory in a computer. What is its use? Information kept in secondary storage are kept in units called files. Examples of secondary memory:

Page 10: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -10- ©2017 David M. Chelberg

Secondary Memory The memory that we have been talking about so far is the main memory, used to execute computer programs. There is also secondary memory in a computer. What is its use? Information kept in secondary storage are kept in units called files. Examples of secondary memory: hard disks, pen drives, diskettes, CD-ROM.

Page 11: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -11- ©2017 David M. Chelberg

CPU The “BRAIN” of the computer. What can a CPU do for you?

Page 12: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -12- ©2017 David M. Chelberg

CPU The “BRAIN” of the computer. What can a CPU do for you? ALU - arithmetic, logic Control Unit - executes the code, branches, fetches memory, etc.

Page 13: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -13- ©2017 David M. Chelberg

Operating System Windows 7, Windows 10 Unix/Linux MacOs ios What does an operating system do for your computer?

Page 14: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -14- ©2017 David M. Chelberg

A Program What is a program?

Page 15: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -15- ©2017 David M. Chelberg

A Program What is a program? A program is a set of instructions for a computer to follow. Input to the computer is a program and some data. data is the input to the program running a program data is also said to be any information available to the computer.

Page 16: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -16- ©2017 David M. Chelberg

Computer Languages • High-level C, Pascal, FORTRAN, BASIC, COBOL, Lisp, Scheme, Ada, Modula-2, SmallTalk, Prolog, and C++. • Low-level Assembler • Machine language Main difference between high-level and machine-language -- high-level languages must be translated into machine language to be executed.

Page 17: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -17- ©2017 David M. Chelberg

Why Study C++? C++ is a superset of C. C was developed to write the UNIX operating system. Problems with C: • It encourages programmers to write large

systems that lack structure! • It encourages beginning programmers to

learn bad habits - writing code that is difficult to read and maintain.

• C lacks many of the fail-safe features of modern programming languages.

Page 18: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -18- ©2017 David M. Chelberg

C++ was developed in the 1980's by Bjarne Stroustrup. It has all the bad features of C, but also has additional features. If the additional features are properly used, they can alleviate many of the problems with C. In particular, C++ supports object-oriented programming. C++ is a much larger and more sophisticated language than C. We will be studying a subset that is manageable.

Page 19: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -19- ©2017 David M. Chelberg

Compilers A compiler is a program that translates a high-level language (C++) to a machine-language. What is the input to the compiler? What is the output?

Page 20: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -20- ©2017 David M. Chelberg

Compilers A compiler is a program that translates a high-level language (C++) to a machine-language. What is the input to the compiler? source program, or source code What is the output? object program, or object code

Page 21: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -21- ©2017 David M. Chelberg

How to run a C++ program 1.) write the code and place in a file. 2.) 3.) 4.)

Page 22: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -22- ©2017 David M. Chelberg

How to run a C++ program 1.) write the code and place in a file. 2.) run the compiler on the program 3.) link the machine code to other existing code 4.) run the resulting machine code

Page 23: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -23- ©2017 David M. Chelberg

Programming and Problem-Solving Computers are STUPID!! In order to get them to do what we want we must be extremely precise in how we order them to do it. This process is the process of writing an algorithm. The subsequent step of converting the algorithm to a particular computer language is called coding.

Page 24: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -24- ©2017 David M. Chelberg

The hardest part of most programming problems is to come up with the algorithm. Once that is done, coding the problem becomes much easier. Definition: an algorithm is a sequence of precise instructions that leads to a solution.

Page 25: Lecture 1: CS2400 Introduction to Computer Scienceoucsace.cs.ohiou.edu/~chelberg/classes/2400/lec01.pdf · C, Pascal, FORTRAN, BASIC, COBOL, Lisp ... • Machine language Main difference

CS2400 Lecture 1 -25- ©2017 David M. Chelberg

Example: Write an algorithm to write your name on the blackboard.