Reviewing all Topics this term

Similar documents
Class 2: Variables and Memory. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

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

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

CS111: PROGRAMMING LANGUAGE II

CSCI 131, Midterm Exam 1 Review Questions This sheet is intended to help you prepare for the first exam in this course. The following topics have

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

Microsoft Excel 2010 Handout

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

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

Add Subtract Multiply Divide

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.

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

CS 1301 Exam 1 Answers Fall 2009

Starting Out With C++: Early Objects, Fifth Edition Solutions to Review Questions. Chapter 1

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

Computer Science II Lecture 1 Introduction and Background

Starting Out With C++: Early Objects, Seventh Edition Solutions to End-of-Chapter Review Questions

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

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

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection

CS 106 Introduction to Computer Science I

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

Today in CS161. Week #3. Learn about. Writing our First Program. See example demo programs. Data types (char, int, float) Input and Output (cin, cout)

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

Lecture 3 Tao Wang 1

Algorithms. Abdelghani Bellaachia, CSCI 1121 Page: 1

CHAPTER 2.1 CONTROL STRUCTURES (SELECTION) Dr. Shady Yehia Elmashad

Introduction to: Computers & Programming: Review prior to 1 st Midterm

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

Basic Data Types and Operators CS 8: Introduction to Computer Science, Winter 2019 Lecture #2

CpSc 111 Lab 3 Integer Variables, Mathematical Operations, & Redirection

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Programming Language. Functions. Eng. Anis Nazer First Semester

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Chapter Overview. C++ Basics. Variables and Assignments. Variables and Assignments. Keywords. Identifiers. 2.1 Variables and Assignments

Chapter 4: Control Structures I (Selection)

CSCE 206: Structured Programming in C++

Homework #3 CS2255 Fall 2012

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

Topic 2: C++ Programming fundamentals

Quiz Determine the output of the following program:

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

CS 111X - Fall Test 1

Professor: Sana Odeh Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators

Introduction to Java Applications

Class #1. introduction, functions, variables, conditionals

CS 61B Data Structures and Programming Methodology. June David Sun

FORM 2 (Please put your name and form # on the scantron!!!!)

Name SECTION: 12:45 2:20. True or False (12 Points)

UNIT- 3 Introduction to C++

The C++ Language. Arizona State University 1

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Announcements. Lab 1 this week! Homework posted Thursday -Due next Thursday at 11:55pm

Chapter 2. C++ Basics

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan

CS 376b Computer Vision

Assignment 1 Expressions Data Types Formatted Printing Variables Scanning CSC 123 Fall 2018 Answer Sheet Short Answers

CS2141 Software Development using C/C++ C++ Basics

Dept. of CSE, IIT KGP

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

age = 23 age = age + 1 data types Integers Floating-point numbers Strings Booleans loosely typed age = In my 20s

Java Bytecode (binary file)

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

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

CS11 Java. Fall Lecture 1

Introduction to C. Sami Ilvonen Petri Nikunen. Oct 6 8, CSC IT Center for Science Ltd, Espoo. int **b1, **b2;

Decisions, Decisions. Testing, testing C H A P T E R 7

Chapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++

Copy: IF THE PROGRAM or OUTPUT is Copied, then both will have grade zero.

Chapter 2: Overview of C++

CS 111X - Fall Test 1 - KEY KEY KEY KEY KEY KEY KEY

Relational Operators EXAMPLE. C++ By

Introduction to C CMSC 104 Spring 2014, Section 02, Lecture 6 Jason Tang

Introduction to C++ 2. A Simple C++ Program. A C++ program consists of: a set of data & function definitions, and the main function (or driver)

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: if Single-Selection Statement CSC 209 JAVA I. week 3- Control Statements: Part I

CS 1301 Exam 1 Fall 2009

The design recipe. Readings: HtDP, sections 1-5. (ordering of topics is different in lectures, different examples will be used)

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

Announcements. Homework 0 out! Coming soon: 1. remote access 2. programming instructions 3. lab 1 (graded!) this week

CS 140. Calendar Assignment. Part 1

CS 12 Fall 2003 Solutions for mid-term exam #2

1. a) What #include statement do you put at the top of a program that does uses cin, cout or endl?

BASIC ELEMENTS OF A COMPUTER PROGRAM

All answers will be posted on web site, and most will be reviewed in class.

Chapter 1 INTRODUCTION

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

CS 141, Lecture 3. Please login to the Math/Programming profile, and look for IDLE (3.4 or the unnumbered. <-- fine <-- fine <-- broken

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

CS 101 Fall 2006 Midterm 1 Name: ID:

Introduction to C. CS 2060 Week 1. Prof. Jonathan Ventura. Outline Introduction Introduction to C Homework 1 C Coding Style Wrap-up

Fundamentals of Programming CS-110. Lecture 2

n Group of statements that are executed repeatedly while some condition remains true

Chapter 1 Style Requirements

Final Exam CS 152, Computer Programming Fundamentals December 9, 2016

Programming - 1. Computer Science Department 011COMP-3 لغة البرمجة 1 لطالب كلية الحاسب اآللي ونظم المعلومات 011 عال- 3

PLT Fall Shoo. Language Reference Manual

Transcription:

Today in CS161 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for) Functions (pass by value, pass by reference) Arrays (specifically arrays of characters) CS161 Week #9-10 1

How to prepare for the Final Exam Best place to start preparing for the final exam is... Homework #6 which has you practice each of the constructs Practice with the demo programs Take them, modify them, replace one loop for one of the other loops Final exam is 2 hours long Closed book, Closed notes It will cover: Algorithms, Ethics, Style, and Programming You will NOT be asked to write a complete program (whew!) CS161 Week #9-10 2

