CS 1044 Homework Assignment 4 Summer I 2001

Similar documents
The University of Alabama in Huntsville Electrical and Computer Engineering CPE Example of Objective Test Questions for Test 4

C++ Final Exam 2017/2018

Do not start the test until instructed to do so!

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

CS Spring 05 - MidTerm

Spring 2002 Page 1 of 8 READ THIS NOW!


True or False (14 Points)

1. Which of the following best describes the situation after Line 1 has been executed?

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.

CMPS 221 Sample Final


Instructions: Submit your answers to these questions to the Curator as OQ02 by the posted due date and time. No late submissions will be accepted.

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

9. Arrays. Compound Data Types: type name [elements]; int billy [5];

CS201- Introduction to Programming Current Quizzes

Programming Language. Functions. Eng. Anis Nazer First Semester

Arrays. Comp Sci 1570 Introduction to C++ Array basics. arrays. Arrays as parameters to functions. Sorting arrays. Random stuff

Chapter 01 Arrays Prepared By: Dr. Murad Magableh 2013

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

FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each):

5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (!

Tutorial 8 (Array I)

Definition Matching (10 Points)

Review Problems for Final Exam. 1. What is the output of the following program? #include <iostream> #include <string> using namespace std;

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

CPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points)

Solving a 2D Maze. const int WIDTH = 10; const int HEIGHT = 10;

Chapter 4 Computer Science with C++ Name: Review Worksheet A Mr. Ferwerda

For questions 4 through 7, select the value assigned to the relevant variable, given the declarations: 3) ) This is not allowed

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

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

True or False (15 Points)

Fundamentals of Programming CS-110. Lecture 2

FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

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

Introduction to Programming EC-105. Lecture 2

Programming in C++ The manager of a company. Lecture Notes 6. Functions (Procedures) 4/24/2018. he he he. Does Does Does

Declaring a 2D Array

CS 115 Exam 2, Fall 2009

arrays review arrays and memory arrays: character array example cis15 advanced programming techniques, using c++ summer 2008 lecture # V.

CSCE 2004 Final Exam Spring Version A

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

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

BITG 1233: Array (Part 1) LECTURE 8 (Sem 2, 17/18)

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

CS 115 Exam 3, Spring 2011

11. Arrays. For example, an array containing 5 integer values of type int called foo could be represented as:

BITG 1113: Array (Part 1) LECTURE 8

CS242 COMPUTER PROGRAMMING

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

Outline. Introduction. Arrays declarations and initialization. Const variables. Character arrays. Static arrays. Examples.

Computer Programming

what are strings today: strings strings: output strings: declaring and initializing what are strings and why to use them reading: textbook chapter 8

LAB 4.1 Relational Operators and the if Statement

CS 240 Computer Programming 1 Arrays

DYNAMIC ARRAYS; FUNCTIONS & POINTERS; SHALLOW VS DEEP COPY

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

Data types. CISC 1600/1610 Computer Science I. Array syntax. Memory allocation. Zero-indexing 4/4/2016. Arrays

Exercise 1.1 Hello world

C++ Program Flow Control: Selection

Programming with Arrays Intro to Pointers CS 16: Solving Problems with Computers I Lecture #11

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Fri, Jan 18, 2013

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II:

Programming in C++: Assignment Week 1

1. In C++, reserved words are the same as predefined identifiers. a. True

Review Summer CSC1322 Adv Programming in C++ Professor: Zhang

Computer Science II Lecture 2 Strings, Vectors and Recursion

Chapter 8 Arrays and Strings. Objectives. Objectives (cont d.) Introduction. Arrays 12/23/2016. In this chapter, you will:

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

Programming. C++ Basics

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

BITG 1113: POINTER LECTURE 12

Thus, to declare billy as shown above it would be something as simple as the following sentence:

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Mon, Jan 20, 2014

Programming in C++: Assignment Week 8

CSCI-1200 Data Structures Spring 2016 Lecture 7 Iterators, STL Lists & Order Notation

As an example using arrays, let s write some code to get started with the Upthrust game. We can use a 2D array to represent the game board.

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

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

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

