Do not turn to the next page until the start of the exam.

Similar documents
PIC 10A Pointers, Arrays, and Dynamic Memory Allocation. Ernest Ryu UCLA Mathematics

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

Tutorial 8 (Array I)

Fundamentals of Programming CS-110. Lecture 2

CMSC 202 Midterm Exam 1 Fall 2015

Arrays. What if you have a 1000 line file? Arrays

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

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.

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

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

Arrays. Arrays (8.1) Arrays. One variable that can store a group of values of the same type. Storing a number of related values.

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

University of Michigan EECS 183: Elem. Programming Concepts Fall 2011 Exam 1: Part 1: Form 1. Professors: ML Dorf, Elliot Soloway

CSCS 261 Programming Concepts Exam 1 Fall EXAM 1 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.

Exam 1. CSI 201: Computer Science 1 Fall 2018 Professors: Shaun Ramsey

CS101 PLEDGED SPRING 2001

Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A

CS 141, Introduction to Computer Science Fall Midterm Exam

The C++ Language. Arizona State University 1

CSCI 111 Midterm 1, version A Exam Fall Solutions 09.00am 09.50am, Tuesday, October 13, 2015

CAAM 420 Fall 2012 Lecture 29. Duncan Eddy

CSCI 111 First Midterm Exam Fall Solutions 09.00am 09.50am, Wednesday, October 18, 2017

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.

Ch 6. Functions. Example: function calls function

CSE030 Fall 2012 Final Exam Friday, December 14, PM

Computer Programming : C++

Example. Section: PS 709 Examples of Calculations of Reduced Hours of Work Last Revised: February 2017 Last Reviewed: February 2017 Next Review:

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

Introduction to Programming EC-105. Lecture 2

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

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

PIC 10A Flow control. Ernest Ryu UCLA Mathematics

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS240 BRANCHING STATEMENTS

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

Name. CPTR246 Spring '17 (100 total points) Exam 2

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

LECTURE 02 INTRODUCTION TO C++

CSCI 111 Midterm 1, version A Exam Fall Solutions 09.00am 09.50am, Tuesday, November 24, 2015

Getting started with C++ (Part 2)

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

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

Introduction to Programming

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

Computer Science II Lecture 1 Introduction and Background

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

8. The C++ language, 1. Programming and Algorithms II Degree in Bioinformatics Fall 2017

Your First C++ Program. September 1, 2010

CSCE Practice Midterm. Data Types

Summary of basic C++-commands

Programming. C++ Basics

1 Pointer Concepts. 1.1 Pointer Examples

ENGI 1020 Introduction to Computer Programming J U L Y 5, R E Z A S H A H I D I

Chapter 2 Basic Elements of C++

CS Semester I. Quiz 1 (version A)

Read and fill in this page now. Your lab section day and time: Name of the person sitting to your left: Name of the person sitting to your right:

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

Chapter 2: Introduction to C++

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

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

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

DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++

Computer Department. Question (1): State whether each of the following is true or false. Question (2): Select the correct answer from the following:

Tutorial Letter 103/1/2017 Introduction to Programming I

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

Starting Out with C++: Early Objects, 9 th ed. (Gaddis, Walters & Muganda) Chapter 2 Introduction to C++ Chapter 2 Test 1 Key

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

Introduction to Programming using C++

CSCS 261 Programming Concepts Exam 2 Fall EXAM 2 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.

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

Chapter 2. C++ Basics

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

a. a * c - 10 = b. a % b + (a * d) + 7 =

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

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

Module 7 b. -Namespaces -Exceptions handling

Introduction to Programming I COS1511 School of Computing Revision Notes

Read and fill in this page now

1st Midterm Exam: Solution COEN 243: Programming Methodology I

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++

Chapter 2: Overview of C++

Linked List using a Sentinel

CSCE121: Introduction to Program Design and Concepts Practice Questions for Midterm 1

Chapter 2 C++ Fundamentals

clicking on the on the New

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

CSCE 110 PROGRAMMING FUNDAMENTALS

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

Week 4 EECS 183 MAXIM ALEKSA. maximal.io

ECE 462 Exam 1. 6:30-7:30PM, September 22, 2010

Chapter 2: Basic Elements of C++

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

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

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

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

Chapter 4 - Notes Control Structures I (Selection)

CPSC 427: Object-Oriented Programming

CS 115 Midterm 2 Solutions

Sample Code: OUTPUT Daily Highs & Lows

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

Transcription:

Introduction to Programming, PIC10A E. Ryu Fall 2017 Midterm Exam Friday, November 3, 2017 50 minutes, 11 questions, 100 points, 8 pages While we don t expect you will need more space than provided, you may continue on the back of the pages. This exam is closed book and closed notes. Student name: Teaching staff signature: Do not turn to the next page until the start of the exam.

