CISC2000/ of 6

Similar documents
Chapter Five: Functions II

17. [Exploring Numbers]

How to convert a numeric value into English words in Excel

Course Directive Degree Audit Exception

Primary Source Verification. How to Apply

Homework 5: Conditionals and Loops in C

Math in Focus Vocabulary. Kindergarten

Programming. Ed Milne

Hello! My name is PC and I am learning how to use a computer. Let s learn together! Unit1

Reports 9i. Section Title Page

Ratios can be written in several different ways. Using a colon. Using the word to. Or as a fraction.

MTK smartphone Multiple downloading tool operating instructions

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

Cisco WebEx Meetings Server Release 1.5MR2. CWMS 1.5MR2 Extended Branding

SAMPLE RESOURCE. dotty share prices

Parent s Guide to GO Math! Technology Correlation

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement

24 Week Marketing & Selling System

Your First C++ Program. September 1, 2010

Place Value. Unit 1 Lesson 1

Installation. 9mm. Rear view showing cable header pins

In this lesson, we will use the order of operations to evaluate and simplify expressions that contain numbers and variables.

Whole Numbers WHOLE NUMBERS.

Lab 2: Pointers. //declare a pointer variable ptr1 pointing to x. //change the value of x to 10 through ptr1

Answer Key // A Process of Learning Mathematics - Level 3 TABLE OF CONTENTS

The School District of Palm Beach County Kindergarten Mathematics Scope st Trimester

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

Java 1.8 Programming

Computer Programming

Computer Programming. Dr. Fahad Computer Science Deptt.

Web Design Course Syllabus and Planner

Essential SQLite3. Section Title Page

Introduction to Programming

The American University in Cairo Computer Science & Engineering Department CSCE Dr. KHALIL Exam II Spring 2010

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

UoK MIS USER MANUAL: STUDENTS

Voice Response System (VRS)

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE Instructor: Final Exam Fall 2014

CSCE Practice Midterm. Data Types

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

1.1 Review of Place Value

Week 4 EECS 183 MAXIM ALEKSA. maximal.io

CSc Introduc/on to Compu/ng. Lecture 8 Edgardo Molina Fall 2011 City College of New York

C++ For Science and Engineering Lecture 12

(6) The specification of a name with its type in a program. (7) Some memory that holds a value of a given type.

Java Programming with Eclipse

Digital codes. Resources and methods for learning about these subjects (list a few here, in preparation for your research):

The American University in Cairo Department of Computer Science & Engineeringt CSCI &09 Dr. KHALIL Exam-I Fall 2009

Whole Numbers. Whole Numbers. Solutions. Curriculum Ready.

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

Number Bases LESSON TWO. Computer Science. By John Owen

Compiling with Multiple Files The Importance of Debugging CS 16: Solving Problems with Computers I Lecture #7

Section 1.1 Patterns in Division

do { statements } while (condition);

Midterm Practice Exam

Scientific Computing

NOT FOR USE AS AN EXAM SAMPLE COPY - CS(H)15A. National Qualifications. Computing Science D D M M Y Y. Mark. Total marks 90

Math. Common Core. Daily/Spiral Review. Math. Common Core. Daily/Spiral Review. Unit 4. Unit 3. 7 th Grade

MathWorks MATLAB download & installation instructions

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

Forms 10g. Section Title Page

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Homeschool Programming, Inc.

Oklahoma State University Institute of Technology Online Common Syllabus Fall 2018

Boolean Data-Type. Boolean Data Type (false, true) i.e. 3/6/2018. The type bool is also described as being an integer: bool bflag; bflag = true;

Exceptions, Case Study-Exception handling in C++.

Local and Global Variables

Lab # 02. Basic Elements of C++ _ Part1

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Instructor: Final Exam Fall Section No.

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

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

C++ Programming: From Problem Analysis to Program Design, Third Edition

EP241 Computing Programming

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Lecture 23: Pointer Arithmetic

Design and Debug: Essen.al Concepts Numerical Conversions CS 16: Solving Problems with Computers Lecture #7

Guidelines for the Read Aloud Accommodation

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Dr. Khalil Exam II Fall 2011

Chapter 2 Basic Elements of C++

Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Introduction to Programming

Lecture # 6. Repetition. Review. If Else Statements Comparison Operators Boolean Expressions Nested Ifs. Switch Statements.

Chapter 8 Patterns. Examples: a, b, c,, x, y, z

Note: The buy help from the TA for points will apply on this exam as well, so please read that carefully.

Primary Source Verification. How to Apply

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

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Homework Assignment #2 (revised)

FIDE Language Reference

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

CDYNE Demographics Web Service

int x = 5; double y = 3; // Integer division rounds the result down to the nearest whole number. cout << "1a: " << x / 3 << endl; //1

QUICK REFERENCE GUIDE

Other operators. Some times a simple comparison is not enough to determine if our criteria has been met.

