True or False (15 Points)

Similar documents
True or False (14 Points)

True or False (12 Points)

Name SECTION: 12:45 2:20. True or False (12 Points)

CPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points)

Name Section: M/W or T/TH. True or False (14 Points)

True or False (15 Points)

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each):

5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (!

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

FORM 2 (Please put your name and form # on the scantron!!!!)

Exam 3 Chapters 7 & 9

Lab 2: Pointers. //declare a pointer variable ptr1 pointing to x. //change the value of x to 10 through ptr1

Chapter 9: Pointers Co C pyr py igh i t gh Pear ea so s n n E ducat ca io i n, n Inc. n c.

1. In C++, reserved words are the same as predefined identifiers. a. True

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

Exam 2. CSI 201: Computer Science 1 Fall 2016 Professors: Shaun Ramsey and Kyle Wilson. Question Points Score Total: 80

9.2 Pointer Variables. Pointer Variables CS Pointer Variables. Pointer Variables. 9.1 Getting the Address of a. Variable

The University of Alabama in Huntsville Electrical and Computer Engineering CPE Example of Objective Test Questions for Test 4

CSCE Practice Midterm. Data Types

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

Sample Final Exam. 1) (24 points) Show what is printed by the following segments of code (assume all appropriate header files, etc.


Week 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7.

Functions, Arrays & Structs


Lecture 23: Pointer Arithmetic

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science. Instructor: Final Exam Fall 2011

Definition Matching (10 Points)

Homework #3 CS2255 Fall 2012

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II:

Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

! Pass by value: when an argument is passed to a. ! It is implemented using variable initialization. ! Changes to the parameter in the function body

CS2141 Software Development using C/C++ C++ Basics

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

C++ Final Exam 2017/2018

FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

TWO DIMENSIONAL ARRAY OR MATRIX common name scores Defined as scores[10][5] IE 10 rows x 5 columns showing name of each position; some values below

Week 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7. CS 5301 Spring 2018

a. a * c - 10 = b. a % b + (a * d) + 7 =

CSCE Practice Midterm. Data Types

CS Spring 05 - MidTerm

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Instructor: Final Exam Fall Section No.

The American University in Cairo Department of Computer Science & Engineeringt CSCI &09 Dr. KHALIL Exam-I Fall 2009

Review. Outline. Array Pointer Object-Oriented Programming. Fall 2013 CISC2200 Yanjun Li 1. Fall 2013 CISC2200 Yanjun Li 2

Review. Outline. Array Pointer Object-Oriented Programming. Fall 2017 CISC2200 Yanjun Li 1. Fall 2017 CISC2200 Yanjun Li 2

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

Chapter 9: Pointers. Copyright 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved.

Chapter 9: Getting the Address of a Variable. Something Like Pointers: Arrays. Pointer Variables 8/23/2014. Getting the Address of a Variable

1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A.

Here, type declares the base type of the array, which is the type of each element in the array size defines how many elements the array will hold

1) You want to determine whether time has run out. The following code correctly implements this:

Test 2: CPS Owen Astrachan. November 17, Name: Honor code acknowledgement (signature)

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

Name: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015

CS2255 HOMEWORK #1 Fall 2012

CS242 COMPUTER PROGRAMMING

Name. Classes and Objects 1. We re going to develop a class to help out Café Below is the definition for a class called

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Dr. Khalil Exam II Fall 2011

CPE Summer 2015 Exam I (150 pts) June 18, 2015

Physics 234: Computational Physics

CSE030 Fall 2012 Final Exam Friday, December 14, PM

Functions. CS111 Lab Queens College, CUNY Instructor: Kent Chin

CMPS 221 Sample Final

CSCE 110 PROGRAMMING FUNDAMENTALS

CS201- Introduction to Programming Current Quizzes

Multiple Choice Questions (20 questions * 5 points per question = 100 points)

Functions, Arrays & Structs

Non-numeric types, boolean types, arithmetic. operators. Comp Sci 1570 Introduction to C++ Non-numeric types. const. Reserved words.

What is an algorithm?

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE Instructor: Final Exam Fall 2014

Review. Modules. CS 151 Review #6. Sample Program 6.1a:

CS101 PLEDGED SPRING 2001

Note: The buy help from the TA for points will apply on this exam as well, so please read that carefully.

CS 117 Programming II, Spring 2018 Dr. Ghriga. Midterm Exam Estimated Time: 2 hours. March 21, DUE DATE: March 28, 2018 at 12:00 PM

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

Input And Output of C++

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

CHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING. Dr. Shady Yehia Elmashad

STRUCTURED DATA TYPE ARRAYS IN C++ ONE-DIMENSIONAL ARRAY TWO-DIMENSIONAL ARRAY

A First Program - Greeting.cpp

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays)

UEE1302 (1102) F10 Introduction to Computers and Programming (I)

Pointers, Dynamic Data, and Reference Types

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

CSCS 261 Programming Concepts Exam 2 Fall EXAM 2 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.

CSC 126 FINAL EXAMINATION FINAL Spring 2012 B. Name (last, First) Instructor. Total Possible. Received

Spring 2002 Page 1 of 8 READ THIS NOW!

9. Arrays. Compound Data Types: type name [elements]; int billy [5];

6. User Defined Functions I

CSCS 261 Programming Concepts Exam 2 Fall EXAM 2 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.

Introduction to Computer Science Midterm 3 Fall, Points

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

Transcription:

Name Number True or False (15 Points) 1. (15 pts) Circle T for true and F for false: T F a) Value Returning Functions cannot use reference parameters. T F b) Arguments corresponding to value parameters can be variables. T F c) ptrvar = *var; assigns the memory address of var to ptrvar T F d) The memory address of the first element of an array is called the Base Address. T F e) The elements of a C++ array must be homogeneous T F f) Given the declaration int beta[20]; the statement cout << beta; can be used to display all 20 elements of the array named beta on the standard output device. T F g) If a program has the declarations enum WeatherType SUNNY, CLOUDY, FOGGY, WINDY; int frequency[4]; then the statement cout << frequency[cloudy]; is syntactically valid. T F h) The C++ statement typedef int Boolean; creates a new name of Boolean for the existing DataType int. T F i) A hierarchical structure has at least one component that is itself a structure. T F j) The members of a C++ structure are always homogeneous. T F k) The names of members in a structure must be unique for that structure T F l) The expression name.first is used to access the first member of the structure variable name. T F m) C++ checks for out-of-bounds array indexes at compile time. T F n) Using an array index that is out of bounds results in a compile error. T F o) The reserved word const before an array parameter allows a function to change values of the array. Page 1 of 11

Extra Credit #1 (2 pts) The code from the day when exam2 was returned (10/27) is: (must have received your exam back in class that day) A) Classes B) I show up C)Missed Again D) Pointers Extra Credit #2 (2 pts) The code given out in class on 11/8 is (must have signed the sheet) A) Classes B) I show up C)Missed Again D) Pointers Multiple choice (17 points) Questions 2 18 For these problems circle all correct answers. For example if answers A, C and E are all valid then circle A, C and E. 2. How many function values does a value-returning function have? A) 4 B) 2 C) As many as necessary D) 1 E) 3 F) None of these 3. A function that does not return a function value is known as what kind of function? A) Value returning function B) Reference Parameter C) Empty D) Void function E) Expression less F) None of these 4. Circle all operations that ARE ALLOWABLE aggregate operations on structures. A) Input/Output (cin, cout statements) B) Assignment C) Arithmetic D) Return as a functions return value E) Comparison F) Argument pass by value to a function G) Argument pass by reference to a function 5. Circle all operations that ARE ALLOWABLE aggregate operations on arrays. A) Input/Output (cin, cout statements) B) Assignment C) Arithmetic D) Return as a functions return value E) Comparison F) Argument in a function call G) All of the above (a through f) Page 2 of 11

6. Value parameters (passing by value) are used if a parameters data flow is A) One-way, into the function B) One-way, out of the function C) Two-way, into and out of the function D) None of these 7. Reference parameters (passing by reference) are used if a parameters data flow is: A) two-way, into and out of the function B) one-way, into the function C) one-way, out of the function D) None of these 8. What are the reference parameters in the following function heading? void DoSomething(string& date, int num, float average, float& sum, string name) A) date B) num C) average D) sum E) name F) None of them 9. What are the value parameters in the following function heading? void DoSomething(string date, int num, float average, float sum, string& name) A) date B) num C) average D) sum E) name F) None of them 10. The following code fragment invokes (calls) a void function named InitToZero: int alpha[20]; InitToZero(alpha); // returns alpha with every element of the array set to 0 Which of the following is a valid function heading for InitToZero? A) void InitToZero( const int beta ) B) void InitToZero( int beta[20] ) C) void InitToZero( int [20] ) D) None of These 11. For the function InitToZero described above in Problem 10, which of the following would be an appropriate function prototype? A) void InitToZero( const int [20] ); B) void InitToZero( const int ); C) void InitToZero( int [ ] ); D) None of These Page 3 of 11

12. Which of the following correctly compares the memory addresses contained in the pointer variables intptr1 and intptr2 A) If(intPtr1 == *intptr2) B) if (intptr1 == intptr2) C) if (*intptr1 == *intptr2) 13. Suppose that typedef int MatrixType[MAXROWS][MAXCOLS]; has been used to create a two-dimensional array matrix data type called MatrixType. Which of the following statements correctly declares a variable named C of the data type MatrixType? A) MatrixType[MAXROWS][MAXCOLS] C; B) MatrixType C; C) int MatrixType; D) None of These 14. Given the global type declaration MatrixType as described in problem 13, which of the following would be a suitable function prototype for a function named PrintMatrix? A) void PrintMatrix( MatrixType[ ][ ] ); B) void PrintMatrix( MatrixType M ); C) void PrintMatrix( MatrixType M[MAXROWS][ ]); D) None of These 15. The void function named GetNums has two parameters A pass-by-value parameter named x of type float A pass-by-value parameter named num of type int. Which of the following choices are correct function prototypes for the description of the parameters for the function GetNums? A) void GetNums( float&, int& ); B) void GetNums( float& x, int& num ); C) void GetNums( float, int num ); D) void GetNums(float, int); E) none of the above 16. Which of the following statements correctly declares a one-dimensional array variable named somearray with exactly 9 elements of type int? A) int somearray[8]; B) int somearray[9]; C) int somearray[10]; D) typedef int somearray[9]; E) B and D F) None of these Page 4 of 11

17. The function PrintMatrix will work only for 2x2 matrices. Assuming that the matrix dimensions are represented by global integer constants MAXROWS and MAXCOLS which specify the maximum number of rows and columns, respectively, in the matrix M, which of the following code fragments would correctly print out the contents of the matrix M row-by-row? If matrix M were as follows: M 1 2 3 4 Sample output for matrix M: 1 2 3 4 A) int r,c; B) int r,c; for(c=0; c<maxcols; c++) for(r=0; r<=maxrows; r++) for(r=0; r<maxrows; r++) for(c=0; c<=maxcols; c++) cout << M[r][c] ; cout << M[r][c] ; cout << endl; cout << endl; C) int r,c; D) int r,c; for(c=1; c<maxcols; c++) for(r=0; r<maxrows; r++) for(r=1; r<maxrows; r++) for(c=0; c<maxcols; c++) cout << M[r][c] ; cout << M[r][c] ; cout << endl; cout << endl; E) None of the above produces the desired output 18. Assuming that the one-dimensional array variable somearray has already been declared correctly, suppose that one wishes to initialize each array element to its index value ( the array element holds the value of the index necessary to access that element ) Which of the following program fragments correctly initializes the array somearray? A) int k = 0; B) int k = 1; C) int k = 0; while (k <= 9) while (k <= 9) while (k <= 9) somearray[k]=k; somearray[k]=k; k=somearray[k]; k++; ++k; ++k; D) int k = 0; E) int k = 0; F) None of these while (k < 9) while (k < 9) k = somearray[k]; somearray[k] = k; k++; k++; Page 5 of 11

Short Answer (68 points) Questions 19 26 19. (4 pts) There are four functions shown in the code segment below. Assume all variables and function prototypes have been correctly declared before this segment of code and that the code compiles. Compute(inFile, MyCalc()); Average(SumUp(num), num); A) Which function(s) is(are) most likely value-returning function(s)? B) Which function(s) is(are) most likely void function(s)? 20. (9 pts) Consider the program below. What is the output written to the terminal when this code is executed? #include <iostream> using namespace std; int main() int x = 1; // Assume variable x is stored at memory address 1000 int y = 2; // Assume variable y is stored at memory address 2000 int *a = &x; // Assume variable a is stored at memory address 3000 int* b = &y; // Assume variable b is stored at memory address 4000 cout << a << endl; cout << &a << endl; cout << *a << endl; cout << b << endl; cout << &b << endl; cout << *b << endl; return 0; Page 6 of 11

