3 using namespace std; 4 Program 6-22 tion arguments. It has a function that displays aster- isks on the screen. This function receives arguments illustrates the use of default func- 5 // Function prototype with default argu- ments 6 void displayStars(int starsPerRow = 10, specifying how many rows of asterisks to display int numRows = 1); and how many asterisks to print on each row. Default arguments are provided to display one row 7 8 int main ( ) of 10 asterisks. 9 { 10 displayStars ( ) ; // starsPerRow & Program 6-22 numRows use defaults (10 & 1) 11 cout <« endl; 12 displayStars(5 ) ; // starsPerRow 5. numRows uses default value 1 1 // This program demonstrates the use of 13 cout <« endl; default function arguments. 14 displayStars(7, 3); // starsPerRow 7. 2 #include

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please help me explain this program, I did not understand. 

 

The output is:

Program Output

**********

*****

*******
*******
*******

numRows 3. No defaults used.
s**
15
return 0;
16 }
24 void displayStars(int starsPerRow, int
17
numRows )
18
25 {
/ *:
26
// Nested loop. The outer loop con-
trols the rows and
19
displayStars
27
// the inner loop controls the number
of stars per roW.
20
This function displays a rectangle
28
for (int row
1; row <= numRows;
made of asterisks.
row++)
*
21
If arguments are not passed to it, it
29
{
*
uses the default *
30
for (int star
1; star <= stars-
%3D
22
arguments 10 for starsPerRow and 1
PerRow; star++)
for numRows.
31
cout <<
23
32
cout <« endl;
Transcribed Image Text:numRows 3. No defaults used. s** 15 return 0; 16 } 24 void displayStars(int starsPerRow, int 17 numRows ) 18 25 { / *: 26 // Nested loop. The outer loop con- trols the rows and 19 displayStars 27 // the inner loop controls the number of stars per roW. 20 This function displays a rectangle 28 for (int row 1; row <= numRows; made of asterisks. row++) * 21 If arguments are not passed to it, it 29 { * uses the default * 30 for (int star 1; star <= stars- %3D 22 arguments 10 for starsPerRow and 1 PerRow; star++) for numRows. 31 cout << 23 32 cout <« endl;
3 using namespace std;
4
Program 6-22 illustrates the use of default func-
tion arguments. It has a function that displays aster-
isks on the screen. This function receives arguments
5 // Function prototype with default argu-
ments
6 void displayStars(int starsPerRow =
10,
specifying how many rows of asterisks to display
and how many asterisks to print on each row.
int numRows
1);
7
Default arguments are provided to display one row
of 10 asterisks.
8 int main( )
9 {
10
displayStars();
// starsPerRow &
numRows use defaults (10 & 1)
Program 6-22
11
cout << endl;
12
displayStars(5);
// starsPerRow 5.
numRows uses default value 1
1 // This program demonstrates the use of
13
cout << endl;
default function arguments.
14
displayStars(7, 3); // starsPerRow 7.
2 #include <iostream>
Transcribed Image Text:3 using namespace std; 4 Program 6-22 illustrates the use of default func- tion arguments. It has a function that displays aster- isks on the screen. This function receives arguments 5 // Function prototype with default argu- ments 6 void displayStars(int starsPerRow = 10, specifying how many rows of asterisks to display and how many asterisks to print on each row. int numRows 1); 7 Default arguments are provided to display one row of 10 asterisks. 8 int main( ) 9 { 10 displayStars(); // starsPerRow & numRows use defaults (10 & 1) Program 6-22 11 cout << endl; 12 displayStars(5); // starsPerRow 5. numRows uses default value 1 1 // This program demonstrates the use of 13 cout << endl; default function arguments. 14 displayStars(7, 3); // starsPerRow 7. 2 #include <iostream>
Expert Solution
Step 1

While creating the function we can set the arguments of the function with some default value so that if the user forgets to pass the parameter while calling the function then the function is executed using the default values and no error has occurred.

Here also we have declared the function with default values.

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY