CS 31 Discussion 1A, Week 1. Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50

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

Week 1: Hello World! Muhao Chen

Your First C++ Program. September 1, 2010

CS 31 Discussion 1A, Week 4. Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50 a.m.

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

Welcome to MCS 360. content expectations. using g++ input and output streams the namespace std. Euclid s algorithm the while and do-while statements

CS31 Discussion 1E. Jie(Jay) Wang Week5 Oct.27

Review. Modules. CS 151 Review #6. Sample Program 6.1a:

More Examples Using Functions and Command-Line Arguments in C++ CS 16: Solving Problems with Computers I Lecture #6

Tutorial 2: Compiling and Running C++ Source Code

Understanding main() function Input/Output Streams

Outline. Review of Last Week II. Review of Last Week. Computer Memory. Review Variables and Memory. February 7, Data Types

Chapter 1: Why Program? Computers and Programming. Why Program?

Lecture 5. Review from last week. Selection Statements. cin and cout directives escape sequences

CS102 Unit 2. Sets and Mathematical Formalism Programming Languages and Simple Program Execution

CIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts)

4. Structure of a C++ program

COMP322 - Introduction to C++ Lecture 01 - Introduction

Compiling C++ Programs Flow Control in C++ CS 16: Solving Problems with Computers I Lecture #3

More Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4

CS 31 Discussion 1A, Week 8. Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50 a.m.

CS 106B, Lecture 1 Introduction to C++

Programming with C++ as a Second Language

Command-line interface DOS Graphical User interface (GUI) -- Windows

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Computer Science II Lecture 1 Introduction and Background

1 Unit 8 'for' Loops

Chapter 2 C++ Fundamentals

DOMjudge team manual. Summary. Reading and writing. Submitting solutions. Viewing scores, submissions, etc.

C++ for Python Programmers

CS 11 C++ track: lecture 1

CS11 Intro C++ Spring 2018 Lecture 1

Scientific Computing

Once you have installed MobaXterm, open MobaXterm. Go to Sessions -> New Session, and click on the SSH icon.

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

Week 0: Intro to Computers and Programming. 1.1 Why Program? 1.2 Computer Systems: Hardware and Software. Hardware Components

DOMjudge team manual. Summary. Reading and writing. Submitting solutions. Viewing scores, submissions, etc.

Announcements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy

DOMjudge team manual. Summary. Reading and writing. Submitting solutions. Viewing scores, submissions, etc.

Lab 2.1: Fixing a C++ program

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

assembler Machine Code Object Files linker Executable File

1. C++ Overview. C++ Program Structure. Data Types. Assignment Statements. Input/Output Operations. Arithmetic Expressions.

Do not turn to the next page until the start of the exam.

Unit 7. 'while' Loops

[Page 177 (continued)] a. if ( age >= 65 ); cout << "Age is greater than or equal to 65" << endl; else cout << "Age is less than 65 << endl";

Computer Programming : C++

8. The C++ language, 1. Programming and Algorithms II Degree in Bioinformatics Fall 2017

CS 376b Computer Vision

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++

EP241 Computer Programming

Today in CS161. Lecture #7. Learn about. Rewrite our First Program. Create new Graphics Demos. If and else statements. Using if and else statements

Discussion 1E. Jie(Jay) Wang Week 10 Dec.2

DOMjudge team manual. Summary. Reading and writing. Submitting solutions. Viewing scores, submissions, etc.

LAB #8. Last Survey, I promise!!! Please fill out this really quick survey about paired programming and information about your declared major and CS.

Introduction to C ++

Functions that Return a Value. Approximate completion time Pre-lab Reading Assignment 20 min. 92

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:

6 Functions. 6.1 Focus on Software Engineering: Modular Programming TOPICS. CONCEPT: A program may be broken up into manageable functions.

CS2141 Software Development using C/C++ Compiling a C++ Program

CMPE110 - EXPERIMENT 1 * MICROSOFT VISUAL STUDIO AND C++ PROGRAMMING

CS246-Assign01 V1.1: Winter 2013

Unit 14. Passing Arrays & C++ Strings

Security Coding Module - Buffer Overflow Data Gone Wild CS1

DOMjudge team manual. Summary. Reading and writing. Submitting solutions. Viewing scores, submissions, etc.

Arithmetic Operators. Binary Arithmetic Operators. Arithmetic Operators. A Closer Look at the / Operator. A Closer Look at the % Operator

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Starting to Program in C++ (Basics & I/O)

CSI33 Data Structures

1) What of the following sets of values for A, B, C, and D would cause the string "one" to be printed?

Review: Using Imported Code. What About the DrawingGizmo? Review: Classes and Object Instances. DrawingGizmo pencil; pencil = new DrawingGizmo();

My First Command-Line Program

Deadline. Purpose. How to submit. Important notes. CS Homework 9. CS Homework 9 p :59 pm on Friday, April 7, 2017

VARIABLES & ASSIGNMENTS

COP4020 Programming Assignment 1 CALC Interpreter/Translator Due March 4, 2015

CS 31 Discussion ABDULLAH-AL-ZUBAER IMRAN WEEK 6: C-STRINGS, STRUCT, CLASS AND PROJECT4

In this chapter you will learn:

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

Your first C and C++ programs

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

