Exam2 Questions
.pdf
keyboard_arrow_up
School
Arizona State University *
*We aren’t endorsed by this school
Course
100
Subject
Computer Science
Date
Dec 6, 2023
Type
Pages
5
Uploaded by ChefClover20268
Exam 2 Review Questions CSE100 1. Which of the following is/are true about the use of switch/case statements? A. allows you to execute a block of code over and over B. allow the reuse of existing code C. allow the value of a variable or expression to control the flow of program execution 2. Given the following function call, which of the following is/are appropriate prototypes? double average = calcAverage(total, no_of_subjects); A. void calcAverage (char, double); B. double calcAverage (double,int); C. int calcAverage (char, int); 3. Given the following function, and A equals "Jr Jr", what is the output of: cout << look(A, ‘A');
string look(string student, char grade) { string phrase; phrase = student + " your grade is " + grade; return phrase; } 4. A double returning function named time has two parameters: x and z. The parameter x needs to be used in the function, then altered and passed out. The parameter z needs to be passed in to alter x. Write a header line for this function. 5. If a variable, int b, is declared locally in function wow(), how can int a in main() receive the value of b? A. use a return B. pass by value C. A and B 6. How many values can be returned by one function without using passing by reference? 7. What will be the output of: for (int j = 0; j < 5; j++) { for (int k = 0; k < 5; k++) cout << k << “
\
t”;
cout<<endl; } 8. What is the output of the following program: for(int x=10;x<13;x++); { cout << “I am happy” <<en
dl; }
9. What will be the output of the following program? for(int i=0 ;;i++) { cout << i<< endl; } 10. It is necessary to have break statements in switch/case, else the program will result in errors (T/F) 11. What will be the output of the following program?
int i = 2; do { cout << i*2 << endl; } while(i>5); 12. If x = 5, what is the value of x after the execution of the switch statement? switch(x) { case 1: case 2: x += 10; case 4: x +=10; case 5: x -= 10; case 6: x -= 10; default: x --; } 13. Given: void attempt(int);
What is wrong with the following segment of code? int num; attempt(num); 14. Write a prototype for a function called square that returns a double value and passes in an integer. 15. What is the output of the following code? void main(void) { int num = 1, num2 =2; int total; total = num; { int num = 2; total += num; } total += num + num2; cout << total; } 16. Given the following segments of code, fill in the rest and write the 4 function definitions
. SAMPLE RUN: Please Enter Destination: [Disney Land]
Please Enter Distance: [1000]
Your flight to Disney Land will cost $500.
#include <iostream> #include <string> using namespace std; // put prototypes here void calcCost(double&); void display(string, double); void main(void) { string location; double miles, cost; //put function call here location = getDistance(miles); //put function calls here } 17. What is wrong with the following code: int calcSquare(int); int main() { int num, sq; num = 2; sq = calcSquare(num); return 0; } int calcSquare(int num) { int square; square = num * num; } 18. Say whether the following are T/F a) There can be any number of functions defined in a function. b) There can be any number of functions called within a function. 19. Given the following function implementation write the function header line, prototype, and a sample call. { //calculate the total kilometers travelled double d_total = museum + bistro + gallery + bookshop + concert; return d_total; }
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
In addition to the instructions on the screenshot, please ensure that your program is made in C++ with comments. Please also ensure that screenshots are taken for the source code and the executed version, including all possible cases. Finally, add your code in a manner so I can just copy and paste it for review. Thanks.
arrow_forward
What happens after a function has been called and the code in the function body has been executed?
A. The function is defined.
B. Program execution jumps to the function definition and executes the code in the function body.
C. The function is destroyed.
D. Program execution returns to where the function was called.
What is the best way to reuse lines of code?
A. Copy and paste them wherever needed
B. Lines of code cannot be reused
C. Include them once at the top of the program
D. Define them once within a function and then call the function as needed
The int() function is an example of a
A. library function
B. built-in function
C. user defined function
D. alternate function
arrow_forward
0
arrow_forward
Make sure to include flow-charts that cover:
Overall program flow (use subprocess blocks to indicate where user-defined functions are called)
Function that randomly generates birthdays
-
- Function that finds birthday matches
arrow_forward
Use c++
arrow_forward
C++ programming. Pls solve. Provide image and code pls.
arrow_forward
USE C++programming language
arrow_forward
USE PYTHON
Source: en.wikipedia.org/wiki/Camel_case
In some languages, it’s common to use camel caseLinks to an external site. (otherwise known as “mixed case”) for variables’ names when those names comprise multiple words, whereby the first letter of the first word is lowercase but the first letter of each subsequent word is uppercase. For instance, whereas a variable for a user’s name might be called name, a variable for a user’s first name might be called firstName, and a variable for a user’s preferred first name (e.g., nickname) might be called preferredFirstName.
Python, by contrast, recommendsLinks to an external site. snake caseLinks to an external site., whereby words are instead separated by underscores (_), with all letters in lowercase. For instance, those same variables would be called name, first_name, and preferred_first_name, respectively, in Python.
In a file called camel.py, implement a program that prompts the user for the name of a variable in camel case and outputs…
arrow_forward
phython
arrow_forward
Reviewing this program address the following points:
Design/Implementation: Are there noticeable issues/flaws in the design and implementation of the code? How would you remedy such issues?
Readability: Is the code well organized and easy to follow? Can you understand what is going on, easily?
Documentation: Is the documentation well-written? does it explain what the code is accomplishing and how? Remember good documentation includes descriptive variable and function names in addition to clear/concise annotation.
Efficiency: Was the code efficient, without sacrificing readability and understanding?
#include <iostream>
using namespace std;
int main() { double meal, tax, tip, total; //create variables double taxPercentage = .0675, tipPercentage = .2; //initiate percentage values cout << "Enter a meal charge: \n"; cin >> meal; //enter meal tax = meal * taxPercentage; tip = (meal + tax) * tipPercentage; total = meal+tax+tip; cout…
arrow_forward
PHYTON
arrow_forward
use python
arrow_forward
It is required to implement a MATLAB program By using "user
define function" that used to:
• Read (100) diagnosis data shown in the table below from the key
board.
• Display all Patient's data who have a "High Risk "condition only
"High Risk" are patient who have an age greater than or equal to 75
If there are no high risk patients the program should terminated with
an appropriate message
Diagnosis Data Sample
No.
Patient ID
Name
Ag Height (cm) Weight(kg)
e
1
905792
K.M. Liam
50
166
90
126987
A.H. Noah
60
170
105
100
913376
L.S.Benjami 80
160
85
arrow_forward
Code it fast
Screenshot attach for confirmation
arrow_forward
Which of the following statements about testing are always true.
A. If a test fails, there must necessarily be a defect in the executed code.
B. If a test passes, there cannot be a defect in any code executed by the test, but there could be a defect elsewhere in the function.
C. If a test is unsound, that test passing or failing doesn't tell us whether or not a defect exists.
D. All of the above are true
arrow_forward
A function with parameters cannot be decorated. State whether true or false.
a.
False
b.
True
arrow_forward
a c++ program for a (cafe system) that includes this
specifications:
-Functions (should include both: pass by value and pass
by reference variables, void function and
unction returning any value)
- Array of structs (at least one single array of struct)
- Selection and repetition structures as needed
- Add your team members names as a comment in the
first line of your program
- You should print a menu to the user and offer him/her
different services.
- Main Services:
1-adding new item.
2-search for specific item.
3-update existing record.
4-delete.
5-Sort.
6-Display.
7-At the start, your program should populate the array(s)
from a file and allow the user to edit it. At
the end overwrite the same file with the latest contents of
the array(s).
8-Provide another statistical report as separate text file
e.g. the number of records, with date, time of last update.
- The program should continue running until the user
chooses to exit it.
- Ensure to avoid any errors of any type (Run-time error,…
arrow_forward
Write C++ program to currency exchange, which is the process that allows customers to
exchange one currency for another. The program will include decision-making statements,
loops, arrays, file I/O, string, and functions.
You should be following below details:
•
As you might know, currency rates are influenced by several factors such a country's
economic performance. Thus, it is better to get the up to-date currency rates from an
external source as it is easier to update. You should read the data from the file
"ExchangeRate.txt".
• "ExchangeRate.txt" file contain:
1.00 SAR 0.08 KWD
1.00 SAR 0.97 QAR
1.00 SAR 0.98 AED
1.00 SAR 0.10 BHD
1.00 SAR 0.10 OMR
1.00 QAR 0.08 KWD
1.00 QAR 1.01 AED
1.00 QAR 0.10 BHD
1.00 QAR 0.11 OMR
1.00 KWD 12.00 AED
1.00 KWD 1.23 BHD
1.00 KWD 1.26 OMR
1.00 AED 0.10 BHD
1.00 AED 0.10 OMR
1.00 BHD 1.02 OMR
The program should print the available currencies for exchange which are:
o SAR --> Saudi Arabia Riyal
o KWD --> Kuwaiti Dinar
o QAR --> Qatar Riyal
o AED -->…
arrow_forward
Survey Data Analysis
Computers are commonly used to compile
and analyze the results of surveys and
opinion polls. For this problem, there is a
maximum of 30 responses for the survey.
Each response is a number from 1 to 9. The
program computes for the mean, median
and mode of the 30 values.
Mean - arithmetic average
Median - middle value
Mode - value that occurs most frequently
The following are some of the function
declarations that will be used by the
program. Implement them.
void initialize(int answer[], int size);
initializes the array by inputting values
float mean(int answer[],int size);
computes for the average
int max(int answer[],int size);
returns the highest value
int min(int answer[], int size);
- returns the smallest value
int range(int answer[],int size);
returns the range of the highest and
smallest values
Provide the main that includes the
creation of the array and tests of the
operations.
arrow_forward
Computer Science
arrow_forward
True/False 7. Python functions can never modify a parameter
arrow_forward
13.
What is the difference between a formal parameter and an argument?
Group of answer choices
A function’s argument is referred to as the formal argument to distinguish it from the value that is passed in during the function call.
The parameter is the passed value.
They are identical but using different terms.
A function’s parameter is used for passing by reference.
The argument is used for passing by value.
A function’s parameter is referred to as the formal parameter to distinguish it from the value that is passed in during the function call.
The argument is the passed value.
A function’s parameter is used for passing by value.
The argument is used for passing by reference.
arrow_forward
Scientific Computing (Matlab)
Q1: Write a script named "CheckNumber" that ask the user to enter a number and check if the number is positive or negative? Provide an example to explain the function.
arrow_forward
Q4/ Fill with the blank for any three of the following:
1: The function has
output(s), while the subroutine has
three.
one,
two,
many,
2: The Ode45 function has a
than Euler's method.
in between.
greater accuracy, less accuracy,
3: Given [T,Y] =(odefun, tspan, y0), Tis_____ and Y_
5
output, input, input or output initial boundary conditions
4: Getframe means
pictures.
temporary, captures the current axes, none of them.
output(s).
arrow_forward
Programming Language: C++
3. Which of the following are true for static variables but not for other variables?
Select one or more:
a. If they are defined and initialized on the same line, this line is guaranteed to only be executed once.
b. They can only be used in the scope where they are defined.
c. They can be used as arguments when calling a function
d. They retain the value stored in them even after the function where they are defined returns
e. They can be defined and initialized on the same line.
arrow_forward
Using pycharm/python
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Related Questions
- In addition to the instructions on the screenshot, please ensure that your program is made in C++ with comments. Please also ensure that screenshots are taken for the source code and the executed version, including all possible cases. Finally, add your code in a manner so I can just copy and paste it for review. Thanks.arrow_forwardWhat happens after a function has been called and the code in the function body has been executed? A. The function is defined. B. Program execution jumps to the function definition and executes the code in the function body. C. The function is destroyed. D. Program execution returns to where the function was called. What is the best way to reuse lines of code? A. Copy and paste them wherever needed B. Lines of code cannot be reused C. Include them once at the top of the program D. Define them once within a function and then call the function as needed The int() function is an example of a A. library function B. built-in function C. user defined function D. alternate functionarrow_forward0arrow_forward
- Make sure to include flow-charts that cover: Overall program flow (use subprocess blocks to indicate where user-defined functions are called) Function that randomly generates birthdays - - Function that finds birthday matchesarrow_forwardUse c++arrow_forwardC++ programming. Pls solve. Provide image and code pls.arrow_forward
- USE C++programming languagearrow_forwardUSE PYTHON Source: en.wikipedia.org/wiki/Camel_case In some languages, it’s common to use camel caseLinks to an external site. (otherwise known as “mixed case”) for variables’ names when those names comprise multiple words, whereby the first letter of the first word is lowercase but the first letter of each subsequent word is uppercase. For instance, whereas a variable for a user’s name might be called name, a variable for a user’s first name might be called firstName, and a variable for a user’s preferred first name (e.g., nickname) might be called preferredFirstName. Python, by contrast, recommendsLinks to an external site. snake caseLinks to an external site., whereby words are instead separated by underscores (_), with all letters in lowercase. For instance, those same variables would be called name, first_name, and preferred_first_name, respectively, in Python. In a file called camel.py, implement a program that prompts the user for the name of a variable in camel case and outputs…arrow_forwardphythonarrow_forward
- Reviewing this program address the following points: Design/Implementation: Are there noticeable issues/flaws in the design and implementation of the code? How would you remedy such issues? Readability: Is the code well organized and easy to follow? Can you understand what is going on, easily? Documentation: Is the documentation well-written? does it explain what the code is accomplishing and how? Remember good documentation includes descriptive variable and function names in addition to clear/concise annotation. Efficiency: Was the code efficient, without sacrificing readability and understanding? #include <iostream> using namespace std; int main() { double meal, tax, tip, total; //create variables double taxPercentage = .0675, tipPercentage = .2; //initiate percentage values cout << "Enter a meal charge: \n"; cin >> meal; //enter meal tax = meal * taxPercentage; tip = (meal + tax) * tipPercentage; total = meal+tax+tip; cout…arrow_forwardPHYTONarrow_forwarduse pythonarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,