Sample Programming Questions Write a C++ statement to answer each of the following: 1. Display your name to the screen 2. Let s say you have a variable that contains your age. Show how you would display it on the screen 3. Show how to add 1 to your age CS161 Week #9-10 3

The Basics Write a C++ statement to answer each of the following: 1. Show an example of an assignment statement. What goes on the left hand side? 2. What is the difference between integer division and floating point division can you give an example? portion = 10/3; what is the answer? portion = 10.0/3.0; how is this different? CS161 Week #9-10 4

The Basics Write a C++ statement to answer each of the following: 1. Show two example of comments 2. Where should comments be placed? 3. Assume you have an integer variable count. Show how to define (create) the variable. 4. Now, show how to add 2 to the variable count and store it in the variable total CS161 Week #9-10 5

Sample Programming Questions: Math! Some math given: int count; and, int total; 1. Multiply count by 4 and store it into total 2. Find the remainder of dividing count by 3, output the result 3. How can you find out if count is an even number? 4. What is the difference between the += and the + operations? CS161 Week #9-10 6

Sample Programming Questions: Trivia Trivia 1. What does each C++ statement end with? 2. Does cin do input or output? 3. Variables must start with what. Show an example 4. The << is for input or output? 5. A group of statements, such as the contents of a function are enclosed by what symbols? CS161 Week #9-10 7

Sample Programming Questions Short coding questions 1. Store the integers 62 and 99 in two variables; store the sum of these two in variable total 2. Compute the sales tax on a $52 purchase assuming that sales tax is 4% 3. You have four values (in four different variables). Show how you could calculate the average of all four. CS161 Week #9-10 8

Sample Programming Questions Change the previous questions 1. Read in two integer values and store the sum of these two in variable total 2. Read in the amount of purchase and sales tax and compute the amount of tax. 3. You have four values that you read in from the user (in four different variables). Show how you could calculate the average of all four. CS161 Week #9-10 9

If Statements 1. Write an if statement that checks to see if x is 100 or if y is zero 2. Write an if/else statement that displays a message indicating whether chr (a character variable) is one of the following symbols:. ;, or! 3. Write an if statement that displays an error message if the variable grade is not 0 through 100 (valid values are 0-100). CS161 Week #9-10 10

If Statements 1. Explain what the does. Give an example of when it could be used 2. Explain what the && does. Give an example of when it could be used 3. True or False: = and == are the same 4. True or False: all lines in a block {} should be indented after the if 5. True or False: x!= y is the same as x > y x < y 6. True or Fasle: y < x is the same as x >= y CS161 Week #9-10 11

If Statements 1. The following statement should determine if x is not greater than 20. What is wrong with it: if (!x > 20) 2. The following statement should determine if count is within the range of 0 through 100. What is wrong with it: if (count >= 0 count <= 100) 3. The following statement should determine if count is within the range of 0 through 100. What is wrong with it: if (count < 0 count > 100) CS161 Week #9-10 12

Loops! 1. Write a while loop that lets the user enters a number. The number should be multiplied by 10 and the result stored in variable product. The loop should continue as long as product contains a value less than 100. 2. Write a for loop that displays 0, 10, 20, 30, 40, 50, 1000 CS161 Week #9-10 13

Loops! 1. Write a do while loop that asks the user to enter a number and echoes the number to the screen. It continues to do this as long as a negative value has been entered. 2. Write a loop that displays 10 rows of 15 # signs CS161 Week #9-10 14

Loops! 1. Why should you indent statements in the body of a loop? 2. Which loop would you use if you knew the number of times it was going to iterate (or loop)? 3. Which loop would you use to confirm the user s input? CS161 Week #9-10 15

Loops! Ask the user to enter in a positive number. Read it in. 1. Then, loop for that many times. Each time through the loop read in a number entered by the user and sum it together with the others. 2. Or, loop for that many times summing up all of the values from1 until that number. So, if 10 was entered, then it will sum together 1+2+3+4+5+6+7+8+9+10 3. Write a loop to display a-z characters be creative! CS161 Week #9-10 16

Functions! 1. Explain pass by value 2. Explain pass by reference 3. What data type can be the returned type of a function 4. What does it mean if a function has a void return type 5. The toupper function is a pass by value function. What does that mean since we are trying to upper case a character? How do we call the function to get an upper case character back? CS161 Week #9-10 17

Functions! 1. How many returned values can a function have? 2. Write a prototype for a function named calculate that returns a float and has two integer arguments (age and num) passed by value. 3. Write a prototype for a function named days. It should return an integer and have three integer arguments: years, months, and weeks passed by value. CS161 Week #9-10 18

Functions! 1. What is a local variable? 2. If two functions have the same local variable does it share the same memory or do they use different memory locations? 3. Why do local variables lose their values between calls to the function in which they are defined? 4. Show how you return a value from a function CS161 Week #9-10 19

Functions! 1. Given this function prototype show an example of how to call it void showvalue (int quantity); 2. The following statement calls a function named half. This function returns a value that is half that of the argument (a floating point value). Write the prototype: 3. True or False: Function prototypes are terminated with a semicolon 4. True or False: The header of a function (where you write the function) is ended witih a semicolon CS161 Week #9-10 20

Arrays 1. Show how to create an array of 100 characters 2. Create an array big enough to hold the word hello 3. What is the index of the first element in an array 4. Show how to read in a sentence and store it in one array. Assume the sentence is no longer than 131 characters and it ends with a period CS161 Week #9-10 21

Arrays 1. Display a message if the first character of the sentence is capitalized 2. Write a loop to find out how many lower case letters are in the array 3. If an array contains the word fun, what number will strlen return? 4. What is the difference between cin >> array and cin.get(); versus cin.get(array, size); CS161 Week #9-10 22