CSCE Practice Midterm. Data Types

Chapter 3 Problem Solving and the Computer

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

1. In C++, reserved words are the same as predefined identifiers. a. True

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

Transcription:

CISC2000/2010 1 of 6 Lecture 3 Fall 2018 Prof. Zhang Last week: 1. Three aspects of programming: a) programming language (syntax and semantics) b) problem solving skills (divide and conquer, step-wise refinement, ) c) software engineering (coding style indentation, comments; tools debugger, profiler; makefiles; ) 2. Quick overview of C++ language syntax and semantics: a) C++ program structure: include directive, main function, b) C++ statement c) C++ expression, operator precedence rules and association rules 3. (Hand) Tracing a C++ program a) finger/arrow pointing to current statement b) labelled box to represent variables c) more later: passing parameters during function calls 4. During lab: a) log on to storm (from lab computer, own laptop ) b) submitting labs c) vi/emacs for editing, g++ for compiling, and execution/testing d) importance of testing Today: 1. lab1 review 2. lab2 preview 3. Array and functions review (slides) : pass-by-value vs pass-by-reference; swap function 1. Lab1 review #include <iostream> #include <assert.h> //include this in order to use assert() using namespace std; //precondition: num is between 0 and 9 void PrintOnes (int num);

CISC2000/2010 2 of 6 //precondition: num is between 11 and 19 void PrintTeen (int num); //precondition: num is 10, 20,..., and 90 void PrintTens (int num); // precondition: num has a value between 0 and 999 // postcondition: the English name of the num is displayed in (standard output) void PrintNumber (int num); int main() int number = 0; cout << "Enter a number "; cin >> number; PrintNumber(number); return 0; // precondition: num has a value between 0 and 999 // postcondition: the English name of the num is displayed void PrintNumber (int num) cout <<"PrintNumber " << num << "\n \n"; assert (num<=999); //checking precondition //if the condition num<=999 is false, the whole //program aborts and display that this assertion fails // divide the numbers by relevant digits to get the relevant answers int hundred = num /100 ; int tens = //(num % 100); //Misleading Names num / 10 % 10; //set tens to the digit in //10-th place int ones = (num % 10 );

CISC2000/2010 3 of 6 //A check-point: making sure digits are properly extracted cout << checking: hundred= << hundred << ; tens= <<tens<< ; ones= <<ones<<endl; //Draw a flowchart about what we want to do first //Please see the last page for the flowchart // Rewrite the rest of this function based upon the flowchart //only display hundred if it is completly divisible by 100 - misleading comment if (hundred > 0) PrintOnes(hundred); cout << " Hundred ; // printing out the teens in the similar manner if ((tens > 10)&& (tens < 20)) PrintTeen(tens); //setting tens to zero because there is no need for it anymore tens = tens - tens ; //if it not teens than start displaying tens by minusing the ones tens = tens - ones ; if ((tens == 10) (tens > 19)); PrintTens (tens); if (ones > 0); PrintOnes (ones); cout <<endl;

CISC2000/2010 4 of 6 void PrintOnes (int num) //precondition: num is between 0 and 9 string Names[10]="Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", Nine"; cout << Names[num]; void PrintTeen (int num) //precondition: num is between 11 and 19 //postcondition: the english name of num is displayed //Better to use nested if statement here; or use an array // as lookup table string teensnames[9]= Eleven, Twelve, Thirteen, Fourteen, Fifteen, Sixteen, Seventeen, Eighteen, Nineteen ; /* */ assert (num>=11 && num<=19); cout << teensnames[num-11]; if (num == 11) cout << "Eleven "; if (num == 12) cout << "Twelve "; if (num == 13) cout << "Thirteen "; if (num == 14) cout << "Fourteen "; if (num == 15) cout << "Fifteen "; if (num ==16) cout << "Sixteen "; if (num ==17) cout << "Seventeen "; if(num == 18) cout << "Eighteen "; if (num ==19) cout << "Nineteen ;

CISC2000/2010 5 of 6 void PrintTens (int num) //precondition: num is 10, 20,..., and 90 if (num == 10) cout << "Ten "; if (num == 20) cout << "Twenty "; if (num == 30) cout << "Thirty "; if (num == 40) cout << "Fourty "; if ( num == 50) cout << "Fifty "; if ( num == 60) cout << "Sixty "; if (num == 70) cout << "Seventy "; if (num == 80) cout << "Eighty "; if (num == 90) cout << "Ninety "; 2. Lab2 Preview: a few pointers a) Top-down approach to implement the decision tree. b) Common logic error when testing some condition as follows: two strings are same if all characters in the two string matche. i.e., two strings are not the same if some characters do not match. A number n is prime if it cannot be divided by all numbers from 2 to n-1. i.e., a number is not prime if it can be divided by one number from 2 to n-1.

CISC2000/2010 6 of 6