week5 quiz solutions
.docx
keyboard_arrow_up
School
Arizona State University *
*We aren’t endorsed by this school
Course
100
Subject
Computer Science
Date
Apr 3, 2024
Type
docx
Pages
26
Uploaded by LieutenantHornetMaster829
QUIZ 6
Question 1
2
/ 2
pts
What is the value of x after the following statements execute?
int x = 5;
int y = 30;
do{
x = x * 2;
}while (x < y);
5
20
10
40
Question 2
2
/ 2
pts
Suppose that the input is 5 3 4 –6 8. What is the output of the following C++ code?
int sum = 0;
int num;
int j;
for (j = 1; j <= 5; j++)
{
cin >> num;
if (num < 0)
continue;
sum = sum + num;
}
cout << sum<<endl;
20
24
22
26
Question 3
2
/ 2
pts
Suppose sum, num, and j are int variables, and the inputs are 4 7 12 9 -1 respectively. What is the output of the following code?
cin >> sum;
cin >> num;
for (j = 1; j <= 3; j++)
{
cin >> num;
sum = sum + num;
}
cout << sum << endl;
24
41
25
42
Incorrect
Question 4
0
/ 2
pts
What is the index number of the last component in the array numList above?
int numList[50];
for (int i = 0; i < 50; i++)
numList[i] = 2 * i;
numList[10] = -20;
numList[30] = 8;
49
0
50
30
The array is size 50.
Index of the array starts from 0. So the last index is 49.
Question 5
2
/ 2
pts
What is the output of the following C++ code?
int x = 7;
bool found = false;
do
{
cout << x << " ";
if (x <= 2)
found = true;
else
x = x – 5;
}
while (x > 0 && !found);
cout << endl;
7
7 2
2 7
None of these
Question 2
2
/ 2
pts
Which of the following loops is guaranteed to execute at least once?
counter-controlled while loop
do...while loop
for loop
sentinel-controlled while loop
Question 4
2
/ 2
pts
Complete the following C++ program that prints the content of a string in the reverse order
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char str[] = “CSE 100 Fall 2014”;
/* To Do: Select a for loop that prints the content of the string in the reverse order
Hint: you can use strlen( const char* ) function to get the length of the string
Ex. char str[] = "Cat"; int length; length = strlen(str); length gets 3.
*/
return 0;
}
int i, length;
length =
strlen(str);
for(i=0;i<length;i++){
cout<<str[i];
}
cout<<endl;
int i, length;
length =
strlen(str);
for(i=length-1;i>=0;i--){
cout<<str[i];
}
cout<<endl;
int i, length;
length =
strlen(str);
for(i=length-1;i>=0;i++){
cout<<str[i];
}
cout<<endl;
int i, length;
length =
strlen(str);
for(i=length;i>0;i--){
cout<<str[i];
}
cout<<endl;
QUIZ 7
Incorrect
Question 2
0
/ 2
pts
What is the value of numList length (size)?
int numList[50];
for (int i = 0; i < 50; i++)
numList[i] = 2 * i;
numList[10] = -20;
numList[30] = 8;
0
30
49
50
The value of numList length (size) is 50 because the code define int numList[50]; 50 is the
size of this array.
Question 3
2
/ 2
pts
Consider the following statements:
int hits[] = {5, 7, 9, 11, 13, 15};
What is the number of elements in the array hits.
0
6
5
15
Question 4
2
/ 2
pts
The size declarator indicates the number of elements, or values, an array can hold.
True
False
Question 5
2
/ 2
pts
Each element of an array is accessed and indexed by a number known as an subscript.
True
False
Question 2
2
/ 2
pts
Consider the following statements:
int hits[] = {5, 7, 9, 11, 13, 15};
cout << hits[3];
What is the output?
5
9
11
13
Question 4
2
/ 2
pts
The size declarator must be an integer with a value grater than 1.
True
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
C++ code not Java
arrow_forward
Please solve it with easy code
Thank you
arrow_forward
Void Do1 (int: &, a. int &b)
{
a = 5;
a = a + b;
b = a + 2;
}
Int main()
{
Int x = 10;
Do1 (x,x);
Cout << x << endl;
}
The output of this program is
arrow_forward
def f(x: float) -> int:
return int(x)
def g(x: str) -> float:
return float(x)
y = f(g("3.14"))
Select all of the following statements that are true:
y's inferred data type is float
O y 's inferred data type is str
O y's inferred data type is int
There is a type error in this program
None of the above are true
arrow_forward
The correct statements are:
(ab)*a = a(ba)*
(a U b)* b (a U b)* = a*b (a U b)*
(a U b)* ba (a U b)* U a*b* = (a U b)*
□ (a U b)* b (a U b)* U (a U b)* a (a U b)* = (a U b)*
arrow_forward
Answer to each question should be a executable java code, tested and run
You implement each question in a separate .java file.
arrow_forward
need help in java.
(1) Prompt the user for a string that contains two strings separated by a comma. (1 pt)
Examples of strings that can be accepted:
Jill, Allen
Jill , Allen
Jill,Allen
Ex:
Enter input string: Jill, Allen
(2) Report an error if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two strings. (2 pts)Ex:
Enter input string: Jill Allen Error: No comma in string. Enter input string: Jill, Allen
(3) Extract the two words from the input string and remove any spaces. Store the strings in two separate variables and output the strings. (2 pts)Ex:
Enter input string: Jill, Allen First word: Jill Second word: Allen
provided code:
import java.util.Scanner;
public class ParseStrings { public static void main(String[] args) { Scanner scnr = new Scanner(System.in);
/* Type your code here. */ }}
(4) Using a loop, extend the program to handle…
arrow_forward
c. Suppose a, b, and sum are int variables and c is a float variable. What value is assigned
to each variable after each statement executes? Suppose a = 9, b = 4, and c = 3.8./
a
b
sum
sum = static cast (++a + b) + c;
9
4
3.8
17
b += c
a;
-= static cast (a-- + 1);
a /= b + c
5;
*= c;
sum
arrow_forward
Use C++ Programing language.
Write a program that computes and displays the charges for a patient’s hospital stay. First, the program should ask if the patient was admitted as an inpatient or an outpatient. If the patient was an inpatient, the following data should be entered:
The number of days spent in the hospital
The daily rate
Charges for hospital services (lab tests, etc.)
Hospital medication charges
If the patient was an outpatient, the following data should be entered:
Charges for hospital services (lab tests, etc.)
Hospital medication charges
Use a single, separate function to validate that no input is less than zero. If it is, it should be reentered before being returned. Once the required data has been input and validated, the program should use two overloaded functions to calculate the total charges. One of the functions should accept arguments for the inpatient data, while the other function accepts arguments for outpatient data. Both functions should return the…
arrow_forward
int y=0,i;
for (int i=0;i<10;++i)
y+=i;
O 36
66
45
55
arrow_forward
Please I want the answer
arrow_forward
Java program: Please help me with this, I want the code without the if statement, and the variables names should be a,b,x,y
thank you so much
arrow_forward
X ، معلومات الدخول الى د
Quiz: FinalExam
quizzes/4585/take/questions/74430
Question 9
2 pts
What is the output of the following code? (NOTE: There are no
spaces between the output)
void test ()
{
static int x = 0;
int y = 1;
X = X + 2;
y =y + 13;
cout<
arrow_forward
python programming.
arrow_forward
Filling the Pool (Deprecated)
Write a program that calculates the time neccessary to completely fill an empty pool with water. We will assume that the
pool is rectangular and the depth is uniform. All input values in this program will be integers.
Prompt the user to enter the pool dimensions - length, width, and depth (unit: feet) - as well as the rate at which water
can be put into the pool (unit: gallons per minute). Using these values, calculate and display the time (in minutes) needed
to fill the pool from completely empty to completely full.
Note: you should calculate the volume of the pool (as cubic feet) and then determine the rate (in cubic feet per minute)
that water can be put into the pool. Assume that there are 7.48 gallons in one cubic foot.
Your program should run like the examples shown below:
Enter pool dimensions
Length: 10
Width: 8
Depth: 7
Water entry rate: 14
The pool will fill completely in 299.2 minutes
arrow_forward
Question #3:
Write a C program that repeatedly asks the user to enter real numbers from the keyboard then it calculates
and prints the average of the entered numbers. The program continuously asks the user till the user responds
by 'N'.
#include
int main(void)
{
//Declare required variables
//code for reading real numbers continuously till the user responds by 'N'
//code for calculating the average of the entered numbers and printing it
printf("\n");
printf("\n");
return 0;
}
Question3.c
Output Screenshot
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Related Questions
- def f(x: float) -> int: return int(x) def g(x: str) -> float: return float(x) y = f(g("3.14")) Select all of the following statements that are true: y's inferred data type is float O y 's inferred data type is str O y's inferred data type is int There is a type error in this program None of the above are truearrow_forwardThe correct statements are: (ab)*a = a(ba)* (a U b)* b (a U b)* = a*b (a U b)* (a U b)* ba (a U b)* U a*b* = (a U b)* □ (a U b)* b (a U b)* U (a U b)* a (a U b)* = (a U b)*arrow_forwardAnswer to each question should be a executable java code, tested and run You implement each question in a separate .java file.arrow_forward
- need help in java. (1) Prompt the user for a string that contains two strings separated by a comma. (1 pt) Examples of strings that can be accepted: Jill, Allen Jill , Allen Jill,Allen Ex: Enter input string: Jill, Allen (2) Report an error if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two strings. (2 pts)Ex: Enter input string: Jill Allen Error: No comma in string. Enter input string: Jill, Allen (3) Extract the two words from the input string and remove any spaces. Store the strings in two separate variables and output the strings. (2 pts)Ex: Enter input string: Jill, Allen First word: Jill Second word: Allen provided code: import java.util.Scanner; public class ParseStrings { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); /* Type your code here. */ }} (4) Using a loop, extend the program to handle…arrow_forwardc. Suppose a, b, and sum are int variables and c is a float variable. What value is assigned to each variable after each statement executes? Suppose a = 9, b = 4, and c = 3.8./ a b sum sum = static cast (++a + b) + c; 9 4 3.8 17 b += c a; -= static cast (a-- + 1); a /= b + c 5; *= c; sumarrow_forwardUse C++ Programing language. Write a program that computes and displays the charges for a patient’s hospital stay. First, the program should ask if the patient was admitted as an inpatient or an outpatient. If the patient was an inpatient, the following data should be entered: The number of days spent in the hospital The daily rate Charges for hospital services (lab tests, etc.) Hospital medication charges If the patient was an outpatient, the following data should be entered: Charges for hospital services (lab tests, etc.) Hospital medication charges Use a single, separate function to validate that no input is less than zero. If it is, it should be reentered before being returned. Once the required data has been input and validated, the program should use two overloaded functions to calculate the total charges. One of the functions should accept arguments for the inpatient data, while the other function accepts arguments for outpatient data. Both functions should return the…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning