Question
(15 Pts) Select the function below which displays three lines of asterisks. Each line should randomly contain between 1 and 80 asterisks. void asterLine() {
(15 Pts) Select the function below which displays three lines of asterisks. Each line should randomly contain between 1 and 80 asterisks.
void asterLine() { int r; for (int i = 0; i < 3; i++) { r = rand() % 80 + 1; for (int i = 1; i <= r; i++) cout << '*'; cout << endl; } } |
void asterLine() { int r; r = rand() % 80 + 1; for (int i = 0; i < r; i++) { for (int i = 1; i <=3; i++) cout << '*'; cout << endl; } } |
void asterLine() { int r; for (int i = 0; i < 3; i++) { r = rand() % 80 ; for (int i = 1; i <= 80; i++) cout << '*'; cout << endl; } } |
int r; for (int i = 0; i < 3; i++) { r = rand() % 80 + 1; for (int i = 1; i <= r; i++) cout << '*'; cout << endl; }
|
Flag this Question
Question 210 pts
(10 Pts) Given the function definition below, what will the following code display? int num1 = 24167, num2=0; cout << num1 << << num2 << endl; num2 = getLast(num1); cout << num1 << << num2 << endl; // program continues int getLast(int num1) { num1%=10; return num1; }
24167 0 7 7 |
24167 0 24167 7 |
24167 0 24167 241670 |
24167 0 24167 24167 |
Flag this Question
Question 315 pts
(15 Pts) Choose the function below which accepts two int values and uses a for loop to display every number from the first one to the second one. You may assume the the second one will be greater than the first one. So if it were called with 6 8, it would display: 6 7 8
void display (int , int) { for(int i=n1;i<=n2;i++) { cout << setw(5) << i << endl; } } |
for(int i=n1;i<=n2;i++) { cout << setw(5) << i << endl; } |
void display (int n1, int n2) { for(int i=n1;i<=n2;i++) { cout << setw(5) << i << endl; } } |
void display () { //n1, n2 declared in main, no need to declare them here n1 =6; n2 = 8; for(int i=n1;i<=n2;i++) { cout << setw(5) << i << endl; } } |
Flag this Question
Question 415 pts
(15 Pts) Write a function that will accept a number in the range 1 through 5, and then use a switch statement to display the name of that number. The function should return the name eg. Five for 5 or Invalid Input if the number passed to the function is out of range.
HTML EditorKeyboard Shortcuts
12pt
Paragraph
p
Flag this Question
Question 520 pts
(20 Pts) Choose the function below which accepts an int value, adds 9 to it and multiplies it by a random number between 1 and 10. If the result is even, the function should return false, if odd, return true.
bool odd (int n) { int n; cout << "Enter an integer" << endl; cin >> n; bool oddNo = true; n+=9; n *= rand()%10 + 1; if(n%2==0) oddNo = false; return oddNo; } |
bool odd (int n) { bool oddNo = true; n+=9; n *= rand()%10 + 1; if(n%2==0) oddNo = false; return oddNo; } |
bool odd (int n) { bool oddNo = true; n+=9; n *= rand()%10 + 1; if(n%2==0) oddNo = true; return oddNo; } |
bool odd (int n) { bool oddNo = true; n+=9; n *= rand()%10 + 1; if(n/2=0) oddNo = false; return oddNo; } |
Flag this Question
Question 615 pts
(15 Pts) Choose the function below that best performs the following task: ask a user to enter a series of integers. The user should enter -99 to signal the end of the series. After exiting the loop, the function should return the highest of the numbers entered.
int findHighest () { int high =-99, num; cout << Enter a series of integers -99 to stop << endl; do { do { cin >> num; } while(num != -99 && num < 0); if(num > high) high = num; } while(num = -99); return high; } |
void findHighest () { int high =-99, num; cout << Enter a series of integers -99 to stop << endl; do { do { cin >> num; } while(num != -99 && num < 0); if(num > high) high = num; } while(num != -99); return high; } |
int findHighest () { int high =-99, num; cout << Enter a series of integers -99 to stop << endl; do { do { cin >> num; } while(num != -99 && num < 0); if(num > high) num =high; } while(num != -99); return high; } |
int findHighest () { int high =-99, num; cout << Enter a series of integers -99 to stop << endl; do { do { cin >> num; } while(num != -99 && num < 0); if(num > high) high = num; } while(num != -99); return high; } |
Flag this Question
Question 715 pts
Which function below best performs the following task: Write a function which accepts two int values. The function should return 0 if they are the same, 1 if the first is larger and 2 if the second is larger.
int compare(int one, int two) { int status = 2; if(one == two) status = 0; else if (one > two) status = 1; return status; }
|
int status = 2; if(one == two) status = 0; else if (one > two) status = 1; return status;
|
int compare(int one, int two) { status = 2; if(one == two) status = 0; else if (one > two) status = 1; return status; } |
int compare(int one, int two) { int status = 2; if(one = two) status = 0; else if (one > two) status = 1; return status; }
|
Flag this Question
Question 815 pts
(15 Pts) Choose the best answer below for a function which accepts any character and two integers, row and column then displays the indicated number of rows of that character, each row containing the indicated number of columns of that character. For example, the call: printChar(#, 5, 12); // 5 rows, 12 columns would display: ############ ############ ############ ############ ############
void printChar(char ch, int rows, int columns) { for(int row=0;row { for (int column=0;column { cout << ch << endl; } } } |
void printChar(char ch, int rows, int columns) { for(int row=0;row<5;row++) { for (int column=0;column<5;column++) { cout << #; } cout << endl; } } |
void printChar(char ch, int rows, int columns) { for(int row=0;row { for (int column=0;column { cout << ch; } cout << endl; } } |
char printChar(char ch, int rows, int columns) { for(int row=0;row { for (int column=0;column { return ch; } } } |
Flag this Question
Question 910 pts
(10 Pts) Which of the following is the best answer to: Write a function which accepts an int, and displays the result of rolling a pair of dice that many times.
void rollEm(int n) { for(int i=1;i<= n;i++) cout << rand()%6+1 + rand()%6+1; } |
void rollEm(int n) { for(int i=1;i<= n;i++) cout << rand()%11+2; } |
void rollEm(int n) { for(int i=1;i<= n;i++) cout << rand()%12+1; } |
for(int i=1;i<= n;i++) cout << rand()%6+1 + rand()%6+1; |
Flag this Question
Question 1020 pts
What will the following code display if the user enters 3?
int n; cout << "Enter an integer" << endl; cin >> n; if (n = 9) { cout << "Fire torpedo!" << endl; } else {
cout << "Belay fire order!" << endl; }
Fire torpedo!
|
Nothing. It's a .syntax error
|
Belay fire order!
|
Fire torpedo! Belay Fire order!
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started