Dayu Zhang 9/10/2014 Lab03. Outline Brief Review of the 4 Steps in Hello.cpp Example Understand endl and \n Understand Comment Programming Exercise -

Slides:



Advertisements
Similar presentations
An Introduction to Programming By :- Vishal Hirani B.Tech II year (CSE)
Advertisements

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 11 – Fundraiser Application: Introducing Scope.
Dayu Zhang 9/8/2014 Lab02. Example of Commands pwd --- show your current directory This is home of venus, not your home directory Tilde: means you are.
CMPUT 101 Lab # 5 October 22, :00 – 17:00.
Local and Global Variables. COMP104 Local and Global / Slide 2 Scope The scope of a declaration is the block of code where the identifier is valid for.
Computer Science 1620 Loops.
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/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
© 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5/e Starting Out with C++: Early Objects 5 th Edition Chapter 2 Introduction.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
CS 202 Computer Science II Lab Fall 2009 September 3.
Dayu Zhang 9/3/2014 Lab01. Lab Instructor: Dayu Zhang Office Hour Mon/Wed 10:40am – 11:10am Room A201 Lab Website
CS 117 Section 2 + KNET Computer accounts – ed to KNET students –Change password Homework 1 Lab Tutors –In lab for next 2 weeks –Will help you with.
Basic Elements of C++ Chapter 2.
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
Programming is instructing a computer to perform a task for you with the help of a programming language.
Introduction to C++ Programming
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
1 ENG236: ENG236: C++ Programming Environment (2) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY.
Agenda Review Compiling Review Data Types Integer Division Composition C++ Mathematical Functions User Input Reading: , 8.11 Homework #3.
Introduction to C++ - How C++ Evolved Most popular languages currently: COBOL, Fortran, C, C++, Java (script) C was developed in 1970s at AT&T (Richie)
Intro. to Game Programming Want to program a game?
Hello World 2 What does all that mean?.
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
1 Documenting Your Project. 2 Documenting your Project Insert Banner Comments in your code Comment - coding statement used by humans not the compiler.
CS161 Topic #21 CS161 Introduction to Computer Science Topic #2.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 4.
Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2.
Creating your first C++ program
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
1 C++ Programming Basics Chapter 2 Lecture CSIS 10A.
Agenda Review C++ Library Functions Review User Input Making your own functions Exam #1 Next Week Reading: Chapter 3.
1 Lab 2 “Hello world” in Unix/Linux #include "std_lib_facilities_4.h" int main(){ cout
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
N from what language did C++ originate? n what’s input, output device? n what’s main memory, memory location, memory address? n what’s a program, data?
1 C++ Programming Basics Chapter 1 Lecture CSIS 10A.
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 2.
1 Original Source : and Problem and Problem Solving.ppt.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 05, 2005 Lecture Number: 4.
Writing Scripts Hadi Otrok COEN 346.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
C++ Programming Lecture 13 Functions – Part V The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Learners Support Publications Introduction to C++
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
Computer Programming A simple example /* HelloWorld: A simple C program */ #include int main (void) { printf (“Hello world!\n”); return.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 2 September 3, 2009.
 Simple UNIX commands  I/O techniques in C++  Solutions to Lab#0 problems  Solutions to Lab#1 problems 1.
Functions in C++ Top Down Design with Functions. Top-down Design Big picture first broken down into smaller pieces.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
1 Structure of Simple C++ Program Chapter 1 09/09/13.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
C++ Programming Lecture 13 Functions – Part V By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
CS 240 Computer Programming 1
Linux CSE 1222 CSE1222: Lecture 1BThe Ohio State University1.
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
1 CS 192 Lecture 4 Winter 2003 December 8-9, 2003 Dr. Shafay Shamail.
Basic concepts of C++ Presented by Prof. Satyajit De
Topic Pre-processor cout To output a message.
Computer Engineering 1nd Semester
CS149D Elements of Computer Science
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Lab 1 Introduction to C++.
Lab 1 Introduction to C++.
COMS 261 Computer Science I
Presentation transcript:

Dayu Zhang 9/10/2014 Lab03

Outline Brief Review of the 4 Steps in Hello.cpp Example Understand endl and \n Understand Comment Programming Exercise - Calculate Area of a Square

Steps of Hello.cpp Create Command: touch Hello.cpp Edit Command: vi Hello.cpp Compile Command: g++ Hello.cpp If there is compile error, file a.out will not be generated Run Command:./a.out

Distinguish In or Not In vi Editor All commands in previous slide should be used outside of vi Editor When in vi Editor Insert Mode: edit code Command Mode: save code and quit vi editor

Understand endl and \n In C++, they both mean new line. endl --- it is used outside of “ ” \n --- it is used inside of “ ” \ --- it has special meaning If you want to print \, you cannot use cout << “\”; Instead, you will use cout << “\\”;

First, know the Difference int main() { cout << "hi"; return 0; } int main() { cout << "hi" << endl; return 0; }

Q1:What is the output? int main() { cout << "hi" << endl << endl << "hello" << endl; return 0; } A. B. hi hello hi hello

Q2: Are the outputs the same? int main() { cout << "hi" << endl; return 0; } int main() { cout << "hi\n"; return 0; } A. Yes B. No

Q3: What is the output? int main() { cout << "today\ntomorrow" << endl; return 0; } A. B. today\ntomorrowtoday tomorrow

Q4: What is the output? int main() { cout << "\\" << endl; return 0; } A. \ B. \\

Q5: What is the output? int main() { cout << "\n" << endl; return 0; } A. B. \n (Choice A means zero or more new lines)

Q6: What is the output? int main() { cout << "endl" << endl; return 0; } A. B. endl

Q7: What is the output? int main() { cout << "\\n" << endl; return 0; } A. \\n B. \n

Q8: What is the output? int main() { cout << "\\\\" << endl; return 0; } A. \\ B. \\\\

Q9: What is the output? int main() { cout << \n << endl; return 0; } A. \n B. Program could not be compiled, thus no output

Understand Comment // Current line is comment. You should always put your name in the first line of programming assignment // Name: LastName, FristName /* */ All lines in between are comments.

Exercise: Calculate Area of a Square Write a program that asks user to input the length of the side of a square (type: int) and then output the area of the square.

Answers to Output Questions Q1 B Q2 A Q3 B Q4 A Q5 A Q6 B Q7 B Q8 A Q9 B