COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.

Slides:



Advertisements
Similar presentations
1 Demo Reading Assignments Important terms & concepts Fundamental Data Types Identifier Naming Arithmetic Operations Sample Programs CSE Lecture.
Advertisements

Numeric Types, Expressions, and Output ROBERT REAVES.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
Problem Solving and Program Design Programming. COMP102 Prog Fundamentals I : Problem Solving and Program Design/Slide 2 Problem Solving Process l Define.
1 Lecture 6 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
C++ Basics. COMP104 C++ Basics / Slide 2 Introduction to C++ * C++ is a programming language for manipulating numbers and user-defined objects. * C++
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
1 9/08/06CS150 Introduction to Computer Science 1 Arithmetic Operators.
1 Chapter 3 Topics Constants of Type int and float l Evaluating Arithmetic Expressions l Implicit Type Coercion and Explicit Type Conversion l Calling.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
C++ Numerical Data Input/Output Programming. COMP 102 Prog Fundamentals I:C++ Numerical Data, Input/Output /Slide 2 Rules for Division l C++ treats integers.
Classes and Objects Objects of class type string Input/Output Objects and Formatted Input/Output 6/30/2015MET CS 563--Fall A. Using Class Type Objects.
CSE202: Lecture 8The Ohio State University1 Formatting Numbers for Output.
1 Lecture 7 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
Basic Elements of C++ Chapter 2.
Lecture 17: 10/29/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 4: Continuing with C++ I/O Basics.
Chapter 3 COMPLETING THE BASICS Programming Fundamentals with C++1.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems.
CSE1222: Lecture 9The Ohio State University1. Formatting Numbers for Output  Number formatters are to be used in conjunction with cout  For example,
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
Formatting, Casts, Special Operators and Round Off Errors 09/18/13.
Introduction to C++ Basic Elements of C++. C++ Programming: From Problem Analysis to Program Design, Fourth Edition2 The Basics of a C++ Program Function:
THE BASICS OF A C++ PROGRAM EDP 4 / MATH 23 TTH 5:45 – 7:15.
I/O and Data Formatting Introduction to Class Concepts INFSY 307 Spring 2003 Lecture 3.
Chapter 3 Arithmetic Expressions, Function Calls, and Output
Input/Output Sujana Jyothi C++ Workshop Day 2. C++ I/O Basics 2 I/O - Input/Output is one of the first aspects of programming that needs to be mastered:
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
C++ Lecture 1 Friday, 4 July History of C++ l Built on top of C l C was developed in early 70s from B and BCPL l Object oriented programming paradigm.
CPS120: Introduction to Computer Science Formatted I/O.
COMP102 Lab 021 COMP 102 Programming Fundamentals I Presented by : Timture Choi.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 5: Continuing with C++ I/O Basics.
1 09/27/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
PROGRAM ESSENTIALS. TOKENS  SMALLEST UNITS OF A PROGRAM LANGUAGE  Special Symbols  Mathematical Operators  Punctuation  Word Symbols  Key Words.
Programming Fundamentals with C++1 Chapter 3 COMPLETING THE BASICS.
If Statements Programming. COMP104 Lecture 7 / Slide 2 Review: Rules for Division l C++ treats integers different than doubles. 100 is an int. l 100.0,
1 Manipulators manipulators are used only in input and output statements endl, fixed, showpoint, setw, and setprecision are manipulators that can be used.
C++ Basics Programming. COMP104 Lecture 5 / Slide 2 Introduction to C++ l C is a programming language developed in the 1970s with the UNIX operating system.
Last Time…. Operators Arithmetic Operators Assignment Operators Increment/Decrement Operators Relational Operators Logical Operators Expression Statements.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
arithmetic operator & cin I.Mona Alshehri The output formatting functions setw(width) setw(n) - output the value of the next expression in n columns.
COMP 2710 Software Construction C++ Basics 2 and Exercises Dr. Xiao Qin Auburn University These slides.
CSCI 125 & 161 / ENGR 144 Lecture 6 Martin van Bommel.
INPUT & OUTPUT 10/20/2016Department of Computer Science, UOM | Introduction | Fakhre Alam.
Chapter Topics The Basics of a C++ Program Data Types
Programming Fundamentals
CPS120: Introduction to Computer Science
CPS120: Introduction to Computer Science
Chapter 3. Expressions and Interactivity
Basic Elements of C++.
Basic Elements of C++ Chapter 2.
C++ fundamentals Lecture 1, Chapter 2 – pp /22/2018 Y K Choi.
Review for Midterm Exam
C++ Basics.
Review for Midterm Exam
Formatting the Output The C++ standard library supplies many manipulators: endl, setw, fixed, showpoint, setprecesion. If we want to use endl, fixed, or.
Chapter 3: Expressions and Interactivity
Review for Midterm Exam
Review for Midterm Exam
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Fundamental Programming
Fundamental Programming
C++ Programming Basics
Programming Fundamental-1
Presentation transcript:

COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo

Lecture Review  Software Development Process Requirement analysis Specifications Design and architecture Coding Testing Documentation Maintenance

Lecture Review  Arithmetic Operators + - * /  Note: Precision problem int/int => int  Truncates instead of round-off  E.g. 3 / 2 => 1 % (modulus/remainder)  E.g. 10 % 3 => 1 int/double =>double double/int => double double/double => double

Lecture Review  Operator Precedence Evaluation order of operators  ( )  *, /  +, -  Left associativity Evaluate from left to right if same precedence E.g.  (1 + 2) * 3 – 4 / => * 3 => / 5 => – 0 => 9

Lecture Review  Assignment Statement Syntax  = ; E.g.  int a_var;  a_var = (1 + 2) * 3 – 4 / 5;

Lecture Review  Data Type Conversions Implicit  E.g. float z = 2.7; int y = 3; y = z;// y will be set to 2 Explicit  Syntax var_1 = type (var_2); var = type (expression);  E.g. int x = 1, y = 2; double z; z = x/y; // z will be set to 0.0 z = double (x)/double (y); // z will be set to 0.5 Now: 1.0 / 2.0 => / 2 => 0

Lecture Review  Standard I/O Include the “ iostream.h ” Input  cin >> … Output  cout << …  Special output characters \a \t \n \\ \’ \”

Leeture Review  Format Manipulation Header Files  #include  using namespace std;

Lecture Review  Defining width Syntax  cout ); E.g.  cout <<setw(2) <<1.20 <<endl;  cout <<setw(7) << <<endl;  Cout <<setw(7) <<1.20 <<endl;  Output:

Lecture Review  Defining sig. fig. Syntax  cout ); E.g.  cout <<setprecision(2) << <<endl;  cout <<setprecision(4) <<101.0/4.0 <<endl;  Cout <<setprecision(4) <<1001.0/4.0 <<endl;  Output: 1.2e

More on prescision  How to define fixed decimal place? Syntax  cout.setf(ios::fixed);  cout ); E.g.  cout.setf(ios::fixed);  cout <<setprecision(2) << <<endl;  cout <<setprecision(4) <<101.0/4.0 <<endl;  Cout <<setprecision(4) <<1001.0/4.0 <<endl;  Output:

Summary  By the end of this lab, you should be able to: Use arithmetic operators Evaluate expression with standard operator precedence order Write assignment Identify rules of division Apply assignment conversions Employ standard I/O functions  cin / cout

Lab2  Random a integer in a given range Syntax E.g.  Random [11-20) int rand_no; rand_no = rand()%(20-11)+11; #include int main() { srand(time(0)); int rand_no; rand_no = rand()%( - ) + ; }

Lab2  How about random no. with decimal place?  E.g. Random [11.0 – 20.0) int rand_no; double result; rand_no = rand()%( )+110; result = rand_no * 0.1  E.g. Random [11.00 – 20.00) int rand_no; double result; rand_no = rand()%( )+1100; result = rand_no * 0.01