Deck 8: Advanced Modularization Techniques

Full screen (f)
exit full mode
Question
Passing Arrays to Functions
In this exercise, you use what you have learned about passing arrays and array elements to functions to answer Questions.
Given the following function header (in which sal is one element of an array of doubles), write a function call that passes the last value in the array named salaries:
a.
double salaries[] = {45000, 23000, 35000};
void bonus(double sal)
Use Space or
up arrow
down arrow
to flip the card.
Question
Pass by Reference and Pass by Address
In this exercise, you use what you have learned about passing arguments by reference and by address to functions to answer Questions.
Given the following variable and function declarations, write the function call and the function's header:
a.
double price = 22.95, increase =.10;void changePrice(double , double);
b.
double price = 22.95, increase =.10;void changePrice(double* , double);
c.
int age = 23;void changeAge(int );
d.
int age = 23;void changeAge(int*);
Question
Pass by Reference and Pass by Address
In this exercise, you use what you have learned about passing arguments by reference and by address to functions to answer Questions.
Given the following function headers and variable declarations, write a function call:
a.
Pass by Reference and Pass by Address In this exercise, you use what you have learned about passing arguments by reference and by address to functions to answer Questions. Given the following function headers and variable declarations, write a function call: a.   b.  <div style=padding-top: 35px>
b.
Pass by Reference and Pass by Address In this exercise, you use what you have learned about passing arguments by reference and by address to functions to answer Questions. Given the following function headers and variable declarations, write a function call: a.   b.  <div style=padding-top: 35px>
Question
Overloading Functions
In this exercise, you use what you have learned about overloading functions to answer Question 1.
In Figure 1, which function header would the following function calls match? Use a line number as your answer.
Figure 1 Function headers and variable declarations
Overloading Functions In this exercise, you use what you have learned about overloading functions to answer Question 1. In Figure 1, which function header would the following function calls match? Use a line number as your answer. Figure 1 Function headers and variable declarations   a. ans2 = sum(2, 7, 9); b. ans1 = sum(number2, number2); c. ans1 = sum(10.0, 7.0); d. ans2 = sum(2, 8, number2); e. ans2 = sum(3, 5);<div style=padding-top: 35px>
a. ans2 = sum(2, 7, 9);
b. ans1 = sum(number2, number2);
c. ans1 = sum(10.0, 7.0);
d. ans2 = sum(2, 8, number2);
e. ans2 = sum(3, 5);
Question
Using C++ Built-in Functions
In this exercise, you use a browser, such as Google, to find information about a built-in function that belongs to the C++ function library to answer Questions.
What does the pow() function do?
Question
Using C++ Built-in Functions
In this exercise, you use a browser, such as Google, to find information about a built-in function that belongs to the C++ function library to answer Questions.
What data type does the pow() function return?
Question
Writing Functions with No Parameters
In this exercise, you use what you have learned about writing functions with no parameters to answer Questions.
Given the following function calls, write the function's header and function declaration:
a.
printMailingLabel();
b.
displayOrderNumbers();
c.
displayTVListing();
Question
Using C++ Built-in Functions
In this exercise, you use a browser, such as Google, to find information about a built-in function that belongs to the C++ function library to answer Questions.
Is the pow() function overloaded? How do you know?
Question
Writing Functions with No Parameters
In this exercise, you use what you have learned about writing functions with no parameters to answer Questions.
Given the following function headers, write a function call:
a.
void printCellPhoneNumbers()
b.
void displayTeamMembers()
c.
void showOrderInfo()
Question
Using C++ Built-in Functions
In this exercise, you use a browser, such as Google, to find information about a built-in function that belongs to the C++ function library to answer Questions.
How many arguments does the pow() function require?
Question
Writing Functions that Require a Single Parameter
In this exercise, you use what you have learned about writing functions that require a single parameter to answer Questions.
Given the following variable declarations and function calls, write the function's header and function declaration:
a. string name; printNameBadge(name);
b. double side_length; calculateSquareArea(side_length);
c. int hours; displaySecondsInMinutes(minutes);
Question
Using C++ Built-in Functions
In this exercise, you use a browser, such as Google, to find information about a built-in function that belongs to the C++ function library to answer Questions.
What is the data type of the argument(s) that the pow() function requires?
Question
Writing Functions that Require a Single Parameter
In this exercise, you use what you have learned about writing functions that require a single parameter to answer Questions.
Given the following function headers and variable declarations, write a function call:
a. string petName = "Mindre"; void displayPetName(string petName)
b. int currentMonth; void printBirthdays(int month)
c. string password; void checkValidPassword(string id)
Question
Using C++ Built-in Functions
In this exercise, you use a browser, such as Google, to find information about a built-in function that belongs to the C++ function library to answer Questions.
What is the value of the variable named result?
result = pow(2,4);
Question
Writing Functions that Require Multiple Parameters
In this exercise, you use what you have learned about writing functions that require multiple parameters to answer Questions.
Given the following function calls and variable declarations, write the function's header and function declaration:
a.
string name, address;
printLabel(name, address);
b.
double side1, side2;
calculateRectangleArea(side1, side2);
c.
int day, month, year;
birthdayInvitation(day, month, year);
Question
Using C++ Built-in Functions
In this exercise, you use a browser, such as Google, to find information about a built-in function that belongs to the C++ function library to answer Questions.
What is the value of the variable named result?
result = pow(10, 2);
Question
Writing Functions that Require Multiple Parameters
In this exercise, you use what you have learned about writing functions that require multiple parameters to answer Questions.
Given the following function headers and variable declarations, write a function call:
a.
string customerName = "Smith"; double balance = 54000; void printBill(string name, double balance)
b.
int val1 = 10, val2 = 20; void findProduct(int num1, int num2)
c.
double balance = 37500, interest =.10; void newBalance(double bal, double pcnt)
Question
Writing Functions that Return a Value
In this exercise, you use what you have learned about writing functions that return a value to answer Questions.
Given the following variable declarations and function calls, write the function's header:
a.
double price, percent, newPrice; newPrice = calculateNewPrice(price, percent);
b.
double area, one_length, two_length; area = calcArea(one_length, two_length);
c.
string lowerCase, upperCase; upperCase = changeCase(lowerCase);
Question
Writing Functions that Return a Value
In this exercise, you use what you have learned about writing functions that return a value to answer Questions.
Given the following function headers and variable declarations, write a function call:
a.
int itemID = 1234;string itemName;string findItem(int itemNumber)
b.
int val, cube;int cubed(int num1)
c.
int number = 3, exponent = 4, result;int power(int num, int exp)
Question
Passing Arrays to Functions
In this exercise, you use what you have learned about passing arrays and array elements to functions to answer Questions.
Given the following function calls, write the function's header:
a.
int marchBirthdays [] = {17, 24, 21, 14, 28, 9}; printBirthdays(marchBirthdays);
b.
double octoberInvoices [] = {100.00, 200.00, 55.00, 230.00}; double total; total = monthlyIncome(octoberInvoices);
c.
double balance[] = {34.56, 33.22, 65.77, 89.99}; printBill(balance[1]);
Question
Passing Arrays to Functions
In this exercise, you use what you have learned about passing arrays and array elements to functions to answer Questions.
Given the following function headers and variable declarations, write a function call:
a.
string names[] = {"Jones", "Smith", "Brown", "Perez"};double grades[] = {95, 76, 88, 72};void midtermGrades(string names[], double grades[])
b.
int numbers[] = {1, 4, 6, 8, 3, 7};int result;int printAverage(int nums[])
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/21
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 8: Advanced Modularization Techniques
1
Passing Arrays to Functions
In this exercise, you use what you have learned about passing arrays and array elements to functions to answer Questions.
Given the following function header (in which sal is one element of an array of doubles), write a function call that passes the last value in the array named salaries:
a.
double salaries[] = {45000, 23000, 35000};
void bonus(double sal)
a. Function call for function header void bonus(double sal)
// Header section // Line 1
#include // Line 2
#include // Line 3
// Line 4
// Function declaration // Line 5
void bonus(double); // Line 6
// Line 7
using namespace std; // Line 8
// Line 9
// Definition of main function // Line 10
int main() // Line 11
{
// Array declaration // Line 12
double salaries [] = {45000, 23000,35000};//Line 13
// Body of main() function // Line 14
// Function call // Line 15
bonus(salaries[2]); // Line 16
} // Line 17
// Line 18
// Define function header // Line 19
void bonus(double sal) // Line 20
{ // Line 21
// Function body // Line 22
} // Line 23
Explanation:
Function call in the above code,
• In line 16, the function void bonus(double)is called with arguments bonus(salaries[2]);.
o The double variable sal is present inside the parentheses.
o The value "35000" of array salaries[2] is passed to the function bonus() as actual parameter and it is stored in formal parameter sal present in bonus(double sal).
2
Pass by Reference and Pass by Address
In this exercise, you use what you have learned about passing arguments by reference and by address to functions to answer Questions.
Given the following variable and function declarations, write the function call and the function's header:
a.
double price = 22.95, increase =.10;void changePrice(double , double);
b.
double price = 22.95, increase =.10;void changePrice(double* , double);
c.
int age = 23;void changeAge(int );
d.
int age = 23;void changeAge(int*);
a. Function header and function call for function declaration " void changePrice(double , double); ":
// Header section //Line 1
#include //Line 2
#include //Line 3
//Line 4
// Function declaration //Line 5
void changePrice(double , double); //Line 6
//Line 7
using namespace std; //Line 8
//Line 9
// Definition of main function //Line 10
int main() //Line 11
{ //Line 12
//Line 13
// Variable declaration //Line 14
double price = 22.95, increase =.10; //Line 15
//Line 16
// Body of main() function //Line 17
//Line 18
// Function call //Line 19
changePrice (price, increase); //Line 20
} //Line 21
//Line 22
// Define function header //Line 23
void changePrice (double pri, double inc) //Line 24
{ //Line 25
// Function body //Line 26
//Line 27
} //Line 28
Explanation:
Function header in the above code,
In "line 24", function header is defined as "void changePrice (double pri, double inc)".
• In the function header, function name is preceded by keyword "void".
In "line 20", call the "changePrice" function is made, the variable "price" is passed by reference and variable "increase" is passed by value.
• Ampersand ( ) operator is used to specify that the variable is passed by reference.
b. Function header and function call for function declaration " void changePrice(double*, double); ":
// Header section //Line 1
#include //Line 2
#include //Line 3
//Line 4
// Function declaration //Line 5
void changePrice(double , double); //Line 6
//Line 7
using namespace std; //Line 8
//Line 9
// Definition of main function //Line 10
int main() //Line 11
{ //Line 12
//Line 13
// Variable declaration //Line 14
double price = 22.95, increase =.10; //Line 15
//Line 16
// Body of main() function //Line 17
//Line 18
// Function call //Line 19
changePrice ( price, increase); //Line 20
} //Line 21
//Line 22
// Define function header //Line 23
void changePrice (double* pri, double inc) //Line 24
{ //Line 25
// Function body //Line 26
//Line 27
} //Line 28
Explanation:
Function header in the above code,
In "line 24", function header is defined as "void changePrice (double* pri, double inc)". In the function header, function name is preceded by keyword void.
In "line 20", call the "changePrice" function is made, the variable "price" is passed by address and variable "increase" is passed by value.
• Asterisk (*) symbol is used to declare a pointer variable where the address of variable "price" is stored.
• Ampersand ( ) operator is used specify that the variable is passed by reference.
c. Function header and function call for function declaration " void changeAge(int ); ":
// Header section //Line 1
#include //Line 2
#include //Line 3
//Line 4
// Function declaration //Line 5
void changeAge(int ); //Line 6
//Line 7
using namespace std; //Line 8
//Line 9
// Definition of main function //Line 10
int main() //Line 11
{ //Line 12
//Line 13
// Variable declaration //Line 14
int age = 23; //Line 15
//Line 16
// Body of main() function //Line 17
//Line 18
// Function call //Line 19
changeAge (age); //Line 20
} //Line 21
//Line 22
// Define function header //Line 23
void changeAge(int newAge) //Line 24
{ //Line 25
// Function body //Line 26
//Line 27
} //Line 28
Explanation:
Function header in the above code,
In line 24, function header is defined as "void changeAge(int newAge)". In the function header, function name is preceded by keyword void.
In line 20, call the "changeAge" function is made, the variable age is passed by reference.
• Ampersand ( ) operator is used specify that the variable is passed by reference.
d. Function header and function call for function declaration " void changeAge(int*); ":
// Header section //Line 1
#include //Line 2
#include //Line 3
//Line 4
// Function declaration //Line 5
void changeAge(int*); //Line 6
//Line 7
using namespace std; //Line 8
//Line 9
// Definition of main function //Line 10
int main() //Line 11
{ //Line 12
//Line 13
// Variable declaration //Line 14
int age = 23; //Line 15
//Line 16
// Body of main() function //Line 17
//Line 18
// Function call //Line 19
changeAge ( age); //Line 20
} //Line 21
//Line 22
// Define function header //Line 23
void changeAge(int* newAge) //Line 24
{ //Line 25
// Function body //Line 26
//Line 27
} //Line 28
Explanation:
Function header in the above code,
In "line 24", function header is defined as "void changeAge(int newAge)". In the function header, function name is preceded by keyword "void".
In "line 20", call the "changeAge" function is made, the variable "age" is passed by value.
• Asterisk (*) symbol is used to declare a pointer variable where the address of variable "age" is stored.
3
Pass by Reference and Pass by Address
In this exercise, you use what you have learned about passing arguments by reference and by address to functions to answer Questions.
Given the following function headers and variable declarations, write a function call:
a.
Pass by Reference and Pass by Address In this exercise, you use what you have learned about passing arguments by reference and by address to functions to answer Questions. Given the following function headers and variable declarations, write a function call: a.   b.
b.
Pass by Reference and Pass by Address In this exercise, you use what you have learned about passing arguments by reference and by address to functions to answer Questions. Given the following function headers and variable declarations, write a function call: a.   b.
a. Function call for function header " void cust(string name[], double bal[]); ":
// Header section //Line 1
#include //Line 2
#include //Line 3
//Line 4
// Function declaration //Line 5
void cust(string[], double[]); //Line 6
//Line 7
using namespace std; //Line 8
//Line 9
// Definition of main function //Line 10
int main() //Line 11
{ //Line 12
//Line 13
// Variable declaration //Line 14
string custNames[]={"Perez", "Smith", "Patel", "Shaw" }; //Line 15
double balances[] = {34.00, 21.00, 41.50, 67.00}; //Line 16
// Body of main() function //Line 17
//Line 18
// Function call //Line 19
cust(custNames, balances); //Line 20
} //Line 21
//Line 22
// Define function header //Line 23
void cust (string name[], double bal[]) //Line 24
{ //Line 25
// Function body //Line 26
//Line 27
} //Line 28
Explanation:
Function call in the above code,
In "line 24", the function "void cust(string name[], double bal[])" is called with arguments "names", and "bal".
• The "string" array "name" and the "double" array "bal" are present inside parentheses.
• The string values "{"Perez", "Smith", "Patel", "Shaw"}" of array "custNames" is passed to function "cust()" as actual parameter and it is stored in formal parameter "name" present in "cust(string name[], double bal[])".
• The double values "{34.00, 21.00, 41.50, 67.00}" of array "balances" is passed to the function "cust()" as actual parameter and it is stored in the formal parameter "bal" present in "cust(string name[], double bal[])".
a. Function call for function header void printSum(int nums[]);
// Header section //Line 1
#include //Line 2
#include //Line 3
//Line 4
// Function declaration //Line 5
void printSum(int[]); //Line 6
//Line 7
using namespace std; //Line 8
//Line 9
// Definition of main function //Line 10
int main() //Line 11
{ //Line 12
//Line 13
// Variable declaration //Line 14
int values[]={1, 77, 89, 321, -2, 34}; //Line 15 //Line 16
// Body of main() function //Line 17
//Line 18
// Function call //Line 19
printSum (values); //Line 20
} //Line 21
//Line 22
// Define function header //Line 23
void printSum(int nums[]) //Line 24
{ //Line 25
// Function body //Line 26
//Line 27
} //Line 28
Explanation:
Function call in the above code,
In "line 24", the function "void printSum(int nums[])" is called with argument "nums".
• The "int" array "nums" is present inside parentheses.
• The integer values "{1, 77, 89, 321, -2, 34}" of array "values" is passed to the function "printSum()" as actual parameter and it is stored in the formal parameter "nums" present in "printSum(int nums[])".
4
Overloading Functions
In this exercise, you use what you have learned about overloading functions to answer Question 1.
In Figure 1, which function header would the following function calls match? Use a line number as your answer.
Figure 1 Function headers and variable declarations
Overloading Functions In this exercise, you use what you have learned about overloading functions to answer Question 1. In Figure 1, which function header would the following function calls match? Use a line number as your answer. Figure 1 Function headers and variable declarations   a. ans2 = sum(2, 7, 9); b. ans1 = sum(number2, number2); c. ans1 = sum(10.0, 7.0); d. ans2 = sum(2, 8, number2); e. ans2 = sum(3, 5);
a. ans2 = sum(2, 7, 9);
b. ans1 = sum(number2, number2);
c. ans1 = sum(10.0, 7.0);
d. ans2 = sum(2, 8, number2);
e. ans2 = sum(3, 5);
Unlock Deck
Unlock for access to all 21 flashcards in this deck.
Unlock Deck
k this deck
5
Using C++ Built-in Functions
In this exercise, you use a browser, such as Google, to find information about a built-in function that belongs to the C++ function library to answer Questions.
What does the pow() function do?
Unlock Deck
Unlock for access to all 21 flashcards in this deck.
Unlock Deck
k this deck
6
Using C++ Built-in Functions
In this exercise, you use a browser, such as Google, to find information about a built-in function that belongs to the C++ function library to answer Questions.
What data type does the pow() function return?
Unlock Deck
Unlock for access to all 21 flashcards in this deck.
Unlock Deck
k this deck
7
Writing Functions with No Parameters
In this exercise, you use what you have learned about writing functions with no parameters to answer Questions.
Given the following function calls, write the function's header and function declaration:
a.
printMailingLabel();
b.
displayOrderNumbers();
c.
displayTVListing();
Unlock Deck
Unlock for access to all 21 flashcards in this deck.
Unlock Deck
k this deck
8
Using C++ Built-in Functions
In this exercise, you use a browser, such as Google, to find information about a built-in function that belongs to the C++ function library to answer Questions.
Is the pow() function overloaded? How do you know?
Unlock Deck
Unlock for access to all 21 flashcards in this deck.
Unlock Deck
k this deck
9
Writing Functions with No Parameters
In this exercise, you use what you have learned about writing functions with no parameters to answer Questions.
Given the following function headers, write a function call:
a.
void printCellPhoneNumbers()
b.
void displayTeamMembers()
c.
void showOrderInfo()
Unlock Deck
Unlock for access to all 21 flashcards in this deck.
Unlock Deck
k this deck
10
Using C++ Built-in Functions
In this exercise, you use a browser, such as Google, to find information about a built-in function that belongs to the C++ function library to answer Questions.
How many arguments does the pow() function require?
Unlock Deck
Unlock for access to all 21 flashcards in this deck.
Unlock Deck
k this deck
11
Writing Functions that Require a Single Parameter
In this exercise, you use what you have learned about writing functions that require a single parameter to answer Questions.
Given the following variable declarations and function calls, write the function's header and function declaration:
a. string name; printNameBadge(name);
b. double side_length; calculateSquareArea(side_length);
c. int hours; displaySecondsInMinutes(minutes);
Unlock Deck
Unlock for access to all 21 flashcards in this deck.
Unlock Deck
k this deck
12
Using C++ Built-in Functions
In this exercise, you use a browser, such as Google, to find information about a built-in function that belongs to the C++ function library to answer Questions.
What is the data type of the argument(s) that the pow() function requires?
Unlock Deck
Unlock for access to all 21 flashcards in this deck.
Unlock Deck
k this deck
13
Writing Functions that Require a Single Parameter
In this exercise, you use what you have learned about writing functions that require a single parameter to answer Questions.
Given the following function headers and variable declarations, write a function call:
a. string petName = "Mindre"; void displayPetName(string petName)
b. int currentMonth; void printBirthdays(int month)
c. string password; void checkValidPassword(string id)
Unlock Deck
Unlock for access to all 21 flashcards in this deck.
Unlock Deck
k this deck
14
Using C++ Built-in Functions
In this exercise, you use a browser, such as Google, to find information about a built-in function that belongs to the C++ function library to answer Questions.
What is the value of the variable named result?
result = pow(2,4);
Unlock Deck
Unlock for access to all 21 flashcards in this deck.
Unlock Deck
k this deck
15
Writing Functions that Require Multiple Parameters
In this exercise, you use what you have learned about writing functions that require multiple parameters to answer Questions.
Given the following function calls and variable declarations, write the function's header and function declaration:
a.
string name, address;
printLabel(name, address);
b.
double side1, side2;
calculateRectangleArea(side1, side2);
c.
int day, month, year;
birthdayInvitation(day, month, year);
Unlock Deck
Unlock for access to all 21 flashcards in this deck.
Unlock Deck
k this deck
16
Using C++ Built-in Functions
In this exercise, you use a browser, such as Google, to find information about a built-in function that belongs to the C++ function library to answer Questions.
What is the value of the variable named result?
result = pow(10, 2);
Unlock Deck
Unlock for access to all 21 flashcards in this deck.
Unlock Deck
k this deck
17
Writing Functions that Require Multiple Parameters
In this exercise, you use what you have learned about writing functions that require multiple parameters to answer Questions.
Given the following function headers and variable declarations, write a function call:
a.
string customerName = "Smith"; double balance = 54000; void printBill(string name, double balance)
b.
int val1 = 10, val2 = 20; void findProduct(int num1, int num2)
c.
double balance = 37500, interest =.10; void newBalance(double bal, double pcnt)
Unlock Deck
Unlock for access to all 21 flashcards in this deck.
Unlock Deck
k this deck
18
Writing Functions that Return a Value
In this exercise, you use what you have learned about writing functions that return a value to answer Questions.
Given the following variable declarations and function calls, write the function's header:
a.
double price, percent, newPrice; newPrice = calculateNewPrice(price, percent);
b.
double area, one_length, two_length; area = calcArea(one_length, two_length);
c.
string lowerCase, upperCase; upperCase = changeCase(lowerCase);
Unlock Deck
Unlock for access to all 21 flashcards in this deck.
Unlock Deck
k this deck
19
Writing Functions that Return a Value
In this exercise, you use what you have learned about writing functions that return a value to answer Questions.
Given the following function headers and variable declarations, write a function call:
a.
int itemID = 1234;string itemName;string findItem(int itemNumber)
b.
int val, cube;int cubed(int num1)
c.
int number = 3, exponent = 4, result;int power(int num, int exp)
Unlock Deck
Unlock for access to all 21 flashcards in this deck.
Unlock Deck
k this deck
20
Passing Arrays to Functions
In this exercise, you use what you have learned about passing arrays and array elements to functions to answer Questions.
Given the following function calls, write the function's header:
a.
int marchBirthdays [] = {17, 24, 21, 14, 28, 9}; printBirthdays(marchBirthdays);
b.
double octoberInvoices [] = {100.00, 200.00, 55.00, 230.00}; double total; total = monthlyIncome(octoberInvoices);
c.
double balance[] = {34.56, 33.22, 65.77, 89.99}; printBill(balance[1]);
Unlock Deck
Unlock for access to all 21 flashcards in this deck.
Unlock Deck
k this deck
21
Passing Arrays to Functions
In this exercise, you use what you have learned about passing arrays and array elements to functions to answer Questions.
Given the following function headers and variable declarations, write a function call:
a.
string names[] = {"Jones", "Smith", "Brown", "Perez"};double grades[] = {95, 76, 88, 72};void midtermGrades(string names[], double grades[])
b.
int numbers[] = {1, 4, 6, 8, 3, 7};int result;int printAverage(int nums[])
Unlock Deck
Unlock for access to all 21 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 21 flashcards in this deck.