Chapter 9 Review-C++ True/False Indicate whether the sentence or statement is true or false.

Similar documents
Answers to Review Questions Chapter 7

An Incomplete C++ Primer. University of Wyoming MA 5310

Introduction to Java

The University of Alabama in Huntsville Electrical and Computer Engineering CPE Test #4 November 20, True or False (2 points each)

Passing 1D arrays to functions.

COMPUTER SCIENCE. Paper 1 (THEORY)

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Basics of I/O Streams and File I/O

Arrays in Java. Working with Arrays

VB.NET Programming Fundamentals

Using C# for Graphics and GUIs Handout #2

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Pseudo code Tutorial and Exercises Teacher s Version

13 Classes & Objects with Constructors/Destructors

1. Use the class definition above to circle and identify the parts of code from the list given in parts a j.

Problem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class

Project 2: Bejeweled

One Dimension Array: Declaring a fixed-array, if array-name is the name of an array

AP Computer Science Java Mr. Clausen Program 9A, 9B

Chapter 13 Storage classes

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c

Arrays in Java. data in bulk

Conditionals (with solutions)

Functions Recursion. C++ functions. Declare/prototype. Define. Call. int myfunction (int ); int myfunction (int x){ int y = x*x; return y; }

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Unit 6. Loop statements

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

I PUC - Computer Science. Practical s Syllabus. Contents

Sources: On the Web: Slides will be available on:

JAVA ARRAY EXAMPLE PDF

LabVIEW Day 6: Saving Files and Making Sub vis

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

arrays C Programming Language - Arrays

Member Functions of the istream Class

Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT

In this Chapter you ll learn:

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

Lecture 22: C Programming 4 Embedded Systems

Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays:

Programming Database lectures for mathema

J a v a Quiz (Unit 3, Test 0 Practice)

Laboratory Assignments of OBJECT ORIENTED METHODOLOGY & PROGRAMMING (USING C++) [IT 553]

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

In This Issue: Excel Sorting with Text and Numbers

Goals for This Lecture:

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 3: Input/Output

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

Arrays. number: Motivation. Prof. Stewart Weiss. Software Design Lecture Notes Arrays

Name = array(x,y,...,z) the indexing starts at zero, i.e. Name(0) = x. Programming Excel/VBA Part II (A.Fring)

Two-Dimensional Arrays. Multi-dimensional Arrays. Two-Dimensional Array Indexing

Unit Write iterative and recursive C functions to find the greatest common divisor of two integers. [6]

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Lab Experience 17. Programming Language Translation

JAVA - METHODS. Method definition consists of a method header and a method body. The same is shown below:

Quosal Form Designer Training Documentation

Final Examination Semester 2 / Year 2011

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Two-Dimensional Arrays Summer 2010 Margaret Reid-Miller

Example of a Java program

Object-Oriented Programming in Java

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Building Java Programs

Iteration CHAPTER 6. Topic Summary

The design recipe. Programs as communication. Some goals for software design. Readings: HtDP, sections 1-5

Stacks. Linear data structures

2D Data Matrix Supplier Label Specification

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl

5 Arrays and Pointers

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

C++ INTERVIEW QUESTIONS

1 Abstract Data Types Information Hiding

Lesson 10: Video-Out Interface

Illustration 1: Diagram of program function and data flow

Welcome to the topic on Master Data and Documents.

7.7 Case Study: Calculating Depreciation

Moving from C++ to VBA

Introduction to Data Structures

Chapter 5 Functions. Introducing Functions

AP Computer Science Java Subset

Chapter 2: Elements of Java

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

Tutorial on C Language Programming

ENGI E1112 Departmental Project Report: Computer Science/Computer Engineering

Introduction to Java. CS 3: Computer Programming in Java

Introduction to Lex. General Description Input file Output file How matching is done Regular expressions Local names Using Lex

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

Chapter 4 OOPS WITH C++ Sahaj Computer Solutions

IS0020 Program Design and Software Tools Midterm, Feb 24, Instruction

CS1112 Spring 2014 Project 4. Objectives. 3 Pixelation for Identity Protection. due Thursday, 3/27, at 11pm

Moving from CS 61A Scheme to CS 61B Java

12-6 Write a recursive definition of a valid Java identifier (see chapter 2).

PROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE

Recursion and Recursive Backtracking

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Transcription:

Chapter 9 Review-C++ True/False Indicate whether the sentence or statement is true or false. 1. It is legal to use the assignment operator (=) with character arrays. 2. The array arr[30] contains 30 elements. 3. Templates have prototypes. 4. In C++, "Baby" is considered greater than "Bunny". 5. A function cannot return a value of the type array. 6. Given the declaration string str[8] and assuming that all of the elements in str contain strings that are at least 5 characters long str[3][2] refers to the third character in the second element of str. 7. The declaration int nums[] = 2,3,4,5}; declares nums to be an array of integers, size 4. 8. In C++, when using < and > with string objects, you are comparing each entire string alphabetically. 9. In C++, tolower()takes a parameter of a string. 10. The following is a correct function definition: void myfun(const int arr[5][2]) <function body> } 11. Arrays, by default, are passed by reference. 12. To display a two dimensional array, you must use a nested loop. 13. When you specify the size of a two dimensional array, the first number represents the number of rows and the second number represents the number of columns. 14. In the following declaration, the array gamma has 11 components int gamma[5][6];. 15. Templates allow you to write functions that will work for more than one data type. Multiple Choice Identify the letter of the choice that best completes the statement or answers the question. 16. Which of the following statements declares alpha to be an array of 25 components of the type int? a. int alpha[25]; c. int alpha[2][5]; b. int array alpha[25]; d. int array alpha[25][25]; 17. Assume you have the following declaration double salesdata[1000];. Which of the following ranges is valid for the indices of the array salesdata? a. 0 through 999 c. 1 through 1001 b. 0 through 1000 d. 1 through 1000 18. Consider the declaration below. Which of the following codes correctly outputs all the elements of list?

a. for(j = 1; j < 10; j++) cout<<list[j]<<" "; cout<<endl; b. for(j = 0; j <= 9; j++) cout<<list[j]<<" "; cout<<endl; c. for(j = 1; j < 11; j++) cout<<list[j]<<" "; cout<<endl; d. for(j = 1; j <= 10; j++) cout<<list[j]<<" "; cout<<endl; 19. What is the output of the C++ code below? a. 0 1 2 3 4 c. 0 5 10 15 20 b. 0 5 10 15 d. 5 10 15 20 20. Which of the following is a correct way to begin a template function? a. template <type whatever> c. template <typename double> b. template <type int> d. template <typename whatever> 21. Given the declaration below, which of the following for loops sets the index of gamma out of bounds?

a. for(j = 0; j <= 49; j++) cout<<gamma[j]<<" "; b. for(j = 1; j < 50; j++) cout<<gamma[j]<<" "; c. for(j = 0; j <= 50; j++) cout<<gamma[j]<<" "; d. for(j = 0; j <= 48; j++) cout<<gamma[j]<<" "; 22. What is the value of alpha[4] after the code below executes? a. 5 c. 11 b. 8 d. 14 23. What is the value of alpha[3] after the code below executes? a. 10 c. 15 b. 13 d. 17 24. What is stored in alpha after the code below executes?

a. alpha = 0, 2, 4, 6, 8} b. alpha = 0, 2, 9, 6, 8} c. alpha = 0, 3, 4, 7, 8} d. alpha = 3, 2, 9, 6, 8} 25. What is the output of the C++ code below? a. 2 4 6 8 10 c. 8 6 4 2 0 b. 4 3 2 1 0 d. 10 8 6 4 2 26. What is the value of alpha[3][2] after the code below executes? int alpha[5][5]= 1, 2, 3, 4, 5}, 6, 7, 8, 9, 10}, 11, 12, 13, 14, 15}, 16, 17, 18, 19, 20}, 21, 22, 23, 24, 25} }; a. 8 c. 14 b. 13 d. 18 27. Consider the following statement: int alpha[25][10];. Which of the following statements about alpha is true? a. Rows of alpha are numbered 0...24 and columns are numbered 0...9. b. Rows of alpha are numbered 0...24 and columns are numbered 1...10. c. Rows of alpha are numbered 1...24 and columns are numbered 0...9. d. Rows of alpha are numbered 1...25 and columns are numbered 1...10.

28. Given the declaration below, which of the following correctly finds the sum of the elements of the fifth row of sale? a. sum = 0; for(j = 0; j < 7; j++) sum = sum + sale[5][j]; b. sum = 0; for(j = 0; j < 7; j++) sum = sum + sale[4][j]; c. sum = 0; for(j = 0; j < 10; j++) sum = sum + sale[5][j]; d. sum = 0; for(j = 0; j < 10; j++) sum = sum + sale[4][j]; 29. After the statements below execute, what are the contents of matrix? a. 0 2 4 1 3 5 2 4 6 3 5 7 b. 0 1 2 1 2 3 2 3 4 3 4 5 c. 0 2 4 2 4 6 4 6 8 6 8 10 d. 0 1 2 2 3 4 4 5 6 6 7 8 30. In C++, which of the following strings would be considered the "greatest?" a. "yellow" c. "Blue" b. blue d. Yellow

Short Answer For the following problems, you should assume that iostream is the only header file that has been included!!!! 31. Write the function definition. Call the function wordcounter. It has two parameters: an array of strings and a character. The function should return an int. The return value represents the number of words in the array that start with the character. You can assume the array has a size of 100. 32. Write a template function called fillarray that takes an array of any data type, size 10. The function will also take an argument that is a single specific value to store in the array. The function will fill the array passed in with the value specified. The function will not return anything. The array should be changed by this function! Example : fillarray(a, 5); will assign 5 to every element of array a, assuming that a is an array of ints.

Chapter 9 Review Answer Section TRUE/FALSE 1. ANS: F 2. ANS: T 3. ANS: F 4. ANS: F 5. ANS: T 6. ANS: F 7. ANS: T 8. ANS: T 9. ANS: F 10. ANS: T 11. ANS: T 12. ANS: T 13. ANS: T 14. ANS: F 15. ANS: T MULTIPLE CHOICE 16. ANS: A 17. ANS: A 18. ANS: B 19. ANS: C 20. ANS: D 21. ANS: C 22. ANS: D 23. ANS: B 24. ANS: D 25. ANS: D 26. ANS: D 27. ANS: A 28. ANS: B 29. ANS: D 30. ANS: A

SHORT ANSWER 31. ANS: int wordcounter(const string s[], char c) int count=0; for(int x=0; x<100; x++) if(s[x][0]==c) count++; } return count; } 32. ANS: template <typename any> int fillarray(any arr[], any item) for(int x=0; x<10; x++) arr[x]=item; }