CS31 Discussion 1E Spring 17 : week 05
|
|
- Douglas Grant
- 5 years ago
- Views:
Transcription
1 CS31 Discussion 1E Spring 17 : week 05 TA: Bo-Jhang Ho bojhang@cs.ucla.edu Credit to former TA Chelsea Ju
2 Road map of CS31 String Array Function Class Variable If / else Loops Pointer
3 Today s Agenda } Use project 3 to get more insights about functions } Peer discussion
4 When we talk about function } How function are executed in a program } Consumer-Provider relation
5 An example of a function int square(int a) { return a * a; } int main() { int a = 3; int b = 6; cout << square(a + b) << endl; } return 0; } Are two variable a s the same?
6 An example of a function int square(int a) { return a * a; } int main() { int a = 3; int b = 6; cout << square(a + b) << endl; } return 0; } Different functions have their own variable sets } Try it on VC++ / Xcode
7 What is your role? User Provider } How to use the function? } What s the goal of the function? } How do you expect users to use this function? } How do you implement it?
8 Math example User 10 cout <<
9 Math example User #include <iostream> using namespace std; int main() { cout <<???????????????????? << endl; } return 0;
10 Math example User } Step 1: Use your own words to ask Google
11 Math example User } Step 1: Use your own words to ask Google } Step 2: Read the parameter description carefully
12 Math example User #include <iostream> #include <cmath> using namespace std; int main() { cout << (1 + pow(2.7, 10.0)) << endl; } return 0;
13 Dice throw example User cout <<
14 Dice throw example User } Step 1: Use your own words to ask Google
15 Dice throw example User } Step 1: Use your own words to ask Google } Step 2: Read the parameter description carefully
16 Math example User #include <iostream> #include <cstdlib> using namespace std; int main() { cout << (rand() % 6 + 1) << endl; } return 0;
17 Math example User #include <iostream> #include <cstdlib> using namespace std; int main() { cout << (rand() % 6 + 1) << endl; } return 0; } Question: why it always give the same value?
18 Project 3 warm-up User } What s the difference between #include and #include <...>?
19 Project 3 warm-up User } *.h shows the interface of the functions } And this is what you need only } *.cpp should be included to make the program complete } You re welcome to check the details, but it s not necessary
20 Questions you have to ask yourself when developing a function Provider } What s the goal of the function? } How do you expect users to use this function? } What information have to pass to your function? } What message are you going to pass back? } How do you implement it?
21 1. What s the goal of the function Provider
22 Provider 2. How people are going to use this function A: Hey, I will give you a base and an exponent B: Sure, I will give you the result
23 Provider 2. How people are going to use this function
24 Provider 2. How people are going to use this function Please pass a coordinate (r, c) to me, remember to mention whether it s a horizontal line or a vertical line, also give me the length as well as the character. Let me know the mode: I can support both foreground and background. If I can successfully draw a line based on the parameters you gave me, I tell you true, otherwise I reply false.
25 Provider 2. How people are going to use this function true distance dir plotchar false Start at (r, c)
26 3. How to implement Provider } Modular design!
27 3. How to implement Provider } Modular design!
28 3. How to implement Provider } Modular design!
29 Determine function call graph void printspacestarline(int numspaces, int numstars); void printlayer(int startnumspaces, int startnumstars) { printspacestarline(startnumspaces, startnumstars); printspacestarline(startnumspaces - 1, startnumstars + 2); printspacestarline(startnumspaces - 2, startnumstars + 4); } int main() { printlayer(5, 1); // * // *** // ***** printlayer(4, 3); // *** // ***** // ******* printlayer(3, 5); // ***** // ******* // ********* printlayer(2, 7); // ******* // ********* //*********** printspacestarline(4, 3); // *** printspacestarline(4, 3); // *** return 0; }
30 Determine function call graph void printspacestarline(int numspaces, int numstars); void printlayer(int startnumspaces, int startnumstars) { printspacestarline(startnumspaces, startnumstars); printspacestarline(startnumspaces - 1, startnumstars + 2); printspacestarline(startnumspaces - 2, startnumstars + 4); } int main() { printlayer(5, 1); printlayer(4, 3); printlayer(3, 5); printlayer(2, 7); printspacestarline(4, 3); printspacestarline(4, 3); return 0; } main() paintlayer() paintspacestarline() Call direction
31 Determine function call graph int factorial(int n) { int prod = 1; for (int i = 2; i <= n; i++) prod *= i; return prod; } int main() { for (int k = 1; k <= 6; k++) { cout << "The factorial of " << k << " is " << factorial(k) << endl; } } void printfactorial(int n) { int prod = 1; for (int i = 2; i <= n; i++) prod *= i; for (int k = 1; k <= 6; k++) { cout << "The factorial of " << k << " is " << factorial(k) << endl; } } int main() { for (int k = 1; k <= 6; k++) printfactorial(k); } Function fun question 4 Function fun question 5 main() factorial() main() printfactorial() Call direction
32 Determine function call graph int factorial(int n) { int prod = 1; for (int i = 2; i <= n; i++) prod *= i; return prod; } void printfactorial(int n) { for (int k = 1; k <= n; k++) { cout << "The factorial of " << k << " is " << factorial(k) << endl; } } int main() { for (int k = 1; k <= 6; k++) printfactorial(k); } main() printfactorial() factorial()
33 3. How to implement Provider Always pay attention to what are available to you!
34 Project 3 warm-up Provider cleargrid() setchar() getchar() draw()
35 Project 3 warm-up Provider main() cleargrid() setchar() getchar() draw()
36 Project 3 Phase 2 Provider plotline() What s the call relation here? cleargrid() setchar() getchar() draw()
37 Project 3 Phase 2 Provider plotline() cleargrid() setchar() getchar() draw()
38 Project 3 Phase 3 Provider main() executecommands() plotline() cleargrid() setchar() getchar() draw()
39 Project 3 Phase 3 Provider main() executecommands() C F@ B@ H00 V00 plotline() cleargrid() setchar() getchar() draw()
40 Project 3 Phase 3 Provider main() executecommands() C F@ B@ H00 V00 plotline() cleargrid() setchar() getchar() draw()
41 Project 3 - executecommands() Provider } A parser question " * 69" "report.docx" "report.png" "int main() { return 0; }" Give me the calculation result Tell me the file type Generate a program
42 Project 3 - executecommands() Provider } A parser question } A typical approach: } Tokenize } Interpret / convert tokens "v2b h12fhh1fih0"
43 Project 3 - executecommands() Provider } A parser question } A typical approach: } Tokenize } Interpret / convert tokens "v2b h12fhh1fih0"
44 Project 3 - executecommands() Provider } A parser question } A typical approach: } Tokenize } Interpret / convert tokens } Why parsing is hard? } The length of tokens vary } There can be many exceptions and hard to come out a unified parsing strategy } In most cases, there are constraints across tokens (but not in this assignment) } Have to report precise error position
45 Project 3 - executecommands() Provider } Write down a lot of both good examples and bad examples
46 Project 3 - executecommands() Provider } Tokenize: Look forward strategy } Separate into several cases: } C } F@ } B@ } H-- } V } H2 } H22 } H-2 } H-22 "v2b h12fhh1fih0"
47 Discussion time } Find a partner and tell him/her what you have done, what program you encounter now } Brain storming the solution } Read code, use debugger help you, give suggestions
CS31 Discussion 1E Spring 17 : week 08
CS31 Discussion 1E Spring 17 : week 08 TA: Bo-Jhang Ho bojhang@cs.ucla.edu Credit to former TA Chelsea Ju Project 5 - Map cipher to crib Approach 1: For each pair of positions, check two letters in cipher
More informationProgramming Language. Functions. Eng. Anis Nazer First Semester
Programming Language Functions Eng. Anis Nazer First Semester 2016-2017 Definitions Function : a set of statements that are written once, and can be executed upon request Functions are separate entities
More informationCS 240 Data Structure Spring 2018 Exam I 03/01/2018
CS 240 Data Structure Spring 2018 Exam I 03/01/2018 This exam contains three section A) Code: (basic data type, pointer, ADT) a. Reading: Trace the code to predict the output of the code b. Filling: Fill
More informationJordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A
Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A Name: ID#: Section #: Day & Time: Instructor: Answer all questions as indicated. Closed book/closed
More informationToday in CS161. Lecture #7. Learn about. Rewrite our First Program. Create new Graphics Demos. If and else statements. Using if and else statements
Today in CS161 Lecture #7 Learn about If and else statements Rewrite our First Program Using if and else statements Create new Graphics Demos Using if and else statements CS161 Lecture #7 1 Selective Execution
More informationReview: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements
Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja
More informationDeadline. Purpose. How to submit. Important notes. CS Homework 9. CS Homework 9 p :59 pm on Friday, April 7, 2017
CS 111 - Homework 9 p. 1 Deadline 11:59 pm on Friday, April 7, 2017 Purpose CS 111 - Homework 9 To give you an excuse to look at some newly-posted C++ templates that you might find to be useful, and to
More informationCS31 Discussion 1E. Jie(Jay) Wang Week1 Sept. 30
CS31 Discussion 1E Jie(Jay) Wang Week1 Sept. 30 About me Jie Wang E-mail: holawj@gmail.com Office hour: Wednesday 3:30 5:30 BH2432 Thursday 12:30 1:30 BH2432 Slides of discussion will be uploaded to the
More informationGE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004
GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004 Functions and Program Structure Today we will be learning about functions. You should already have an idea of their uses. Cout
More informationFunctions. CS111 Lab Queens College, CUNY Instructor: Kent Chin
Functions CS111 Lab Queens College, CUNY Instructor: Kent Chin Functions They're everywhere! Input: x Function: f Output: f(x) Input: Sheets of Paper Function: Staple Output: Stapled Sheets of Paper C++
More information(created by professor Marina Tanasyuk) FUNCTIONS
FUNCTIONS (created by professor Marina Tanasyuk) In C++, a function is a group of statements that is given a name, and which can be called from some point of the program. The most common syntax to define
More informationCISC 1110 (CIS 1.5) Introduc2on to Programming Using C++
CISC 1110 (CIS 1.5) Introduc2on to Programming Using C++ Spring 2012 Instructor : K. Auyeung Email Address: Course Page: Class Hours: kenny@sci.brooklyn.cuny.edu hbp://www.sci.brooklyn.cuny.edu/~kenny/cisc1110
More informationExceptions, Case Study-Exception handling in C++.
PART III: Structuring of Computations- Structuring the computation, Expressions and statements, Conditional execution and iteration, Routines, Style issues: side effects and aliasing, Exceptions, Case
More informationAgenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures
The main body and cout Agenda 1 Fundamental data types Declarations and definitions Control structures References, pass-by-value vs pass-by-references The main body and cout 2 C++ IS AN OO EXTENSION OF
More informationWeek 4 EECS 183 MAXIM ALEKSA. maximal.io
Week 4 EECS 183 MAXIM ALEKSA maximal.io Agenda Functions Scope Conditions Boolean Expressions Lab 2 Project 2 Q&A Lectures 15% 36% 19% 8:30am 10:00am with Bill Arthur 10:00am 11:30am with Mary Lou Dorf
More informationCS 161 Intro to CS I. Finish Pointers/Start Recursion
CS 161 Intro to CS I Finish Pointers/Start Recursion 1 In-class Exercise #3 Understanding Pointers Create a pointer to a double, i.e. double *d; and three doubles d1, d2, and, d3 that get the values 7.8,
More informationWeek 1: Hello World! Muhao Chen
Week 1: Hello World! Muhao Chen 1 Muhao Chen Teaching Fellow Email address: muhaochen@ucla.edu Office Hours: Thursday 11:30 ~ 2:30 PM BH2432 Personal office BH3551 Homepage (where I post slides): http://yellowstone.cs.ucla.edu/~muhao/
More informationCS 31 Discussion 1A, Week 1. Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50
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
More informationUniversity of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.
University of Technology Laser & Optoelectronics Engineering Department C++ Lab. Fifth week Control Structures A program is usually not limited to a linear sequence of instructions. During its process
More informationSpring CS Homework 12 p. 1. CS Homework 12
Spring 2018 - CS 111 - Homework 12 p. 1 Deadline 11:59 pm on Friday, May 4, 2018 Purpose CS 111 - Homework 12 To practice with sentinel- and question-controlled loops, file input and file output, and writing
More informationWelcome to Lab! Feel free to get started until we start talking! The lab document is located on the course website:
Welcome to Lab! Feel free to get started until we start talking! The lab document is located on the course website: https://users.wpi.edu/~sjarvis/ece2049_smj/ece2049_labs.html You do not need to keep
More informationANSI C. Data Analysis in Geophysics Demián D. Gómez November 2013
ANSI C Data Analysis in Geophysics Demián D. Gómez November 2013 ANSI C Standards published by the American National Standards Institute (1983-1989). Initially developed by Dennis Ritchie between 1969
More informationCS31 Discussion. Jie(Jay) Wang Week6 Nov.4
CS31 Discussion Jie(Jay) Wang Week6 Nov.4 Outline Project 4 Array C Strings Project 4 DDL: Monday, November 7 Read the spec & FAQ carefully Incremental development You can call your function in other functions
More informationCS 117 Programming II, Spring 2018 Dr. Ghriga. Midterm Exam Estimated Time: 2 hours. March 21, DUE DATE: March 28, 2018 at 12:00 PM
CS 117 Programming II, Spring 2018 Dr. Ghriga Midterm Exam Estimated Time: 2 hours March 21, 2018 DUE DATE: March 28, 2018 at 12:00 PM INSTRUCTIONS: Do all exercises for a total of 100 points. You are
More informationHomework 11 Program Setup (with some IMPORTANT NEW STEPS!)
Spring 2018 - CS 111 - Homework 11 p. 1 Deadline 11:59 pm on Friday, April 27, 2018 Purpose To practice with loops, arrays, and more! How to submit CS 111 - Homework 11 Submit your main.cpp (or it may
More informationMore Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4
More Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4 Ziad Matni Dept. of Computer Science, UCSB Administrative CHANGED T.A. OFFICE/OPEN LAB HOURS! Thursday, 10 AM 12 PM
More informationTutorial 12 Craps Game Application: Introducing Random Number Generation and Enumerations
Tutorial 12 Craps Game Application: Introducing Random Number Generation and Enumerations Outline 12.1 Test-Driving the Craps Game Application 12.2 Random Number Generation 12.3 Using an enum in the Craps
More informationFunctions and Recursion
Functions and Recursion 1 some useful problems 2 Function: power Power iteration Power recursive #include #include 3 using std::cout; using std::cin; using std::endl; // function prototype
More information1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.
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. B. Outputs to the console a floating point number f1 in scientific format
More informationNon-numeric types, boolean types, arithmetic. operators. Comp Sci 1570 Introduction to C++ Non-numeric types. const. Reserved words.
, ean, arithmetic s s on acters Comp Sci 1570 Introduction to C++ Outline s s on acters 1 2 3 4 s s on acters Outline s s on acters 1 2 3 4 s s on acters ASCII s s on acters ASCII s s on acters Type: acter
More informationReview. Modules. CS 151 Review #6. Sample Program 6.1a:
Review Modules A key element of structured (well organized and documented) programs is their modularity: the breaking of code into small units. These units, or modules, that do not return a value are called
More informationPre- Defined Func-ons in C++ Review for Midterm #1
Pre- Defined Func-ons in C++ Review for Midterm #1 CS 16: Solving Problems with Computers I Lecture #6 Ziad Matni Dept. of Computer Science, UCSB Announcements Homework #5 due today Homework #6 issued
More informationLocal and Global Variables
Lecture 10 Local and Global Variables Nearly every programming language has a concept of local variable. As long as two functions mind their own data, as it were, they won t interfere with each other.
More informationLab Instructor : Jean Lai
Lab Instructor : Jean Lai Group related statements to perform a specific task. Structure the program (No duplicate codes!) Must be declared before used. Can be invoked (called) as any number of times.
More informationProject 1: Convex hulls and line segment intersection
MCS 481 / David Dumas / Spring 2014 Project 1: Convex hulls and line segment intersection Due at 10am on Monday, February 10 0. Prerequisites For this project it is expected that you already have CGAL
More informationOverloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6
Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6 Ziad Matni Dept. of Computer Science, UCSB A reminder about Labs Announcements Please make sure you READ
More informationSuperior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.6
Superior University Department of Electrical Engineering CS-115 Computing Fundamentals Experiment No.6 Pre-Defined Functions, User-Defined Function: Value Returning Functions Prepared for By: Name: ID:
More informationCSCE Practice Midterm. Data Types
CSCE 2004 - Practice Midterm This midterm exam was given in class several years ago. Work each of the following questions on your own. Once you are done, check your answers. For any questions whose answers
More informationWELCOME TO CS 16! Enrollment status: 117/ Problem Solving with Computers-I
WELCOME TO CS 16! Problem Solving with Computers-I https://ucsb-cs16-s18-mirza.github.io/ Enrollment status: 117/105 2 About me Diba Mirza (diba@ucsb.edu) PhD (Computer Engineering, UCSD) First year as
More informationC++ basics Getting started with, and Data Types.
C++ basics Getting started with, and Data Types pm_jat@daiict.ac.in Recap Last Lecture We talked about Variables - Variables, their binding to type, storage etc., Categorization based on storage binding
More informationFORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each):
FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): 1. The basic commands that a computer performs are input (get data), output (display result),
More information5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (!
FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): 1. Assume that all variables are properly declared. The following for loop executes 20 times.
More informationThe cin Object. cout << "Enter the length and the width of the rectangle? "; cin >> length >> width;
The cin Object Short for console input. It is used to read data typed at the keyboard. Must include the iostream library. When this instruction is executed, it waits for the user to type, it reads the
More informationFunction. Mathematical function and C+ + function. Input: arguments. Output: return value
Lecture 9 Function Mathematical function and C+ + function Input: arguments Output: return value Sqrt() Square root function finds the square root for you It is defined in the cmath library, #include
More informationDesigning Loops and General Debug Pre-Defined Functions in C++ CS 16: Solving Problems with Computers I Lecture #6
Designing Loops and General Debug Pre-Defined Functions in C++ CS 16: Solving Problems with Computers I Lecture #6 Ziad Matni Dept. of Computer Science, UCSB Announcements Homework #5 due today Lab #3
More informationCh 6. Functions. Example: function calls function
Ch 6. Functions Part 2 CS 1428 Fall 2011 Jill Seaman Lecture 21 1 Example: function calls function void deeper() { cout
More informationChapter Four: Loops II
Chapter Four: Loops II Slides by Evan Gallagher & Nikolay Kirov Chapter Goals To understand nested loops To implement programs that read and process data sets To use a computer for simulations Processing
More informationCS 31 Discussion 1A, Week 4. Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50 a.m.
CS 31 Discussion 1A, Week 4 Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50 a.m. Today s focus Notes from the project 2 grading Function call predefined function define a function
More informationProject 1: Convex hulls and line segment intersection
MCS 481 / David Dumas / Spring 2012 Project 1: Convex hulls and line segment intersection Due at 2pm on Monday, February 6 0. Requirements In order to complete this project you will need CGAL and a compatible
More informationCS31 Discussion 1E. Jie(Jay) Wang Week5 Oct.27
CS31 Discussion 1E Jie(Jay) Wang Week5 Oct.27 Outline Project 3 Debugging Array Project 3 Read the spec and FAQ carefully. Test your code on SEASnet Linux server using the command curl -s -L http://cs.ucla.edu/classes/fall16/cs31/utilities/p3tester
More informationExam I KEY (corrected)
CS 102 * * * Sections 2 5 * * * Spring 2010 Exam I KEY (corrected) Name: KEY Section: Use the back for scratch paper if you need it. Make sure your final answer is clear to us (put a circle or box around
More informationToday in CS161. Week #3. Learn about. Writing our First Program. See example demo programs. Data types (char, int, float) Input and Output (cin, cout)
Today in CS161 Week #3 Learn about Data types (char, int, float) Input and Output (cin, cout) Writing our First Program Write the Inches to MM Program See example demo programs CS161 Week #3 1 Data Types
More informationHonors Computer Science C++ Mr. Clausen Program 4A, 4B, 4C (4D, 4G)
Honors Computer Science C++ Mr. Clausen Program 4A, 4B, 4C (4D, 4G) Program 4A: Function: Comments And Output 10 points Write a program that practices comments, output, and void functions. Save the program
More informationWeek 2: Console I/O and Operators Arithmetic Operators. Integer Division. Arithmetic Operators. Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.
Week 2: Console I/O and Operators Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.1) CS 1428 Fall 2014 Jill Seaman 1 2.14 Arithmetic Operators An operator is a symbol that tells the computer to perform specific
More informationVARIABLES & ASSIGNMENTS
Fall 2018 CS150 - Intro to CS I 1 VARIABLES & ASSIGNMENTS Sections 2.1, 2.2, 2.3, 2.4 Fall 2018 CS150 - Intro to CS I 2 Variables Named storage location for holding data named piece of memory You need
More informationCISC2000/ of 6
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
More informationExam 1. CSI 201: Computer Science 1 Fall 2018 Professors: Shaun Ramsey
Exam 1 CSI 201: Computer Science 1 Fall 2018 Professors: Shaun Ramsey I understand that this exam is closed books and closed notes and is to be completed without a calculator, phone, or other computer.
More informationBuilding on the foundation. Now that we know a little about cout cin math operators boolean operators making decisions using if statements
Chapter 5 Looping Building on the foundation Now that we know a little about cout cin math operators boolean operators making decisions using if statements Advantages of Computers Computers are really
More informationCIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts)
CIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts) Problem 0: Install Eclipse + CDT (or, as an alternative, Netbeans). Follow the instructions on my web site.
More informationChapter 17 - Notes Recursion
Chapter 17 - Notes Recursion I. Recursive Definitions A. Recursion: The process of solving a problem by reducing it to smaller versions of itself. B. Recursive Function: A function that calls itself. C.
More informationWeek 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7. CS 5301 Spring 2018
Week 3 Functions & Arrays Gaddis: Chapters 6 and 7 CS 5301 Spring 2018 Jill Seaman 1 Function Definitions l Function definition pattern: datatype identifier (parameter1, parameter2,...) { statements...
More informationName. CPTR246 Spring '17 (100 total points) Exam 2
Name CPTR246 Spring '17 (100 total points) Exam 2 1. Pointer parameters (the old C way) In the following program, make all of the changes to convert the call-by-reference parameters in the function computeoptions
More informationUnit 13. Linux Operating System Debugging Programs
1 Unit 13 Linux Operating System Debugging Programs COMPILATION 2 3 Editors "Real" developers use editors designed for writing code No word processors!! You need a text editor to write your code Eclipse,
More informationModule Contact: Dr Pierre Chardaire, CMP Copyright of the University of East Anglia Version 1
UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2016-17 INTRODUCTORY PROGRAMMING CMP-0005A Time allowed: 2 hours Answer BOTH questions from Section A and ONE question
More informationDue Date: See Blackboard
Source File: ~/2315/45/lab45.(C CPP cpp c++ cc cxx cp) Input: under control of main function Output: under control of main function Value: 4 Integer data is usually represented in a single word on a computer.
More informationUsing the Command Line
1 Unit 15 Debugging COMPILATION 2 3 Using the Command Line While it has a GUI interface like your Mac or Windows PC much of its power lies in its rich set of utilities that are most easily run at the command
More informationWhy Is Repetition Needed?
Why Is Repetition Needed? Repetition allows efficient use of variables. It lets you process many values using a small number of variables. For example, to add five numbers: Inefficient way: Declare a variable
More informationThe American University in Cairo Department of Computer Science & Engineeringt CSCI &09 Dr. KHALIL Exam-I Fall 2009
The American University in Cairo Department of Computer Science & Engineeringt CSCI 106-05&09 Dr. KHALIL Exam-I Fall 2009 Last Name :... ID:... First Name:... Form I Section No.: EXAMINATION INSTRUCTIONS
More informationDue Date: See Blackboard
Source File: ~/2336/43/lab43.(C CPP cpp c++ cc cxx cp) Input: under control of main function Output: under control of main function Value: 2 The purpose of this assignment is to modify Lab 38. Instead
More informationChapter 10 - Notes Applications of Arrays
Chapter - Notes Applications of Arrays I. List Processing A. Definition: List - A set of values of the same data type. B. Lists and Arrays 1. A convenient way to store a list is in an array, probably a
More informationFunctions and Recursion
Functions and Recursion 1 Outline Introduction Program Components in C++ Math Library Functions Functions Function Definitions Function Prototypes Header Files Random Number Generation Example: A Game
More informationtype name(arg1, arg2,...) { body return }
defining functions function: a group of statements given a name that can be called from some point in the program. Functions allow us to write programs in pieces of code that perform individual tasks type
More informationWeek 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7.
Week 3 Functions & Arrays Gaddis: Chapters 6 and 7 CS 5301 Fall 2015 Jill Seaman 1 Function Definitions! Function definition pattern: datatype identifier (parameter1, parameter2,...) { statements... Where
More informationThe American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011
The American University in Cairo Department of Computer Science & Engineering CSCI 106-07&09 Dr. KHALIL Exam-I Fall 2011 Last Name :... ID:... First Name:... Form I Section No.: EXAMINATION INSTRUCTIONS
More informationWentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. C++ Kitchen Sink. Lecture 14.
Lecture 14 1 Exceptions Iterators Random numbers Casting Enumerations Pairs The Big Three Outline 2 Error Handling It is often easier to write a program by first assuming that nothing incorrect will happen
More informationEECS402 Lecture 02. Functions. Function Prototype
The University Of Michigan Lecture 02 Andrew M. Morgan Savitch Ch. 3-4 Functions Value and Reference Parameters Andrew M. Morgan 1 Functions Allows for modular programming Write the function once, call
More informationEECS 211 Spring Quarter, 2010 Program 5 Due Tuesday, May 18th, 2010 at 11:59PM
EECS 211 Spring Quarter, 2010 Program 5 Due Tuesday, May 18th, 2010 at 11:59PM In this assignment we will form the basic looping and branching mechanism in the main function that will be used for the remaining
More informationLinked List using a Sentinel
Linked List using a Sentinel Linked List.h / Linked List.h Using a sentinel for search Created by Enoch Hwang on 2/1/10. Copyright 2010 La Sierra University. All rights reserved. / #include
More informationDiscussion 1H Notes (Week 2, 4/8) TA: Brian Choi Section Webpage:
Discussion 1H Notes (Week 2, 4/8) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 Variables You have to instruct your computer every little thing it needs to do even
More informationDiscussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:
Discussion 1H Notes (Week 3, April 14) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 More on Arithmetic Expressions The following two are equivalent:! x = x + 5;
More informationLAB #8. GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act:
LAB #8 Each lab will begin with a brief demonstration by the TAs for the core concepts examined in this lab. As such, this document will not serve to tell you everything the TAs will in the demo. It is
More informationSample Final Exam. 1) (24 points) Show what is printed by the following segments of code (assume all appropriate header files, etc.
Name: Sample Final Exam 1) (24 points) Show what is printed by the following segments of code (assume all appropriate header files, etc. are included): a) int start = 10, end = 21; while (start < end &&
More informationCSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100
CSC 126 FINAL EXAMINATION Spring 2011 Version A Name (Last, First) Your Instructor Question # Total Possible 1. 10 Total Received 2. 15 3. 15 4. 10 5. 10 6. 10 7. 10 8. 20 TOTAL 100 Name: Sp 11 Page 2
More information1. a) What #include statement do you put at the top of a program that does uses cin, cout or endl?
Exercises with solutions. 1. a) What #include statement do you put at the top of a program that does uses cin, cout or endl? #include b) What using statement do you always put at the top of
More information05-01 Discussion Notes
05-01 Discussion Notes PIC 10B Spring 2018 1 Exceptions 1.1 Introduction Exceptions are used to signify that a function is being used incorrectly. Once an exception is thrown, it is up to the programmer
More informationChapter Four: Loops. Slides by Evan Gallagher. C++ for Everyone by Cay Horstmann Copyright 2012 by John Wiley & Sons. All rights reserved
Chapter Four: Loops Slides by Evan Gallagher The Three Loops in C++ C++ has these three looping statements: while for do The while Loop while (condition) { statements } The condition is some kind of test
More informationMore Group HW. #ifndef Stackh #define Stackh. #include <cstdlib> using namespace std;
More Group HW The following code is contained in the file ex1stck.h. Fill in the blanks with the C++ statement(s) that will correctly finish the method. Each blank may be filled in with more than one statement.
More informationC++ Programming Lecture 1 Software Engineering Group
C++ Programming Lecture 1 Software Engineering Group Philipp D. Schubert Contents 1. More on data types 2. Expressions 3. Const & Constexpr 4. Statements 5. Control flow 6. Recap More on datatypes: build-in
More informationCHAPTER 4 FUNCTIONS. Dr. Shady Yehia Elmashad
CHAPTER 4 FUNCTIONS Dr. Shady Yehia Elmashad Outline 1. Introduction 2. Program Components in C++ 3. Math Library Functions 4. Functions 5. Function Definitions 6. Function Prototypes 7. Header Files 8.
More informationCS2141 Software Development using C/C++ C++ Basics
CS2141 Software Development using C/C++ C++ Basics Integers Basic Types Can be short, long, or just plain int C++ does not define the size of them other than short
More informationChapter 3 - Functions
Chapter 3 - Functions 1 Outline 3.1 Introduction 3.2 Program Components in C++ 3.3 Math Library Functions 3.4 Functions 3.5 Function Definitions 3.6 Function Prototypes 3.7 Header Files 3.8 Random Number
More informationDue Date: See Blackboard
Source File: ~/2315/38/lab38.(C CPP cpp c++ cc cxx cp) Input: under control of main function Output: under control of main function Value: 3 A bucket sort begins with a one-dimensional array of positive
More informationC++ Programming: From Problem Analysis to Program Design, Third Edition
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine
More informationA SHORT COURSE ON C++
Introduction to A SHORT COURSE ON School of Mathematics Semester 1 2008 Introduction to OUTLINE 1 INTRODUCTION TO 2 FLOW CONTROL AND FUNCTIONS If Else Looping Functions Cmath Library Prototyping Introduction
More informationWelcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 1/9/ Review. Here s a simple C++ program:
Welcome Back CSCI 262 Data Structures 2 - Review What you learned in CSCI 261 (or equivalent): Variables Types Arrays Expressions Conditionals Branches & Loops Functions Recursion Classes & Objects Streams
More informationCS31 Discussion 1E. Jie(Jay) Wang Week3 Oct.12
CS31 Discussion 1E Jie(Jay) Wang Week3 Oct.12 Outline Problems from Project 1 Review of lecture String, char, stream If-else statements Switch statements loops Programming challenge Problems from Project
More informationReview Questions for Final Exam
CS 102 / ECE 206 Spring 11 Review Questions for Final Exam The following review questions are similar to the kinds of questions you will be expected to answer on the Final Exam, which will cover LCR, chs.
More informationDesign and Debug: Essen.al Concepts Numerical Conversions CS 16: Solving Problems with Computers Lecture #7
Design and Debug: Essen.al Concepts Numerical Conversions CS 16: Solving Problems with Computers Lecture #7 Ziad Matni Dept. of Computer Science, UCSB Announcements We are grading your midterms this week!
More informationpointers + memory double x; string a; int x; main overhead int y; main overhead
pointers + memory computer have memory to store data. every program gets a piece of it to use as we create and use more variables, more space is allocated to a program memory int x; double x; string a;
More informationassembler Machine Code Object Files linker Executable File
CSCE A211 Programming Intro What is a Programming Language Assemblers, Compilers, Interpreters A compiler translates programs in high level languages into machine language that can be executed by the computer.
More information