Jie(Jay) Wang Week1 Sept. 30

Slides:



Advertisements
Similar presentations
COSC 120 Computer Programming
Advertisements

What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Your First C++ Program Aug 27, /27/08 CS 150 Introduction to Computer Science I C++  Based on the C programming language  One of today’s most.
1 9/28/07CS150 Introduction to Computer Science 1 Loops section 5.2, 5.4, 5.7.
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
If You Missed Last Week Go to Click on Syllabus, review lecture 01 notes, course schedule Contact your TA ( on website) Schedule.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Programming is instructing a computer to perform a task for you with the help of a programming language.
C++ Programming Language Day 1. What this course covers Day 1 – Structure of C++ program – Basic data types – Standard input, output streams – Selection.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
Course websites CS201 page link at my website: Lecture slides Assistant’s Information Recitations Office Hours Make-up.
3. The Nuts and Bolts of C++ Computer Programming 3. The Nuts and Bolts of C++ 1 Learning the C++ language 3. The Nuts and Bolts of C++
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Fundamental Programming: Fundamental Programming Introduction to C++
Control Structures (B) Topics to cover here: Sequencing in C++ language.
CHAPTER 1: INTRODUCTION C++ Programming. CS 241 Course URL: Text Book: C++ How to Program, DETITEL & DEITEL, eighth Edition.
12/14/2016CS150 Introduction to Computer Science 1 Announcements  Website is up!   All lecture slides, assignments,
CS201 Introduction to Sabancı University 1 Chapter 2 Writing and Understanding C++ l Writing programs in any language requires understanding.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Bill Tucker Austin Community College COSC 1315
Last week: We talked about: History of C Compiler for C programming
C++ First Steps.
Introduction to Computers and C++ Programming
Chapter Topics The Basics of a C++ Program Data Types
CMPT 201.
Chapter 1.2 Introduction to C++ Programming
ANNOUNCEMENT The missed lecture will be made up this Monday evening in the Tech PC classroom (MG51). A tentative time interval is 6:30-8:00. The exact.
Chapter 2: Introduction to C++
Completing the Problem-Solving Process
CS31 Discussion 1E Jie(Jay) Wang Week5 Oct.27.
Computing Fundamentals
Chapter 2 part #1 C++ Program Structure
Basic Elements of C++.
Beginning C++ Programming
Introduction to C++ October 2, 2017.
CSCI 161: Introduction to Programming
Chapter 2: Introduction to C++
Basic Elements of C++ Chapter 2.
Chapter 2 – Getting Started
2.1 Parts of a C++ Program.
Introduction to C++ Programming
Announcements General rules about homeworks
Programming Funamental slides
CS150 Introduction to Computer Science 1
Course websites CS201 page link at my website: Lecture slides
Introduction to C++ Introduced by Bjarne Stroustrup of AT&T’s Bell Laboratories in mid-1980’s Based on C C++ extended C to support object-oriented programming.
Chapter 3: Input/Output
Let’s all Repeat Together
Announcements Homework 1 will be assigned this week,
Chapter 2: Introduction to C++.
Programs written in C and C++ can run on many different computers
Arithmetic Operations
Capitolo 1 – Introduction C++ Programming
Announcements General rules about homeworks
COMS 261 Computer Science I
Introduction to Programming - 1
Chapter 1 c++ structure C++ Input / Output
CS31 Discussion 1H Fall18: week 1
CS31 Discussion 1H Winter19: week 1
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

Jie(Jay) Wang Week1 Sept. 30 CS31 Discussion 1E Jie(Jay) Wang Week1 Sept. 30

About me Jie Wang E-mail: holawj@gmail.com Office hour: Wednesday 3:30 – 5:30 BH2432 Thursday 12:30 – 1:30 BH2432 Slides of discussion will be uploaded to the link: http://cadlab.cs.ucla.edu/~jaywang/teaching/cs31. html

About CS31 7 programming projects Due at 9PM on the dates listed in the website http://web.cs.ucla.edu/classes/fall16/cs31/ Project 1 -> Tuesday, October 4 Grade breakdown: Assignments 40% Midterm 25% Final 35% A request for reconsideration of the grading for an item must be made within one week of our sending you your score for that item.

About the discussion Review and practice things covered during lectures Code examples Clarifications for project assignments Time for you to ask questions!

Outline Review Project 1 Environment setup Compile and debug

Review What is a computer program? A computer program is a collection of instructions that performs a specific task when executed by a computer. To calculate some formulas Online shopping website Games … a C++ program

