CSCE 206: Structured Programming in C++

Similar documents
CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

Exam 3 Chapters 7 & 9

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

CS2255 HOMEWORK #1 Fall 2012

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty!

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

Introduction to Computer Science Midterm 3 Fall, Points

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

CS201- Introduction to Programming Current Quizzes

Pointers. 1 Background. 1.1 Variables and Memory. 1.2 Motivating Pointers Massachusetts Institute of Technology

Exercise 1.1 Hello world

Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

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

C Pointers. 7.2 Pointer Variable Definitions and Initialization

Arrays. Week 4. Assylbek Jumagaliyev

CSC 1300 Exam 4 Comprehensive-ish and Structs

pointers + memory double x; string a; int x; main overhead int y; main overhead

Objectivities. Experiment 1. Lab6 Array I. Description of the Problem. Problem-Solving Tips

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)

Pointers and Arrays CS 201. This slide set covers pointers and arrays in C++. You should read Chapter 8 from your Deitel & Deitel book.

C++ Programming. Arrays and Vectors. Chapter 6. Objectives. Chiou. This chapter introduces the important topic of data structures collections

Lecture 05 POINTERS 1

CS162 - POINTERS. Lecture: Pointers and Dynamic Memory

Multiple Choice Questions (20 questions * 5 points per question = 100 points)

Review Questions for Final Exam

Review. Outline. Array Pointer Object-Oriented Programming. Fall 2013 CISC2200 Yanjun Li 1. Fall 2013 CISC2200 Yanjun Li 2

Pointers and Strings. Adhi Harmoko S, M.Komp

Review. Outline. Array Pointer Object-Oriented Programming. Fall 2017 CISC2200 Yanjun Li 1. Fall 2017 CISC2200 Yanjun Li 2

Arrays. Returning arrays Pointers Dynamic arrays Smart pointers Vectors

Homework #3 CS2255 Fall 2012

Multiple Choice Questions (20 questions * 6 points per question = 120 points)


Exam 1 Practice CSE 232 Summer 2018 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

Week 3: Pointers (Part 2)

What is an algorithm?

CSE030 Fall 2012 Final Exam Friday, December 14, PM

Chapter 9: Pointers Co C pyr py igh i t gh Pear ea so s n n E ducat ca io i n, n Inc. n c.

C++ ARRAYS POINTERS POINTER ARITHMETIC. Problem Solving with Computers-I

Pointers and Strings Prentice Hall, Inc. All rights reserved.

UNIVERSITY OF WINDSOR Fall 2007 QUIZ # 2 Solution. Examiner : Ritu Chaturvedi Dated :November 27th, Student Name: Student Number:

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

Agenda / Learning Objectives: 1. Map out a plan to study for mid-term Review the C++ operators up to logical operators. 3. Read about the tips

Sample Final Exam. 1) (24 points) Show what is printed by the following segments of code (assume all appropriate header files, etc.

Programación de Computadores. Cesar Julio Bustacara M. Departamento de Ingeniería de Sistemas Facultad de Ingeniería Pontificia Universidad Javeriana

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

REFERENCES, POINTERS AND STRUCTS

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

Lecture 14. No in-class files today. Homework 7 (due on Wednesday) and Project 3 (due in 10 days) posted. Questions?

Output of sample program: Size of a short is 2 Size of a int is 4 Size of a double is 8

Part 1 (80 points) Multiple Choice Questions (20 questions * 4 points per question = 80 points)

Pointers, Dynamic Data, and Reference Types

CS 161 Exam II Winter 2018 FORM 1

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

(6) The specification of a name with its type in a program. (7) Some memory that holds a value of a given type.

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

Pointer Basics. Lecture 13 COP 3014 Spring March 28, 2018

CS 216 Fall 2007 Midterm 1 Page 1 of 10 Name: ID:

Pointers, Arrays and C-Strings

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

Unit 1: Preliminaries Part 4: Introduction to the Standard Template Library

Do not start the test until instructed to do so!

CSCI-1200 Data Structures Fall 2010 Lecture 8 Iterators

High Institute of Computer Science & Information Technology Term : 1 st. El-Shorouk Academy Acad. Year : 2013 / Year : 2 nd

! Determine if a number is odd or even. ! Determine if a number/character is in a range. ! Assign a category based on ranges (wind speed)

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays)

DYNAMIC ARRAYS; FUNCTIONS & POINTERS; SHALLOW VS DEEP COPY

CSCI-1200 Data Structures Fall 2014 Lecture 8 Iterators

Spring 2002 Page 1 of 8 READ THIS NOW!

Practice Problems CS2620 Advanced Programming, Spring 2003

7.1. Chapter 7: Arrays Hold Multiple Values. Array - Memory Layout. Array Terminology. Array Terminology 8/23/2014. Arrays Hold Multiple Values

CSCI-1200 Data Structures Fall 2017 Lecture 9 Iterators & STL Lists

CS201 Latest Solved MCQs

double d0, d1, d2, d3; double * dp = new double[4]; double da[4];