CS 240 Data Structure Spring 2018 Exam I 03/01/2018

Call-by-Type Functions in C++ Command-Line Arguments in C++ CS 16: Solving Problems with Computers I Lecture #5

EL2310 Scientific Programming

Computer Programming

Getting started with C++ (Part 2)

Designing Loops and General Debug Pre-Defined Functions in C++ CS 16: Solving Problems with Computers I Lecture #6

Chapter 1 INTRODUCTION

Quiz Determine the output of the following program:

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

Tutorial-2a: First steps with C++ programming

MA400: Financial Mathematics

Why Is Repetition Needed?

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

CS31 Discussion 1E. Jie(Jay) Wang Week3 Oct.12

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Review: Classes and Object Instances. Review: Creating an Object. Using Multiple Objects. DrawingGizmo pencil; pencil = new DrawingGizmo();

Object-oriented programming in C++

Chapter 1 Introduction to Computers and Programming

CS 117 Programming II, Spring 2018 Dr. Ghriga. Midterm Exam Estimated Time: 2 hours. March 21, DUE DATE: March 28, 2018 at 12:00 PM

Binomial pricer (1.1)

Transcription:

CS 31 Discussion 1A, Week 1 Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50

TA Zengwen Yuan ( zyuan [at] cs.ucla.edu ) Discussion session (1A): Humanities A65 Friday 10:00 11:50 Office hours: BH 2432 Tuesday 11:30 12:30 Thursday 8:30 10:30 By appointment Class website: http://web.cs.ucla.edu/classes/fall16/cs31/

Course Review Basics

Introduction to Programming What is high-level language? (Analogy) Natural language: English: Hello! Voice: Programming: C++: std::cout << Hello! << std::endl Machine code: 0110011110101110 (I made this up)

A first look at a C++ program // filename: hello.cpp #include <iostream> using namespace std; int main () { } cout << "Hello World!" << endl;

A first look at a C++ program comment line use I/O library (for the print statement) // filename: hello.cpp #include <iostream> using namespace std; the context we are using int main () { } cout << "Hello World!" << endl; function boundaries print new line just a template for you to follow (more details later) print to standard output

How to run a program Compilation compiled language C++, C, Java, the compiler will translate the program directly into machine code that is specific to the target machine source code -> (compiler) -> executable Interpretation interpreted language Python, Bash, The source code is not directly run by the target machine. The interpreter reads and then executes the original source code.

Compilation source code (hello.cpp) compiler (Visual C++ / clang++ / g++) executable (hello)

Environment Setup Visual C++ Remote connection: see http://www.seasnet.ucla.edu/ terminal-server/ Caveat: use UCLA_WIFI or CSD; use UCLA VPN if you are working from home Xcode g++ with Linux server

Live demo

Errors (are bound to happen ) Compilation error (syntax error) Errors in which the programmer has violated a portion of the language syntax (the language structure). These will prevent source code from compiling into program/executable. Runtime error (logic error) Your source code might compile successfully, but encounter an error during runtime that either causes the program to break or produces unexpected (wrong) results.

Quiz: list some compilation errors Missing semicolons at ends of statements Missing brackets around blocks Missing namespace or #include definitions Misspelled variables or names

Quiz: list some runtime errors Division by 0 Overflow (e.g. trying to hold a really big number in an int variable that exceeds its bounds) int range: -2,147,483,648 2,147,483,647 (32-bit)

Quiz: what s wrong? (1) // filename: hello.cpp #include <iostream> using namespace std; double main () { } cout << "Hello World!" << endl;

Quiz: what s wrong? (2) / filename: quiz.cpp #include <iostream> int main () { cout << "Hello World!" cout << endl; }

Project Hints Project 1

General project requirement READ THE SPEC http://web.cs.ucla.edu/classes/fall16/cs31/ requirements.html Make sure your code works with two compilers: g++ with Linux Visual C++ 2015 or clang++ (Xcode) Submit single zip file, with correct file extension name

Project 1 spec a. get the environment set up b. original.cpp get the demo cpp program working c. logic_error.cpp modify the code such that it compiles but gives the wrong output d. compile_error.cpp introduce two distinct types of errors which make the code fail to compile e. write your report

Submission requirements Time due: 9:00 PM Tuesday, October 4 A compressed file in zip format containing exactly four files mentioned The zip file itself may be named whatever you like Do not include anything else in the zip file Submission links will be available by October 3

Best practice Comments Indentation

A more complex example #include <iostream> using namespace std; int main() { cout << "How many hours did you work? "; double hoursworked; cin >> hoursworked; cout << "What is your hourly rate of pay? "; double payrate; cin >> payrate; double amtearned = hoursworked * payrate; cout.setf(ios::fixed); cout.precision(2); cout << "You earned $" << amtearned << endl; cout << "$" << (0.10 * amtearned) << " will be withheld." << endl; }

Quiz: what s wrong? (3) #include <iostream> using namespace std; int main () { int worldpopulation = 7500000000; cout << "The world population is "; cout << worldpopulation << endl; }

Quiz: what s wrong? (4) #include <iostream> using namespace std; int main () { double PI = 3.14; int r, h; cout >> "Enter values of r and h: " cin >> r, h; v = PI * r * r * h; cout << "Volume = " << v; }