Exam2 Questions

.pdf

School

Arizona State University *

*We aren’t endorsed by this school

Course

100

Subject

Computer Science

Date

Dec 6, 2023

Type

pdf

Pages

5

Uploaded by ChefClover20268

Report
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