Chapter 4: Subprograms Functions for Problem Solving. Mr. Dave Clausen La Cañada High School

CSci 1113 Midterm 1. Name: Student ID:

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

STRUCTURED DATA TYPE ARRAYS IN C++ ONE-DIMENSIONAL ARRAY TWO-DIMENSIONAL ARRAY

a data type is Types

! Pass by value: when an argument is passed to a. ! It is implemented using variable initialization. ! Changes to the parameter in the function body

CSCI 111 First Midterm Exam Spring Solutions 09.05am 09.55am, Wednesday, March 14, 2018

Answer all of the following questions (66 points)

Abstract Data Type (ADT) & ARRAYS ALGORITHMS & DATA STRUCTURES I COMP 221

CS Exam 2 Study Suggestions

Chapter 4 - Notes Control Structures I (Selection)

C++ Lecture 5 Arrays. CSci 588: Data Structures, Algorithms and Software Design.

Array Elements as Function Parameters

BITG 1113: Function (Part 2) LECTURE 5

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

Classes, objects. Static, const, mutable members of a class

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

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

Chapter 7 - Notes User-Defined Functions II

Transcription:

Instructions: This homework assignment focuses on the basics of C++ arrays. The answers to the following questions can be determined from Chapters 3 through 9 of the lecture notes and Chapters 11 and 12 of the text. Assume any #include directives, variable declarations, etc, which are needed to make the given code syntactically correct. 1) Given the declaration: double Alpha[75]; the logically valid range of index values for alpha is: 1) 0 through 75 2) 0 through 74 3) 1 through 75 4) 1 through 74 5) 1 through 76 2) What is the output of the following program fragment? int Gamma[3] = {5, 10, 15; for (int i = 0; i < 3; i++) cout << Gamma[i] << ' '; 1) 5 10 15 2) 5 10 3) 0 1 2 4) 0 1 5) Cannot be determined from the information given. 3) Given the array declaration: int status[10]; which of the following loops correctly stores zeros at each valid index of the array status[]? 1) for (int i = 0; i <= 10; i++) 2) for (int i = 1; i < 10; i++) 3) for (int i = 1; i <= 10; i++) 4) for (int i = 0; i < 10; i++) 5) for (int i = 1; i <= 11; i++) 4) You are writing a program to count the frequencies of characters that are read from a data file. (The computer uses the extended ASCII character set, which defines 256 different characters.) Which of the following array declarations is most appropriate, given that input characters will be used to index into the freqcount[] array? 1) char freqcount[256]; 2) char freqcount[int]; 3) int freqcount[256]; 4) int freqcount[char]; Due: see course website Page 1 of 5

For questions 5 and 6, consider execution of the code fragment: int Arr[5]; int i; for (i = 0; i < 5; i++) { Arr[i] = i + 2; if (i >= 3) Arr[i-1] = Arr[i] + 3; 5) What value will be contained in Arr[1]? 1) 2 2) 3 3) 7 4) 8 6) What value will be contained in Arr[3]? 1) 2 2) 3 3) 7 4) 8 7) What is the output of the following program fragment? int Alpha[5] = {100, 200, 300, 400, 500; int i; for (i = 4; i > 0; i--) cout << Alpha[i] << ' '; 1) 400 300 200 100 2) 500 400 300 200 100 3) 500 400 300 200 4) 4 3 2 1 5) It cannot be answered from the information given. 8) Given a 5000-element integer array Beta[], which of the code fragments below could be used to print out the values of Beta[0], Beta[2], Beta[4], and so forth? 1) for (int i = 0; i < 5000; i = i + 2) cout << beta[i] << endl; 2) for (int i = 0; i < 2500; i++) cout << beta[2*i] << endl; 3) for (int i = 0; i < 2500; i++) cout << beta[i]*2 << endl; 4) all of the above 5) 1 and 2 only Due: see course website Page 2 of 5

Questions 9 through 11 refer to the following incomplete program: void FillEm( arr1[], arr2[], int length); // line 1 void Copy( arr1[], arr2[], int length); // line 2 void main() { const int dim = 200; char alpha[dim]; char beta[dim]; FillEm(alpha, beta, dim); Copy(alpha, beta, dim); // Initialize arrays alpha and beta // Copy all components of beta into alpha void Copy( arr1[], arr2[], int length) { for (int Idx = 0; Idx < length; Idx++) { arr1[idx] = arr2[idx]; return; void FillEm( arr1[], arr2[], int length) { // some initialization code goes here 9) What is the most appropriate way to fill the blank preceding the first formal parameter of FillEm() in line 1? 10) What is the most appropriate way to fill the blank preceding the first formal parameter of Copy() in line 2? 11) What is the most appropriate way to fill the blank preceding the second formal parameter of Copy() in line 2? Due: see course website Page 3 of 5

12) Which of the following code fragments can be used to input values into a 3-element int array named Alpha? 1) cin >> Alpha[0] >> Alpha[1] >> Alpha[2]; 2) cin >> Alpha; 3) for (i = 0; i < 3; i++) cin >> Alpha[i]; 4) cin >> Alpha[0]; cin >> Alpha[1]; cin >> Alpha[2]; 5) All of them 6) 1 and 4 only 7) 1, 3 and 4 only 8) None of them 13) You are writing a program to keep track of majors for a collection of students. Given the following declarations const int MAXSTUDENTS = 100; const int NUMMAJORS = 4; const string MAJORS[NUMMAJORS] = {"CS", "CpE", "Math", "Other"; which of the following will properly declare two parallel arrays for storing student names and majors? 1) string Name[MAXSTUDENTS]; string Major[NUMMAJORS]; 2) string Name[MAXSTUDENTS]; string Major[MAXSTUDENTS]; 4) All of them 5) 1 and 2 only 6) 1 and 3 only 7) 2 and 3 only 8) None of them 3) string Name[NUMMAJORS]; string Major[NUMMAJORS]; For questions 14 through 17, assume that the following are global declarations in a program: const int NOMATCH = -1; const int NUMMAJORS = 4; const string MAJORS[NUMMAJORS] = {"CS", "CpE", "Math", "Other"; The following function should search the array MAJORS[] for the string tofind, and return the index of the matching string or an error indicator, as appropriate: int FindMajor( tofind) { // line 1 int Idx; // line 2 for (Idx = 0; ; Idx++) { // line 3 if ( == tofind) // line 4 return ; // line 5 return NOMATCH; // line 6 14) What is the most appropriate way to fill the blank preceding the formal parameter tofind in line 1? 1) string 2) string& 3) const string& Due: see course website Page 4 of 5

15) What is the most appropriate way to fill the blank in line 3? 1) Idx < NUMMAJORS 2) Idx <= NUMMAJORS 3) Idx < MAJORS.length() 16) What is the most appropriate way to fill the blank in line 4? 1) MAJORS[NUMMAJORS] 2) MAJORS[Idx] 3) MAJORS 17) What is the most appropriate way to fill the blank in line 5? 1) MAJORS[NUMMAJORS] 2) MAJORS[Idx] 3) MAJORS 18) Given the declarations below, how many components of type double does Depth have? const int HEIGHT = 100; const int WIDTH = 50; double Depth[HEIGHT][WIDTH]; 1) 100 2) 50 3) 99 * 49 4) 100 * 50 5) None, they are of type int. 19) Given the declarations from question 18, the expression Depth[5][3] refers to: 1) the third element of the fifth row of Depth 2) the fifth element of the third row of Depth 3) the fourth element of the sixth row of Depth 4) the sixth element of the fourth row of Depth 5) The expression is not allowed. 20) Given the declarations below, the elements of X could be copied to the corresponding locations in Y by: char X[100], Y[100]; 1) the statement: Y = X; 2) the statement: Y[] = X[]; 3) a user-defined function to which X and Y are passed 4) All of these. 5) 1 and 3 only 6) The elements of Y cannot possibly be copied into X. 7) None of these Due: see course website Page 5 of 5