Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Each of the following functions contains errors, Locate as many as you can. A) void showValues (Int nums) for (Int count = 0; count < 8; count++) cout \(\langle\langle\text { nums }[\text { count }]\) B) void showValues (int nums \([4][])\) for \((\text { rovs }=0: \text { rows }\langle 4: \text { rows++})\) For \((\operatorname{cols}=0: \operatorname{cols}<5: \operatorname{cols}++)\) cout \(<<\) nums [rows] [cols] :

Short Answer

Expert verified
Question: Identify and correct the errors in the given functions A and B. Function A: ``` void showValues (Int nums) for (Int count = 0; count < 8; count++) cout << nums[count] ``` Function B: ``` void showValues (int nums[4][]) for (rows=0: rows<4: rows++) For(cols=0: cols<5: cols++) cout << nums[rows][cols] ```

Step by step solution

01

Locate Errors in Function A

The given function A is: ``` void showValues (Int nums) for (Int count = 0; count < 8; count++) cout << nums[count] ``` The errors in function A are: 1. The function parameter should have a lowercase 'i' for int, not an uppercase 'I'. 2. The function parameter should be an array, so it should be followed by square brackets []. 3. The function body should be enclosed within curly braces {}. After correcting the errors, the corrected function A is: ``` void showValues (int nums[]) { for (int count = 0; count < 8; count++) { cout << nums[count]; } } ```
02

Locate Errors in Function B

The given function B is: ``` void showValues (int nums[4][]) for (rows=0: rows<4: rows++) For(cols=0: cols<5: cols++) cout << nums[rows][cols] ``` The errors in function B are: 1. The function parameter should specify the second dimension of the array. It should be followed by square brackets [][5]. 2. The loop variables 'rows' and 'cols' should be declared as int and properly initialized with for loop syntax using the semicolon (;) separator. 3. The nested for loops should use lowercase 'for' and must be enclosed within curly braces {}. After correcting the errors, the corrected function B is: ``` void showValues (int nums[][5]) { for (int rows=0; rows<4; rows++) { for (int cols=0; cols<5; cols++) { cout << nums[rows][cols]; } } } ```

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Diagrams are an important means of clarifying many programming concepts. You have seen them used throughout this book to illustrate such things as how the flow of control works for various programming constructs, how a program is broken into modules and those modules related, how data is stored in memory, and how data is organized. Here is a set of declarations that define how the data for a set of poker hands is organized. Create a neat diagram that illustrates this organization. The diagram in Section 7.4 of Chapter 7 on nested structures might give you an idea of how to begin. struct CardStruct Int face: char suit: \(\quad / /\) 's' \(,\) 'h', 'd', or 'c' struct Playerstruct int playerNum; CardStruct card [5] P1ayerStruct player [4]

The ________ indicates the number of elements, or values, an array can hold.

Use the following Car structure declaration to answer questions \(28-30\). struct Car string make model: Int year: double cost: // Constructors \(\operatorname{Car}()\) { make \(=\) model \(=" " ;\) year \(=\cos t=0: 1\) } Car(string mk, string md. int yr, double c) { make \(=\) whe model \(=\) ind : year \(=y r ; \quad \cos t=c: 1\)} Define an array named for Sale that holds 35 Car structures. Initialize the first three elements with the following data: $$\begin{array}{llll} \text { Make } & \text { Model } & \text { Year } & \text { cost } \\ \text { Ford } & \text { Taurus } & 2002 & \$ 21,000 \\ \text { Honda } & \text { Accord } & 2001 & \$ 11,000 \\ \text { Jeep } & \text { Wrangler } & 2004 & \$ 24,00000 \end{array}$$

Starting values for the elements of an array may be specified with a(n) ____ list.

Look at the following array definition. Int values [10]: A) How many elements does the array have? B) What is the subscript of the first element in the array? C) What is the subscript of the last element in the array? D) If an int uses four bytes of memory, how much memory does the array use?

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free