21. (5 pts) Consider the following structure declarations when answering the questions below. struct Date int day; int month; int year; ; struct Purchase string name; Date buydate; ; a) Write a statement that declares the identifier payday as a variable of DataType Date. b) Write a output statement that will output the value of month of the variable payday. c) Write a statement that declares the identifier item as a variable of DataType Purchase. d) Write a statement that assigns a value of Car to the name member of item. e) Write an output statement that will output the value of year of the buydate member of item. 22. (6 pts) Write a structure declaration for a structure named Zoo with the following members: an integer variable representing the number of animals a string variable representing the name of the zoo a string variable representing the city where the zoo is located a floating-point variable indicating the cost of admission Page 7 of 11

23. (10 pts) For the questions A through G, consider the following program. Note just the lines of importance have been displayed here. There is at least one answer for each question, and some may have more than one answer. Provide ALL the answers to a question. As an example, if the question is what line contains a return statement? The answer is line 12, 14, 16 and line 18. #include <iostream> // Line 1 using namespace std; // Line 2 int function_1(int&, float, int); // Line 3 void function_2(float&, int, float&); // Line 4 void function_3(); // Line 5 int main() // Line 6 int sum1, num, enter; // Line 7 float temp, avg; // Line 8 function_3(); // Line 9 function_2(avg,num,temp); // Line 10 function_2(avg,function_1(sum1,avg,num),temp); // Line 11 return 0; // Line 12 int function_1(int& sum, float number, int enter) // Line 13 return enter; // Line 14 void function_2(float& average, int count, float& number) // Line 15 return; // Line 16 void function_3() // Line 17 return; // Line 18 A) Which of the lines indicated are function prototypes? B) Which of the lines indicated include function calls? C) Which lines are a function heading? D) What are the arguments used in the function call for function_1? E) Which parameter(s) of function_2 are value parameters? Page 8 of 11

24. (10 pts) What is the output for the following program? Pay attention to the index values used with the arrays. #include <iostream> using namespace std; void init_array (int[][3]); void print_array (int [][3]); int main() int my_array[4][3]; init_array(my_array); print_array(my_array); return 0; void init_array (int my_array[][3]) int row, col; for (row = 0; row < 4 ; row++) for (col = 0; col < 3; col++) my_array[row][2 - col] = row + col; void print_array (int my_array[][3]) int row, col; for (row = 3; row >= 0; row--) for (col = 2; col >= 0; col--) cout << my_array[row][col] << ; cout << endl; Page 9 of 11

25. (12 pts) Finish the program below by adding a void function as specified below. Add only a function prototype, function call statement and function definition to the following program. Do not add any variable declarations. The name of the void function is InitStruct. The function has one parameter of the struct DataType Time. The function is to initialize the structure parameter with a time of 12:00:00 AM.(form is HH:MM:SS) The information stored in the parameter must be available in main() after the function call. #include <iostream> using namespace std; struct Time // format of the time is HH:MM:SS designator // where HH is for hours, MM for minutes and SS for seconds int hour; int minute; int second; string designator; // for AM or PM ; // Place the function prototype below this line int main() Time appt; // appt is a structure variable of data type Time // Place the function call below this line return 0; // Place the function definition below this line Page 10 of 11

26. (12 pts) Add a function prototype, function call statement and function definition to the following program. The name of the void function that is to be added is FillArray. This function is to read in values from standard input (cin) to fill all of the array elements. The void function has the following two parameters: 1) a floating-point one-dimensional array, 2) an integer value representing the number of array elements to read in. In the function definition use a for loop to read in a value for each element/component of the array. Use cout to prompt for a value and cin for reading the value. Assume that all values are entered correctly. #include <iostream> using namespace std; const int NUM = 100; // dimension size: number of values to read // Place the function prototype below this line int main() float numbers[num]; // one-dim. Array for holding floats entered // Place the function call statement below this line return 0; // Place the function definition below this line Page 11 of 11