Answers to Review Questions Chapter 7



Similar documents
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

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

Passing 1D arrays to functions.

VB.NET Programming Fundamentals

Arrays in Java. Working with Arrays

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

13 Classes & Objects with Constructors/Destructors

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

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

The While Loop. Objectives. Textbook. WHILE Loops

Chapter One Introduction to Programming

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

Moving from C++ to VBA

In this Chapter you ll learn:

Introduction to Java

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

C++ Input/Output: Streams

arrays C Programming Language - Arrays

Comp151. Definitions & Declarations

7.7 Case Study: Calculating Depreciation

5 Arrays and Pointers

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

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

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

Chapter 8 Selection 8-1

Data Structures using OOP C++ Lecture 1

Common Beginner C++ Programming Mistakes

Formatting Numbers with C++ Output Streams

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

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Basics of I/O Streams and File I/O

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

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

Chapter 2: Elements of Java

C++FA 5.1 PRACTICE MID-TERM EXAM

CSI33 Data Structures

Two-Dimensional Arrays Summer 2010 Margaret Reid-Miller

Sequential Program Execution

The if Statement and Practice Problems

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification:

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

Cpt S 223. School of EECS, WSU

COMPUTER SCIENCE 1999 (Delhi Board)

Chapter 2 Introduction to Java programming

Schedule. Structures and Classes in C++ Outline. Goals for This Topic. Another Example of a Structure. What is a Structure? Classes May 12-17, 2005

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

PIC 10A. Lecture 7: Graphics II and intro to the if statement

Stacks. Linear data structures

Functional Programming in C++11

Chapter 5 Functions. Introducing Functions

Number Representation

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

6. Control Structures

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

Member Functions of the istream Class

Iteration CHAPTER 6. Topic Summary

Solving Problems Recursively

Informatica e Sistemi in Tempo Reale

Answers to Mini-Quizzes and Labs

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

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

C++FA 3.1 OPTIMIZING C++

Memory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example

Variables, Constants, and Data Types

While Loop. 6. Iteration

C++ program structure Variable Declarations

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control

MS ACCESS DATABASE DATA TYPES

Appendix K Introduction to Microsoft Visual C++ 6.0

Lecture 22: C Programming 4 Embedded Systems

Writing Control Structures

In This Lecture. SQL Data Definition SQL SQL. Notes. Non-Procedural Programming. Database Systems Lecture 5 Natasha Alechina

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Recursion. Slides. Programming in C++ Computer Science Dept Va Tech Aug., Barnette ND, McQuain WD

The C++ Language. Loops. ! Recall that a loop is another of the four basic programming language structures

Chapter 9 Text Files User Defined Data Types User Defined Header Files

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

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

Note: Syntactically, a ; is needed at the end of a struct definition.

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

Short Notes on Dynamic Memory Allocation, Pointer and Data Structure

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

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

Chapter 5. Selection 5-1

Using C# for Graphics and GUIs Handout #2

C++ INTERVIEW QUESTIONS

C++ Language Tutorial

Lecture 2 Notes: Flow of Control

Tutorial on C Language Programming

Basics of C++ and object orientation in OpenFOAM

Compiler Construction

Chapter 07: Instruction Level Parallelism VLIW, Vector, Array and Multithreaded Processors. Lesson 05: Array Processors

Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s

Transcription:

Answers to Review Questions Chapter 7 1. The size declarator is used in a definition of an array to indicate the number of elements the array will have. A subscript is used to access a specific element in an array. 2. The array has 10 elements. The subscript of the first element is 0. The subscript of the last element is 9. Using four-byte integers, this array uses 40 bytes of memory. 3. Because, with the array alone the function has no way of determining the number of elements it has. 4. 2 14 8 5. By providing an initialization list. The array is sized to hold the number of values in the list. 6. 3 0 7. Because an array name without brackets and a subscript represents the array's beginning memory address. The statement shown attempts to assign the address of array2 to array1, which is not permitted. 8. No. 9. By reference. 10. The array's beginning memory address. 11. By using the same subscript value for each array. 12. Eight elements Yes, it is null terminated. 13. Eight rows Ten columns Eighty elements sales[7][9] = 123.45; 14. The second size declarator, which is for the number of columns. 15. You do not have to declare the number of elements that a vector will have. If you add a value to a vector that is already full, the vector will automatically increase its size to accommodate the new value. A vector can report the number of elements it contains. 16. size declarator 17. integer, 0 18. subscript 19. 0 20. size declarator, subscript 21. bounds 22. initialization 23. 0

24. initialization list 25. null terminator 26. subscript 27. = 28. an address 29. address, or name 30. multi-dimensional 31. rows, columns 32. two 33. braces 34. column 35. Standard Template Library (or STL) 36. sequence and associative 37. sequence 38. vector 39. push_back 40. size 41. pop_back 42. clear 43. for (int i = 0; i < 20; i++) cout << names[i] << endl; 44. for (int i = 0; i < 100; i++) numberarray2[i] = numberarray1[i]; 45. const int SIZE = 10; int id[size]; // To hold ID numbers double weeklypay[size]; // To hold weekly pay // Display each employee's gross weekly pay. for (int i = 0; i < SIZE; i++) cout << "The pay for employee " << id[i] << " is $" << fixed << showpoint << setprecision(2) << weeklypay[i] << endl; 46. const int ROWS = 30, COLS = 10; int grades[rows][cols]; 47. const int SIZE = 12; char countries[size]; // To hold the country names long populations[size]; // To hold populations // Display each country's name and poplualtion. for (int i = 0; i < 12; i++)

cout << "The population of " << countries[1] << " is " << populations[i] << endl; 48. No, the correct sum will not be printed for numberarray2 because the accumulator (total) is not set back to zero before the second loop executes. 49. const int NUM_NAMES = 3, SIZE = 10; char mynames[num_names][size] = "Jason", "Lee", "Smith" ; 50. numberarray[0][0] = 145; numberarray[8][10] = 18; 51. int row, col; // Loop counters float total = 0.0; // Accumulator // Sum the values in the array. for (row = 0; row < 10; row++) for (col = 0; col < 20; col++) total += values[row][col]; 52. int row, col, // Loop counters total; // Accumulator // Display the sum of each row. for (row = 0; row < 29; row++) // Set the accumulator. total = 0; // Sum a row. for (col = 0; col < 5; col++) total += days[row][col]; // Display the row's total. cout << "The total for row " << row << " is " << total << endl; // Display the sum of each column. for (col = 0; col < 29; col++) // Set the accumulator. total = 0; // Sum a column. for (row = 0; row < 5; row++) total += days[row][col]; // Display the column's total.

cout << "The total for column " << col << " is " << total << endl; 53. false 54. true 55. true 56. false 57. true 58. false 59. false 60. true 61. false 62. true 63. true 64. false 65. false 66. false 67. true 68. false 69. true 70. false 71. true 72. true 73. true 74. true 75. true 76. false 77. false 78. true 79. false 80. true 81. true 82. false 83. true 84. The size declarator cannot be a variable. 85. The size declarator cannot be negative. 86. The loop will write data past the end of the array. 87. The initialization list must be enclosed in braces. 88. The string George Washington includes a null terminator, which makes it 18 characters in length. 89. Two of the initialization values are left out. 90. For the array to be implicitly sized there must be an initialization list. 91. A null terminator must be specified in the initialization list.

92. The assignment operator cannot be used to assign the contents of one array to another, in a single statement. 93. The parameter should be declared as int nums[]. 94. The parameter must specify the number of columns, not the number of rows.