Download - Fundamentals of Computer Science
![Page 1: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/1.jpg)
Fundamentals of Computer Science
Ethan CeramiNew York University
Spring 2000
![Page 2: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/2.jpg)
Today
• Course Description– Or, what am I getting myself into?
• Exams, Grades, Course Web Page, etc.
• The Lego Theory and the Course Syllabus
• What’s a Programming Language?
• Why Learn C?
• “Hello, World!” Program– Your first taste of real programming.
![Page 3: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/3.jpg)
How do I get these slides?
• Occasionally, I will use present PowerPoint slides.
• Whenever I do so, I will post them to the course web page:
Go to http://cs.nyu.eduClick on Course Home PagesClick on V22.0380.002 Course Home Page
![Page 4: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/4.jpg)
Why is this class so *%&#*@#! Early?
• Yes, class starts at 8:00 am.• Last semester, class started at
8:30 am. This semester, NYU gets cruel ;)
• Please try and stay awake!• We will usually have a break
at around 8:45. So, go get coffee.
![Page 5: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/5.jpg)
Course Description
• Official Description: This is a course in computer programming concepts for students with little or no programming experience. The intent is to teach students to write both clear and efficient C programs by emphasizing structured programming principles. This course is intended as a first course for information systems majors, for students of other scientific disciplines, and for a functional introduction to programming.
![Page 6: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/6.jpg)
What the class is really about
There are four main goals of this course:
1. Basics of C
2. Core Concepts of Programming Languages
3. Basics of Software Development
4. Extra Topics
![Page 7: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/7.jpg)
1. Learn the Basics of C Programming
• C is a popular programming language, widely used in Industry.• We will learn all the specifics of how to program in C.• This includes all the peculiar rules that are specific to C.• We will cover all the fundamentals: Variables, For Loops, While Loops, Arrays, Pointers, Structures, etc.
![Page 8: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/8.jpg)
For Example
/* Sample C Program */
#include <stdio.h>
#define MAX_NUM 10
main () {
int i;
for (i=0; i<MAX_NUM; i++) {
printf ("Number: %d\n", i);
}
return 0;
}
This program counts from 1 to 10. In a few weeks, it will all make sense.
![Page 9: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/9.jpg)
2. Learn the Core Concepts of all Programming Languages
• There are lots of programming languages available: Pascal, Java, Ada, Lisp, Perl.
• All of these languages share core concepts.• By focussing on these concepts, you are better able to
learn any programming language.• Hence, by learning C, you are poised to learn other
languages, such as C++ or Java.• By learning the core concepts, you are also much more
marketable as you are able to learn new technologies much faster.
![Page 10: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/10.jpg)
For Example: For Loops
• C has a construct called a for loop that enables a program to repeat actions over and over.
• Every other language also has a for loop.
• Hence, by learning about for loops in C, you can easily learn for loops in C++ or Java.
![Page 11: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/11.jpg)
3. Learn the Principles of Software Development
• Building high quality software is very difficult.• The course therefore presents the syntax and
concepts of programming, but also presents strategies for building real software that addresses real problems.
• I will also try to bring real-world industry experience to class.
![Page 12: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/12.jpg)
For Example: Principle 61: “Transition from specification to code is not easy.”*
Specification for building an Airline Reservation System
Actual Software that gets the job done.
* Alan M. Davis, “201 Principles of Software Development”, (McGraw Hill, Inc, 1995.)
![Page 13: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/13.jpg)
4. Extra Topics
“Try to imagine all the new kinds of computers that will arrive in the next generation or two. Imagine what we -- actually our children and grandchildren -- will do with them all. One thing is sure: whatever wild visions you can conjure are too tame.”
-- Peter J. Denning, “Beyond Calculation: The Next Fifty Years of Computing” (ACM: 1997.)
![Page 14: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/14.jpg)
Extra Topics in the Past
• DigiScents: computers capable of producing smells (!)
• TCP/IP: understanding how the Internet routes packets to the correct destination.
• Virtual Reality and 3D Chat• Computer Animation• The technology behind Burger King’s
Whopper.
![Page 15: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/15.jpg)
On to Administrative Issues...
• Books
• Software
• Grades
• Getting Help
• Course Home Page
![Page 16: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/16.jpg)
Required Text Book
Deitel and Deitel,
C: How to Program
Very comprehensive text book.
Available at the NYU Book Store.
![Page 17: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/17.jpg)
Supplemental Book
Kernighan and Ritche, The C Programming Language
-- Written by the creators of C.
-- A good reference, but not an easy read.
![Page 18: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/18.jpg)
Annotated Programs Packet
• Word Document that contains all the programs to be discussed in class.
• Available on the Course Web Site.• Some are taken from the book, some were created in
previous semesters.• You can also download all the programs directly from
the web site, and try them out within your own compiler.
• Please bring the packet to every class!
![Page 19: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/19.jpg)
Software
• We will use the Borland C++ compiler.• Borland C++ is available in some Stern Labs and all
the ACF Labs.• You can also purchase an academic version for ~$50
from the NYU Computer Bookstore.• If you buy a copy, you want to buy Borland C++
Builder 4.0, and install the CD named, “Borland C++, Version 5.0” (you won’t need the other CDs for this class.)
![Page 20: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/20.jpg)
Other things you will need
• Email Account: All homework assignments must be submitted via E-Mail.
• Floppy Disks: If you are planning on using the NYU Computer Labs, make sure to save your programs to a floppy disk.
![Page 21: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/21.jpg)
Grading
• All homework must be done individually. The Grader will be checking for cheating.
• Also, see the late policy on our web site.
• How your grade is determined: homework: 40% midterm exam: 25% final exam 35%
![Page 22: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/22.jpg)
Getting HelpMany students find this course very challenging. When you get stuck, ask for help!
1. Office Hours: Every Thursday, 9:30 am - 11:30 am, 419 Warren Weaver Hall.
2. E-Tutor: E-Tutor is required to write back in 24 hours. (See Web Page for
E-Tutor’s Email Address.)
3. Yahoo! Club: Write your questions here, and other students might be able to help out.
![Page 23: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/23.jpg)
Course Home Page
• Everything regarding the course is available via the Course Home Page. So, check it early and often.
• How to get to the Home Page:Go to http://cs.nyu.eduClick on Course Home PagesClick on V22.0380.002 Course Home Page
![Page 24: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/24.jpg)
The Lego Theory
The Lego Theory: Complex software is built with simple,
basic building blocks.
Check out: http://www.lego.com/justbuild/buildpage.asp
![Page 25: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/25.jpg)
Lego Theory (cont.)
• Lego theory goes by many different names: abstraction, “divide and conquer”, object orientation, etc.
• Nonetheless, it represents the most powerful idea in computer science, and the most important thing you will learn this semester.
• If nothing else, I hope you remember the Lego theory five years from now.
![Page 26: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/26.jpg)
Lego Theory Applied: Basic Example
Lego Block: For loop for repeating
actions
Suppose you want to print your name five times.
Lego Block: Printf()for displaying yourname
Main Lego Block: For Coordinating
everything
![Page 27: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/27.jpg)
Lego Theory Applied: Searching the Web
• Suppose you want to build a piece of software that searches the web.
Lego Block 2: Huge storage of web sites.
Lego Block 3: Formats the results in a nice graphical interface.
Lego Block 1: Retrieves user search keyword and sends the query to Lego Block 2. Once it has results from Lego Block 2, send it to Lego Block 3
![Page 28: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/28.jpg)
Searching the Web (cont.)
• By using the Lego Theory, you break complicated tasks into smaller, simpler subtasks.
• You can also more easily divide up the work, and more easily figure out where things go wrong.
![Page 29: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/29.jpg)
How we will use the Lego Theory
• Each week, we will introduce a new basic building block. For example, this week we will cover input and output. Later on, we will cover variables.
• By combining these blocks, we can start creating more and more powerful programs.
• By the end of the semester, you will have all the basic blocks for building very sophisticated software.
![Page 30: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/30.jpg)
Syllabus: First Half of Semester
• Week 1: Basic Input/Output
• Week 2: Variables, Basic Mathematics
• Week 3: If/Else, While Loops
• Week 4: For Loops, Logical Operators
• Week 5-7: Functions
![Page 31: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/31.jpg)
What’s a Programming Language?
• Programming Language: A language used to create computer applications.
• Examples of Programming Languages: C C++ Pascal Java (Internet) Cobol (COmmon Buisiness Oriented Language) Ada (mainly used by Department of Defense)
![Page 32: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/32.jpg)
Why Learn C?
So, why pick C?
1. It’s a very powerful, very fast language.
2. C is one of the most widely used languages. People use it in the ‘real world’
3. It forms the basis of more advanced languages, such as C++ and Java.
![Page 33: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/33.jpg)
C v. Pascal
• Lots of other introductory classes focus on Pascal.
• Pascal is easier to program, but it’s only used in Academic settings. And, this course tries to focus on practical business applications.
• "Pascal keeps your hand tied. C gives you enough rope to hang yourself."
![Page 34: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/34.jpg)
History of C
• Developed in 1972 at Bell Labs (now part of Lucent Technologies)
• C does not stand for anything: C evolved from a language called B (which also didn’t stand for anything.)
![Page 35: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/35.jpg)
ANSI C– ANSI C: American National Standards Institute
Standard C that runs on most operating systems. There are lots of operating systems currently is
use: Windows, Macintosh, UNIX, IBM Mainframes. You can run ANSI C on any of these platforms.
• Portable: a program that runs on more than one operating system.
![Page 36: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/36.jpg)
Your first C Program
/* First Program in C */#include <stdio.h>
main(){ printf("Hello, World!");
/* Wait for user to Press Enter */ getchar();}
Hello, World!
![Page 37: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/37.jpg)
Comments
/* First Program in C */ Text that helps you and others to understand the program Completely ignored by the computer Anything between /* and */ A Program with no comments is a very bad program.
Tip: You must include comments in your homeworks.
![Page 38: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/38.jpg)
#include <stdio.h>
#include tells the compiler to include certain library files.
stdio.h stands for Standard Input/Output header file
stdio.h is required any time you use printf or scanf.
Other libraries: math.h, graphics.h
![Page 39: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/39.jpg)
main () function
Every C program must have a main function. Every program begins execution at the main
function. No matter how big your program, you must
always have a main(). We will return to a formal definition of
functions later.
![Page 40: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/40.jpg)
Blocks of Code
{} Any code between { and } is considered a
block of code. In this case, anything between { and } is
considered part of the main function. Hence, when we run main, we will run
everything within the {} block.
![Page 41: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/41.jpg)
printf("Hello, World!");
Displays a string of text. String: any text appearing within quotes. Printf is an example of a statement. Note that all statements in C end with a
semi-colon.
![Page 42: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/42.jpg)
/* Wait for user to Press Enter */ getchar();
• getchar() pauses the program until the user presses the ENTER key.
• As we will soon see, this pause is important when running programs under Borland C++.
• Without the getchar(), the program will run and exit so fast that you will not see any output.
![Page 43: Fundamentals of Computer Science](https://reader035.vdocuments.mx/reader035/viewer/2022062217/568134e5550346895d9c16e3/html5/thumbnails/43.jpg)
Quick Recap/* First Program in C */#include <stdio.h>
main(){ printf("Hello, World!");
/* Wait for user to Press Enter */ getchar();}
main () function
#include library
Comments
Block of Code
printf()