CIS199 Test Review 2 REACH.

Slides:



Advertisements
Similar presentations
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Advertisements

Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Chapter 7: User-Defined Functions II Instructor: Mohammad Mojaddam.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Computer Science 1620 Loops.
Enumerated Types 4 Besides the built-in types, ANSI C allows the definition of user-defined enumerated types –To define a user-define type, you must give.
Chapter 6: User-Defined Functions I
COMP 14 Introduction to Programming Miguel A. Otaduy May 25, 2004.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 6: User-Defined Functions I.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 8, 2005.
Copyright © 2003 Pearson Education, Inc. Slide 1.
Chapter 6: User-Defined Functions I
Copyright © 2012 Pearson Education, Inc. Chapter 6 Modularizing Your Code with Methods.
Python quick start guide
Fundamentals of Python: First Programs
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
 2003 Prentice Hall, Inc. All rights reserved. 1 Functions and Recursion Outline Function Templates Recursion Example Using Recursion: The Fibonacci Series.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
Chapter 6: User-Defined Functions
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
Project 1 Due Date: September 25 th Quiz 4 is due September 28 th Quiz 5 is due October2th 1.
CPS120: Introduction to Computer Science Decision Making in Programs.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 6 September 17, 2009.
USER-DEFINED FUNCTIONS. STANDARD (PREDEFINED) FUNCTIONS  In college algebra a function is defined as a rule or correspondence between values called the.
Current Assignments Homework 2 is available and is due in three days (June 19th). Project 1 due in 6 days (June 23 rd ) Write a binomial root solver using.
CPS120: Introduction to Computer Science Lecture 14 Functions.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
I Power Higher Computing Software Development High Level Language Constructs.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
© Janice Regan, CMPT 128, February CMPT 128: Introduction to Computing Science for Engineering Students Recursion.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Chapter 3: User-Defined Functions I
A First Book of ANSI C Fourth Edition Chapter 6 Modularity Using Functions: Part I.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
C# Programming Methods.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
CC213 Programming Applications Week #2 2 Control Structures Control structures –control the flow of execution in a program or function. Three basic control.
Function Parameters and Overloading Version 1.0. Topics Call-by-value Call-by-reference Call-by-address Constant parameters Function overloading Default.
Functions + Overloading + Scope
Chapter Topics Chapter 16 discusses the following main topics:
Chapter 9: Value-Returning Functions
Chapter 6: User-Defined Functions I
Chapter 15 Recursion.
Chapter 7: User-Defined Functions II
REPETITION CONTROL STRUCTURE
Chapter 15 Recursion.
Algorithm Analysis CSE 2011 Winter September 2018.
JavaScript: Functions.
Chapter 8: Control Structures
Programmazione I a.a. 2017/2018.
User-Defined Functions
Chapter 14 Recursion. Chapter 14 Recursion Overview 14.1 Recursive Functions for Tasks 14.2 Recursive Functions for Values 14.3 Thinking Recursively.
Subroutines Idea: useful code can be saved and re-used, with different data values Example: Our function to find the largest element of an array might.
User Defined Functions
Chapter 4 void Functions
CIS 199 Test 02 Review.
Introduction to Problem Solving and Control Statements
CS2011 Introduction to Programming I Arrays (I)
A First Book of ANSI C Fourth Edition
CPS120: Introduction to Computer Science
BBIT 212/ CISY 111 Object Oriented Programming (OOP)
Chapter 6: User-Defined Functions I
Test Review CIS 199 Exam 2 by.
The structure of programming
The structure of programming
Thinking procedurally
Corresponds with Chapter 5
Presentation transcript:

CIS199 Test Review 2 REACH

What will be discussed Selection/Decision statements Looping statements Top-Down vs OOP Reference data types vs value data types Coding problems Conclusion

Selection/Decision Statements Types If statement If-Else statement Nested if statement If-else-if statement Switch statement http://www.programiz.com/c-programming/c-if-else-statement

Switch vs If-else-If The switch statement can be used to replace the if-else-if statement if: Matching has to be done on a specific: Value Type Enumeration Other data Recall that the test condition in the switch statement cannot be a: Decimal number Floating point number Switch statement cannot be used to test for a range of values. Each value must be tested individually

Loops Usually consists of: Definite/Finite Loops Initial value (i = 0) Test condition (i < FINAL_VALUE) Body (console.WriteLine(“The number is “, i)) Modification (i++) Definite/Finite Loops Test for a predefined condition Once condition no longer remains true, exit the loop Indefinite/Infinite Loops Most times happens by mistake Occurs when a stop condition is not defined thereby leading the program to run endlessly

Types of Looping statements While statement: test for condition then enters the loop Do while statement: enters the loop before testing for condition. Loop will run at least once even if the condition is not true For statement: condensed version of the while statement Foreach statement: used for going through an array or list. Cannot select what items in the list/array to manipulate

Break vs Continue Break statement Continue statement When a break statement is encountered within a loop, the loop is stopped and the statement right after the loop is executed next. Continue statement When a continue statement is encountered within a loop, the loop skips that step of the iteration and moves on to the next iteration

Top Down Design This is a method for breaking down an algorithm into methods The overall task that the program is to perform is broken down into a series of sub-tasks Each sub-task is examined to determine whether it can be broken down further into more subtasks. This is repeated until no more subtasks can be identified Once all the subtasks are identified, they are written in code It is called top-down design because the programmer begins by looking at the topmost level of tasks that must be performed and then breaks down those tasks into lower levels of subtasks

Example of Top Down Design

Methods A method can be used to break a complex program into smaller manageable pieces. A void method simply executes a group of statements and then terminates A value-returning method returns a values to the statement that called it Preconditions: Conditions that MUST be true BEFORE a method execution Postconditions: Conditions that MUST be true AFTER a method execution An Argument is any piece of data that is passed into a method when the method is called WHILE a Parameter is a variable that receives an argument that is passed into a method

Example Parameters are used in the method signature Arguments are used in the method call

Pass by Value vs Pass by Reference When an argument is passed by value, only a copy of the argument’s value is passed into the parameter variable. If the contents of the parameter variable are changed inside the method, it has no effect on the argument calling part of the program. It guarantees that the value of the variable will not be changed by the method its passing through When an argument is passed by reference to a method, he method can change the value of the argument in the calling part of the program using a reference parameter: ref Using an output parameter method: out

Ref vs Out Ref: anything done to the reference parameter is actually done to the argument it references Useful for establishing 2-way communication between methods Out: anything done to the output parameter is actually done to the argument it references. They are different from ref in the following ways: An argument does not have to be set to a value before it passed into an output parameter e.g an uninitialized variable A method with an output parameter must set the output parameter to some value before it finishes executing. E.g TryParse Method

Reference vs Value Data Types Value Types: When declared, memory is set aside for the variable e.g. int, float, decimal, string Reference Types: the variable does not hold data but rather it holds a reference which links the variable to the object e.g Random r = new Random()

Code Fragments Write a loop that displays every fifth number from 1 through 100 (5, 10, 15, etc.). Write a method named ShowRetailPrice that accepts two parameters, a double wholesaleCost and a double markupPercent and does not return a value (void method). The method should calculate the retail price (increase the cost by the given percentage) and display it using a MessageBox. Write a method named ConvertInchesToCM that accepts a double parameter inches and returns a double value. The method should convert the specified number of inches into centimeters. Each inch is equivalent to 2.54 centimeters. Write a C# code fragment (just the relevant statements, not an entire program) that defines a public method named Sum that returns a double and accepts three double parameters a, b, and c. The method should calculate the sum of the three values and return it. Write a C# code fragment (just the relevant statements, not an entire program) that defines a public method named SumArray that returns an int and accepts one parameter, an array of integers named arr. The method should calculate the sum of all the numbers in the array arr and return it. Write a C# code fragment (just the relevant statements, not an entire program) that defines a public method named Max that returns a double and accepts two double parameters a, and b. The method should return the value of the larger parameter, either a or b. Write a C# code fragment (just the relevant statements, not an entire program) that defines a public method named Max that returns a double and accepts three double parameters a, b, and c. The method should return the value of the largest parameter, either a, b, or c. Write C# code fragments (just the relevant statements, not an entire program) to accomplish the following: a) Declare an array of ints named temps. b) Allocate memory for the array to hold 10 elements. c) Write a for loop to initialize all of the array elements to the value 72 . Write a C# code fragment that prints each element of an array of doubles named arr to the console, each on a separate line. You must use a foreach loop. Write a C# code fragment that creates an array of int values using an initializer list with the following values: 10, 14, 16, 21, 27 . Write a loop that displays the values from first to last, and then write another loop that displays them from last to first.

Questions? For more information or if you need any help: REACH Computer Resource Center: Ekstrom Library, Ground Floor. Hours: Mon –Thurs: 8am – 8pm Friday: 8am – 4pm Sunday: 12 noon – 2pm Our Website with Test Review Info: http://reach.louisville.edu/tutoring/computer/cistestreviews.html You can also visit the link above to get these slides