Lab 2: Pointers. //declare a pointer variable ptr1 pointing to x. //change the value of x to 10 through ptr1

Midterm Practice Exam

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

[0569] p 0318 garbage


Sol. Sol. a. void remove_items_less_than(int arr[], int size, int value) #include <iostream> #include <ctime> using namespace std;

Chapter 7: Arrays Copyrig opy ht rig 2012 Pea e rson a Educa Educ ti a on, Inc I. nc

CSCE 2014 Final Exam Spring Version A

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

Exam 2. CSC 121 MW Class. Lecturer: Howard Rosenthal. April 26, 2017

Introducing C++ to Java Programmers

CS31 Discussion. Jie(Jay) Wang Week8 Nov.18

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

Review of Important Topics in CS1600. Functions Arrays C-strings

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

Algorithms for Arrays Vectors Pointers CS 16: Solving Problems with Computers I Lecture #14

C++ PROGRAMMING SKILLS Part 4: Arrays

ECE264 Spring 2013 Final Exam, April 30, 2013

CS31 Discussion 1E Spring 17 : week 08

Midterm Review. PIC 10B Spring 2018

CSCI-1200 Data Structures Spring 2014 Lecture 5 Pointers, Arrays, Pointer Arithmetic

Note 12/1/ Review of Inheritance Practice: Please write down 10 most important facts you know about inheritance...

Programming for Engineers Arrays

Transcription:

CSCE 206: Structured Programming in C++ 2017 Spring Exam 3 Monday, April 17, 2017 Total - 100 Points A Instructions: Total of 11 pages, including this cover and the last page. Before starting the exam, count the pages to make sure you have all 11. Read the questions and instructions carefully to see what kind of answer is expected. Some code snippets may not have the header and std namespace inclusion, but assume that there are included. Put the Exam Code on your scantron in the lower right corner There are 50 questions worth 2 points each. On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work Signature: Name (Print): UIN: Section: 1

TRUE/FALSE: Select A if the statement is true and B if the statement is false. 1) In a two-dimensional array declaration, the first size declarator specifies the number of rows, and the second size declarator specifies the number of columns. 2) The binary search performs at most log 2 N comparisons 3) The first element of an array has an index of 0. 4) The maximum number of dimensions an array can have is two. 5) C++ performs a check to make sure that a program does not try to access a subscript beyond the bound of an array. 6) To copy one array to another, each element must be copied one-by-one. 7) For an array called a with 10 elements, a[10] will return the last element a. 8) The following code snippet prints 11 38 int main() { int table[1][2] = {38,11}; cout << table[0][1]<<" "; cout << table[0][0]; return 0; } 9) When an array that has been passed to a function is modified, the original array is modified as well. 10) When a multi-dimensional array is passed to a function as a papameter, it is required to specify all but 1 st dimension in the prototype and header. 11) A bubble sort can only arrange data into ascending order. 12) A vector object automatically expands in size to accommodate the items stored in it. 2

13) The output of the following program is 0. int main() { vector<int> V1(20,20); vector<int> V2(V1); cout << V2[18]; return 0; } 14) If arr is an array of integers, the following statement will display the contents of arr. cout << arr << endl; 15) With pointer variables you can access, but you cannot modify, data in other variables. MULTIPLE CHOICE: Choose the the single option that best completes the statement or answers the question. 16) What will the following code output? int *numbers = new int[5]; for (int i = 0; i <= 4; i++) *(numbers + i) = i; cout << numbers[2] << endl; A) Five memory addresses B) 0 C) 3 D) 2 E) 1 17) Which of the following are valid array definitions? A) int array[5]; B) int array[] = {0, 0, 0, 0, 0}; C) int array[3] = {1, 2, 3}; D) A and B E) A, B, and C 3

18) When you work with a dereferenced pointer, you are working with. A) The actual value of the variable whose address is stored in the pointer variable B) A copy of the value pointed to by the pointer variable C) A reference of the variable pointed to by the pointer variable D) A value of a string variable E) Both B and C 19) What is the output of the following code snippet char arr[100]; int i; for(i = 0; i < 10; i++) { *(arr + i) = 65 + i + 2; } *(arr + i) = '\0'; cout << arr; A) ABCDEFGHIJ B) AAAAAAAAAA C) JJJJJJJJ D) CDEFGHIJKL E) 67697173757779818385 20) What is the main disadvantage of the binary search algorithm? A) It is inefficient B) The elements must be sorted first C) It only works for binary numbers D) It is difficult to program E) There are no disadvantages 21) What is the output of the following program? int n = 0; int *nptr = n; cout << *nptr; A) The value of n B) The address of n C) The address of nptr D) A compiler error E) The value stored in nptr 4

