PIC 10A. Review for Midterm I

Similar documents
PIC 10A. Final Review: Part I

PIC 10A. Final Review

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.

Problem Solving: Storyboards for User Interaction

Getting started with C++ (Part 2)

CMSC 202 Midterm Exam 1 Fall 2015

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

Why Is Repetition Needed?

Introduction to Programming EC-105. Lecture 2

Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering

Definition Matching (10 Points)

1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A.

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

Fundamentals of Programming CS-110. Lecture 2

CIS 130 Exam #2 Review Suggestions

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

CSCE Practice Midterm. Data Types

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

Chapter 3. Numeric Types, Expressions, and Output

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

THE INTEGER DATA TYPES. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

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

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

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

C++ PROGRAMMING. For Industrial And Electrical Engineering Instructor: Ruba A. Salamh

Chapter Four: Loops. Slides by Evan Gallagher. C++ for Everyone by Cay Horstmann Copyright 2012 by John Wiley & Sons. All rights reserved

CS 117 Programming II, Spring 2018 Dr. Ghriga. Midterm Exam Estimated Time: 2 hours. March 21, DUE DATE: March 28, 2018 at 12:00 PM

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

WARM UP LESSONS BARE BASICS

BITG 1233: Introduction to C++

From Pseudcode Algorithms directly to C++ programs

Introduction to C++ Dr M.S. Colclough, research fellows, pgtas

Week 4 EECS 183 MAXIM ALEKSA. maximal.io

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS242 ARRAYS

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

Discussion 1H Notes (Week 2, 4/8) TA: Brian Choi Section Webpage:

Expressions, Input, Output and Data Type Conversions

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

Week 3: File I/O and Formatting 3.7 Formatting Output

Chapter 2 - I know what I want to do NOW WHAT? Student Learning Outcomes (SLOs)

Arrays 2 CS 16: Solving Problems with Computers I Lecture #12

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6

More Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4

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

Basic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces

File Input / Output Streams in C++ CS 16: Solving Problems with Computers I Lecture #9

CS 151 Review #3. // More than one variable can be defined // in a statement. Multiple variables are // separated by a comma.

Name Section: M/W or T/TH. True or False (14 Points)

CSCE Practice Midterm. Data Types

CSci 1113 Midterm 1. Name: Student ID:

Sample Code: OUTPUT Daily Highs & Lows

Understanding main() function Input/Output Streams

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)

To become familiar with array manipulation, searching, and sorting.

EP578 Computing for Physicists

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. The Increment and Decrement Operators

CS31 Discussion 1E. Jie(Jay) Wang Week3 Oct.12

Structured Programming. Flowchart Symbols. Structured Programming. Selection. Sequence. Control Structures ELEC 330 1

Programming Language. Functions. Eng. Anis Nazer First Semester

C++ for Python Programmers

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

Exam 2. CSI 201: Computer Science 1 Fall 2016 Professors: Shaun Ramsey and Kyle Wilson. Question Points Score Total: 80

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.

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

I/O Streams and Standard I/O Devices (cont d.)

The cin Object. cout << "Enter the length and the width of the rectangle? "; cin >> length >> width;

CPE Summer 2015 Exam I (150 pts) June 18, 2015

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science. Instructor: Final Exam Fall 2011

Lecture 4 Tao Wang 1

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

REVIEW. The C++ Programming Language. CS 151 Review #2

BEng (Hons) Electronic Engineering. Resit Examinations for / Semester 1

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

CS 106B, Lecture 1 Introduction to C++

Chapter Four: Loops II

EP241 Computing Programming

The C++ Language. Output. Input and Output. Another type supplied by C++ Very complex, made up of several simple types.

CS Exam 2 Study Suggestions

Unit 7. 'while' Loops

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

Computer Science II Lecture 1 Introduction and Background

Computer Programming

C/C++ Programming Lecture 7 Name:

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

CS Homework 10 p. 1. CS Homework 10

Introduction to the C++ Programming Language

CSCI 1061U Programming Workshop 2. C++ Basics

LECTURE 5 Control Structures Part 2

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

3.1. Chapter 3: The cin Object. Expressions and Interactivity

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.7. User Defined Functions II

Computer Science C++ Placement Exam

BITG 1113: Array (Part 1) LECTURE 8

Data Structures CSci 1200 Test 2 Questions

Programming in C++ PART 2

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

The following is a typical execution run of this program:

Functions that Return a Value. Approximate completion time Pre-lab Reading Assignment 20 min. 92

Transcription:

PIC 10A Review for Midterm I

Midterm I Friday, May 1, 2.00-2.50pm. Try to show up 5 min early so we can start on time. Exam will cover all material up to and including todays lecture. (Only topics that I explicitly state are not included, are not included.)

How to study for the exam Read the slides. Work through as many practice exams and problems as you can. Look at your notes and examples your TA did. Review homework assignments. Read the book.

Syntax Knowing the syntax also helps you write correct structure for your program. Knowing the syntax reinforces other concepts. If you are not confused about syntax the problem becomes clearer. There is no excuse for not knowing the syntax. All it takes is some memorization.