Review A computer program is written by a computer programmer in a programming language. E.g.: C++, C, java, etc. What is a programming language? It is a language of “medium difficulty” for both us humans and computers. We use it to represent the logic of a program.

Review Example: In English: In a programming language (C++): A set of instructions in English Example: In English: Hey Computer, say “Hello!” In a programming language (C++): In a machine language: 010000101110010… You (Programmer) C++ Program Compiler(visual c++, clang++, g++) Program in binary (executable)

Our first program Include the library <iostream> to use “cout” Use the namespace std (standard) namespace is a collection of name definitions a function name can have different definitions in two namespaces #include <iostream> using namespace std; int main() { cout << “Hello!” << endl; } Main() function: where the C++ program begins executing An instruction to print “Hello” in the screen. endl -> to end the line

Let’s try to compile it! Clang++(Xcode) Visual C++ g++: g31 -o hello hello.cpp

Variables Output: x = 5, y = 6 Declare a variable datatype identifier int: integer, 4 bytes long, ranging from -2,147,483,647 to 2,147,483,647 Double: real numbers, 8 bytes long, ranging from -1.7× 10 308 to 1.7× 10 308

Variables √ √ √ Identifiers There are variable naming rules. An identifier must begin with an alphabetic character (a-z or A-Z) or an underscore (‘_’), which may be followed by alphabetic/numeric (0-9) characters and underscores. Violating any of these rules will result in a compile error. Question: Which ones of these are valid identifiers? los angeles computer_science engineering bruin@ucla.edu C++ 5272BH cs31 √ √ √

Variables Identifiers Case sensitivity Question: Do engineering and Engineering refer to the same variable?

Comments We use /* ... */ and // for making notes in the code for ourselves. Text within /* and */ (which can span over multiple lines), and everything after // and before the end of the line are not considered to be part of the code. We call such text a comment and say that part of the code is commented out.

Errors/Bugs

Errors/Bugs Compilation/Syntax Errors Errors in which the programmer has violated a portion of the language syntax (the language structure). These will prevent the code from compiling. Some common syntax errors: Missing semicolons at ends of statements Missing brackets around blocks Missing namespace or #include definitions Misspelled variables or names

Errors/Bugs Runtime/logic errors: Errors that might compile successfully, but encounter an error during runtime that either causes the program to break or produces unexpected (read: wrong) results. Some common runtime errors: Division by 0 Overflow (e.g.: trying to hold a really big number in an int variable that exceeds its bounds)

Errors/Bugs Question: Find the error in the following code snippet. Is it an syntax or a runtime error? int main() { int age = 32; double weight = 56; cout << “age: ” << Age << “ weight: ” << weight << endl; }

Errors/Bugs Question: What could possibly go wrong during runtime with the following program? #include <iostream> using namespace std; int main() { double numerator, divisor, result; cout << “Please enter the numerator: ”; cin >> numerator; cout << “Please enter the divisor: ”; cin >> divisor; result = numerator / divisor; cout << “The quotient is: ” << result << endl; }

Errors/Bugs Question: Will the following code compile? If so, what value will be printed? #include <iostream> using namespace std; int main() { int x; cout << x << endl; } When a primitive variable is not initialized (i.e., set to some value like int x = 5;), it will have unpredictable junk value.

Errors/Bugs Question: Will the following code compile? If so, what value will be printed? #include <iostream> using namespace std; int main() { double i_declare_war-or-just_this_var = 1; cout << i_declare_war-or-just_this_var << endl; }

Errors/Bugs Question: Will the following code compile? If so, what value will be printed? #include <iostream> using namespace std; int main () { int numerator = 5; int divisor = 2; int result = numerator / divisor; cout << result << endl; }

Project 1 One difficult point In step 5, find input integer values that cause it to product incorrect, unusual, or nonsensical results. (Notice that the instructions say to use input integer values, not input like 12324.435 or “computer”.) Normal results: 0 ~ 100% Incorrect results: -19.5%, 1200%, two percentages whose sum is not 100%, …

Project 1 The zip file you submit must follow the instructions exactly. (Pay attention to the name of each cpp file and your zip file) Late submissions will be penalized. Your code should run successfully under two compilers: g++ with linux and either Visual C++ or clang++ (Xcode). Demo of g++

Credit to 3 previous CS31 TAs This slide is finished with reference from: Andrew Forney http://web.cs.ucla.edu/~forns/ Brian Choi http://netlab.cs.ucla.edu/~schoi/cs31/ Muhao Chen http://yellowstone.cs.ucla.edu/~muhao/cs31f15/cs31f1 5.html

Thanks!