22) What is the output of the following program? int n = 10, *nptr = &n; cout << *nptr; A) The value of n (i.e. 10) B) The address of n C) The address of nptr D) No output E) Garbage value 23) Before performing linear search, the array elements must be, A) Summed B) Set to zero C) Sorted in either increasing or decreasing order D) Positive numbers E) No constraints 24) What is the output of the following code snippet char i = 't'; char* ptr = &i; cout<<sizeof(ptr)<<" "; cout<<sizeof(*ptr); A) 1 1 B) 1 4 C) 4 1 D) 4 4 E) 4 8 25) This vector function returns the number of elements in a vector. A) length() B) num_elements() C) elements() D) size() E) count() 5

26) The operator is used to declare an array. A) [] B) & C) * D)? E) () 27) What is the output of the following code snippet const int t = 100; int q = 36; const int* ptr = &t; cout << *ptr << " "; ptr = &q; cout << *ptr; A) 36 100 B) 100 36 C) 36 36 D) Compilation error E) Run time error 28) What is the output of the following code snippet? int a[3] = {5}; for (int i = 0; i < 3; i++) cout << a[i] << " "; A) 5 5 5 B) 5 0 0 C) 0 0 0 D) 0 0 5 E) 5 0 5 29) Given an array containing {1, 4, 6, 12, 18, 26, 33}, a linear search will take comparisons to find the value 26 and a binary search will take comparisons. A) 2, 2 B) 2, 6 C) 6, 2 D) 2, 5 E) 5, 2 6

30) A variable that can store multiple values of the same type is called a(n): A) Array B) List C) Collection D) Set E) Multi-element variable 31) Which of the following is a valid way to access the third element of an array named arr? A) *(arr) + 3 B) *(arr + 3) C) arr[3] D) A and C E) B and C 32) A variable that holds an address is called. A) An address variable B) A pointer variable C) A reference variable D) A dereference variable E) A stack variable 33) The effect of using the ++ operator with an int pointer variable is ( e.g., ptr++) A) The value the pointer points to is incremented by one B) The address the pointer is holding is incremented by one C) The address the pointer is holding is incremented by the size of a single int D) The ++ can t be used on pointers E) The outcome is compiler dependent 34) In a local array, all elements are initialized to by default. A) 0 B) 1 C) -1 D) Uninitialized or garbage value E) Local value 35) How many swaps does a bubble sort require to sort the array {1,2,3,4} in descending order? A) 5 B) 4 C) 7 D) 6 E) Depends on the compiler 7

36) Which statement correctly defines a vector object for holding integers? A) vector v<int>; B) int vector v; C) vector<int> v; D) int<vector> v; E) <int> vector v; 37) What is the output of the following code? int arr[] = {0, 6, 2, 7}; int *arrptr = arr; cout << arrptr[2]; A) 2 B) 6 C) A garbage value D) 0 E) 7 38) When the less than ( < ) operator is used between two pointer variables ( ptr1 < prt2 ), the expression is testing whether. A) The first variable was declared before the second variable B) The value pointed to by the first variable is less than the value pointed to by the second variable C) The value pointed to by the first variable is greater than the value pointed to by the second variable D) The address stored in the first variable comes before the address stored in the second variable E) This operation is illegal 39) What will the following code display? int numbers[] = { 99, 87, 66, 55, 101 }; for (int i = 1; i < 4; i++) { cout << numbers[i] << " "; } A) 99 87 66 55 101 B) 87 66 55 101 C) 87 66 55 D) 99 87 66 E) 87 101 8

40) The, also known as the address operator, returns the memory address of a variable. A) & B) * C)! D) % E) &* 41) The keyword is used to dynamically allocate memory. A) allocate B) mem C) mallalloc D) new E) memnew 42) This vector function returns false if the vector contains more than 0 elements. A) has_no_elements() B) null_size() C) empty() D) is_empty() E) zero_size() 43) The sort is usually more efficient than the sort. A) Selection, bubble B) Binary, linear C) Bubble, selection D) ANSI, ASCII E) Bubble_Advanced, bubble 44) This algorithm starts at the first element of an array and steps through, examining each element until it locates the value it is searching for. A) Linear Search B) Binary Search C) Bubble Sort D) Selection Sort 45) Two or more array that contain related data are called. A) Adjacent arrays B) Multi-dimensional arrays C) Parallel arrays D) Equivalent arrays E) Related arrays 9

46) The keyword is used to free dynamically allocated memory. A) delete B) free C) release D) erase E) empty 47) What is the output of the following program? int a[] = {1, 1, 2, 3, 5}; for (int i = 0; i <= 5; i+=2) { cout << a[i] << " "; } A) 1 1 2 3 5 B) 1 2 5 C) 1 1 2 3 5 plus a garbage value D) 1 2 5 plus a garbage value E) 1 2 5 0 48) What is the output of the following code snippet? int i = 0; int a[] = {11, 38}; cout << a[i]++ << " " << a[i++]; A) 12 38 B) 11 12 C) 38 11 D) 38 12 E) Garbage value 49) Sorting algorithms can arrange values into which of the following orders: A) Equally spaced order B) Ascending C) Descending D) B and C E) A and B 10

50) An array that is initialized with fewer elements than its size is called a. A) Incomplete array B) Partially-filled array C) Semi-filled array D) fewer elements array E) Will cause a compilation error 11