1. (2 points) Consider the following program, which is poorly indented on purpose. # include < iostream > using namespace std ; int main () { for ( int i = 1; i <= 5; i ++) { for ( int j = 1; j <= i; j ++) cout << ""; cout << "\n"; What is the output of this program? A. The output is... (Repeated 25 times.) B. The output is... (Repeated 15 times.) C. The output is D. The output is 2. (2 points) Let a, b, and c be variables of type bool. Then the expression (!(a &&!c) b ) == (!a b c) A. always evaluates to false. B. always evaluates to true. C. can evalute to true or false depending on what values a, b, and c take. Page 2

3. (2 points) The type char is a fundamental type. A. True B. False 4. (2 points) Consider the following code. int a [10];... // Other code here... // Other code here for ( int b=a; b <(a +10); b +=2) cout << b << endl ; Which of the following choices most accurately describe the functionality of the for loop? A. Prints a[0],a[2],a[4],a[6],a[8]. B. Prints a[0],a[2],a[4],a[6],a[8],a[10]. C. Prints a[1],a[3],a[5],a[7],a[9]. 5. (2 points) How many statements are in string s = " UCLA "; cout << s << endl ;;; A. 0 B. 1 C. 2 D. 3 E. 4 6. (2 points) C++ variables are stored in A. primary storage. B. secondary storage. C. ternary storage. D. nowhere. Variables are not stored in storage, unless explicitly saved. 7. (2 points) Consider the following code. # include < iostream > # include < string > using namespace std ; int main () { string s; cin >> s; bool b = false ; for ( int i =0; i<s. length (); i ++) { if ( A <=s[i] && s[i]<= Z ) b = b true ; cout << b << endl ; If the input is uclastudent what is the output? A. 0 B. 1 Page 3

8. (2 points) Consider the following code. float d = new float [ 20]; Which of the following choices is the correct way to deallocate the dynamic array? A. delete d; B. delete float d; C. delete[] d; D. delete[] float d; E. delete[20] float d; F. None of the above. The array is automatically deallocated. 9. (4 points) Convert BFF2 (base 16) into base 2. Solution: 1011 1111 1111 0010 Page 4

10. (40 points) Unix time counts the number of the seconds elapsed since 00:00:00 am, January 1, 1970. (We ll not worry about timezones.) Complete the program that converts a given Unix time into a human readable time. We assume every year is exactly 365 days and every day is exactly 24 hours. (So no leap days and no leap seconds.) Your output should be given in a 24-hour clock (no need to differentiate am and pm). # include < iostream > using namespace std ; int main () { const int DAYS_IN_MONTH [12] = {31,28,31,30,31,30,31,31,30,31,30,31; int year, month, day, hour, min, sec ; // Input in unix time long long int unixtime ; cin >> unixtime ; // -------------------------------------------------------------------- FILL IN HERE // -------------------------------------------------------------------- cout << " Time is " << hour << ":" << min << ":" << sec << ", "; cout << month << "-" << day << "-" << year << ". \n"; For your information, January has 31 days, Feburary has 28 days, March has 31 days, April has 30 days, May has 31 days, June has 30 days, July has 31 days, August has 31 days, September has 30 days, October has 31 days, November has 30 days, and Decemeber has 31 days. In the blank space below, write (with your pen or pencil) the missing code. Page 5

Solution: const int SEC_ IN_ MIN = 60; const int SEC_ IN_ HOUR = SEC_ IN_ MIN 60; const int SEC_ IN_ DAY = 24 SEC_ IN_ HOUR ; const int SEC_ IN_ YEAR = 365 SEC_ IN_ DAY ; year = unixtime / SEC_ IN_ YEAR + 1970; unixtime %= SEC_ IN_ YEAR ; month = 0; while ( unixtime >= ( SEC_IN_DAY DAYS_IN_MONTH [ month ])){ unixtime -= SEC_IN_DAY DAYS_IN_MONTH [ month ]; month ++; day = unixtime / SEC_ IN_ DAY ; unixtime %= SEC_ IN_ DAY ; hour = unixtime / SEC_ IN_ HOUR ; unixtime %= SEC_ IN_ HOUR ; min = unixtime / SEC_ IN_ MIN ; unixtime %= SEC_ IN_ MIN ; sec = unixtime ; Page 6

11. (40 points) Finish writing a program that takes in two strings and checks if the two strings are equal when capitalization is ignored. The input strings can contain (English) letters, numbers, and special characters. Assume the input string does not contain a space or any whitespace characters. # include < iostream > # include < string > using namespace std ; int main (){ string s1, s2; cout << " Enter string 1: " << endl ; cin >> s1; cout << " Enter string 2: " << endl ; cin >> s2; int length1 = s1. length (); int length2 = s2. length (); // store lengths of s1 and s2 bool same ; // -------------------------------------------------------------------- FILL IN HERE // -------------------------------------------------------------------- if ( same ) cout << " The strings are the same." << endl ; else cout << " The strings are not the same." << endl ; In the blank space below, write (with your pen or pencil) the missing code. Page 7

Solution: for ( int i =0; i< length1 ; i ++) if( A <=s1[i] && s1[i]<= Z ) s1[i] = char (s1[i]- A + a ); for ( int i =0; i< length2 ; i ++) if( A <=s1[i] && s1[i]<= Z ) s2[i] = char (s2[i]- A + a ); same = (s1 == s2 ); Page 8