Variables Declare variables on top if possible. Pick good names. Assign values to variables before referencing their value. Remember that there are rules as to what variable names can be. Data types are key. Always ask yourself if it makes sense to have a given data type in your code.

Input and output In console we have two ways to get input cin and getline: int number; string phrase; cout << "Please give me a value: "; cin >> number; cout << "Enter some text: "; getline(cin, phrase); Know when to use and what the difference is!

Input and output Recall that we learned about ways to manipulate output. setw to set widths of "columns" of output. setprecision and fixed to manipulate how numbers are outputted. To use all these we need to include <iomanip> library. int a=1, b=3; double r = a/b ; cout << setprecision(2) << r << " " << 3 + 1.0 * a/b << "\n"; cout << setw(5) << "Dog" << "\n" << "Cat";

Arithmetic and casting Review lecture 3. You certainly should be familiar with all artihmetic operations including +,-, *, /, %, ++, --, += etc. You should understand how integers interact in divisions. You should know casting.

Strings You should know how string variables store strings. You should know all the string member functions we discussed. There will most likely be questions that have you manipulating strings in some manner. Lets look at the example from previous exam:

String example Write a full program (starting from #include) that asks the user to enter a phrase and then a single letter. The program should then report how many times that letter occurred in the phrase, displaying the letter with double quotes around it. Sample run: Please enter a phrase: Futurama is the best show on tv! (user enters) Please enter a letter to search: t (user enters) The letter "t" occurred 4 times.

String example #include <iostream> #include <string> using namespace std; int main() { string phrase; string letter; int count = 0; cout << "Please enter a phrase:" << "\n"; getline(cin,phrase); cout << "Please enter a letter to search:"; cin >> letter; for (int i=0; i<phrase.length(); i++) if (phrase.substr(i,1) == letter) count++; cout << "The letter \"" << letter << "\" occurred " << count << " times.\n"; return 0; }

Classes In theory you should be able to use a class if I give you an explanation of the member functions. You should be able to create the object and initialize it. You should be able to implement it in your program. Particularly you should know how to use the graphics classes: Point, Line, Circle, Message.

Graphics I expect you to know the graphics environment well. You should know how to get user input in a graphics environment and how to produce output. You should be familiar with cwin. Refer to many examples we did in class as well as the two homework assignments.

Boolean expressions and if statements You should be able to evaluate boolean expressions. Know how to use boolean variables in your code. Particularly should be familiar with &&,, ==,!= and!. Know how to use if, if-else and if-else-if-else structures.

The loops We have spent quite a bit of time learning the 3 loops: while, dowhile and for. Know the syntax for all. Know when to use them. You should also understand nested loops.

Loop example Write a full program (starting from #include) that asks the user to enter a number N and then prints on the screen the numbers 1 through N^2 arranged in a NxN grid. For example if the user enters 3 the output should be: 1 2 3 4 5 6 7 8 9

Loop example #include <iostream> #include <iomanip> using namespace std; int main() { int N; cout << "Enter number: " ; cin >> N; for (int i=1; i<=n*n; i++) { cout << setw(5) << i; if (i%n == 0) cout << "\n"; } return 0; } // Could also use a nested for loop for the rows and columns, // but that's a little harder. For a nested loop we should have // cout << setw(5) << N*(i-1)+j; where i and j are counter for //outer loop and inner loop respectively.

Functions Know the syntax for function prototype, function definition and for calling a function. It is quite likely that when I ask you to write code that does some task I will ask you to write a function that does the task. You should know what a void function is. You should know how to write a function returning type bool and know how and when to use such a function.

Function definition Write a function definition for a function that takes as arguments 3 Points and draws a triangle. This function should not return anything. (This is in the graphics environment.) void Triangle(Point P1, Point P2, Point P3) { Line L1(P1,P2); Line L2(P2,P3); Line L3(P3,P1); } cwin << L1 << L2 << L3; Write the function prototype: void Triangle(Point P1, Point P2, Point P3);

Calling a function Never put any types in function call!! Function call only has names of variables. Assume P1, P2 and P3 have been initialized somehow. We might have a function call in ccc_win_main: Triangle(P1,P2,P3);

Example In mathematics, the Fibonacci series is a sequence of numbers: 0,1,1,2,3,5,8,13,21... The next number in the sequence is obtained by adding together the two previous numbers. The first two Fibonacci numbers are taken to be 0 and 1. Our goal will be to write a function that calculates the nth Fibonacci number. Our function will be called fibonacci and it will take as an argument an int n and return the nth Fibonacci number.

Example a) Write a function prototype for the fibonacci function.

Example a) Write a function prototype for the fibonacci function. int fibonacci(int n);

Example b) Write a function definition for the fibonacci function. Hint: Use a loop to calculate the nth Fibonacci number. When you know the two previous Fibonacci numbers you can always calculate the next one. Make sure your function returns correct values also in the case if n is 0 or 1.

Example int fibonacci(int n) { int previous_previous = 0; int previous = 1; int current = 0; if (n==0) return 0; for (int i=0; i < n; i++) { current = previous_previous + previous; previous_previous = previous; previous = current; } } return current;