CSCE 2004 Final Exam Spring Version A

Similar documents
CSCE 2004 Midterm Exam Spring 2017

CSCE 2014 Final Exam Spring Version A

CSCE 206: Structured Programming in C++

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

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

CS 115 Exam 3, Spring 2010

2013 Academic Challenge

CSCE Practice Midterm. Data Types

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

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

Computer Department. Question (1): State whether each of the following is true or false. Question (2): Select the correct answer from the following:

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. Looping. ++ is the increment operator.

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

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

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

while for do while ! set a counter variable to 0 ! increment it inside the loop (each iteration)

*Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* COMPUTER PROGRAMMING LECTURE 05 LOOPS IMRAN IHSAN

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

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.

Reviewing all Topics this term

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. The Increment and Decrement Operators

Topics. Constructor. Constructors

The American University in Cairo Computer Science & Engineering Department CSCE Dr. KHALIL Exam II Spring 2010

Midterm Examination. Instructor: Gary Chan Date: Saturday, 23 October 2010 Time: 2:30pm 4:00pm Venue: LTC

CSCE Practice Midterm. Data Types

CS201- Introduction to Programming Current Quizzes


Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5-1

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

CS 115 Exam 3, Spring 2011

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

Ch 6. Functions. Example: function calls function

READ THIS NOW! Failure to read and follow the instructions below may result in severe penalties. Do not start the test until instructed to do so!

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

Functions, Arrays & Structs

Programming. C++ Basics

Chapter 5: Prefix vs. Postfix 8/19/2018. The Increment and Decrement Operators. Increment and Decrement Operators in Program 5-1

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)

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

Question 2. [5 points] Given the following symbolic constant definition

CS 376b Computer Vision

CMSC 202 Midterm Exam 1 Fall 2015

University of Maryland Baltimore County. CMSC 202 Computer Science II. Fall Mid-Term Exam. Sections

CS 216 Exam 1 Fall SOLUTION

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 1 Fall EXAM 1 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.

CSE143 Exam with answers Problem numbering may differ from the test as given. Midterm #2 February 16, 2001

Multiple Choice Questions (20 questions * 6 points per question = 120 points)

Review: C++ Basic Concepts. Dr. Yingwu Zhu

Functions, Arrays & Structs

#include <iostream> #include <algorithm> #include <cmath> using namespace std; int f1(int x, int y) { return (double)(x/y); }

Name Section: M/W T/TH Number Definition Matching (8 Points)

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

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

Chapter 5: Loops and Files

C++ Final Exam 2017/2018

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

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

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

Exam 3 Chapters 7 & 9

Short Notes of CS201

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

Final Exam Solutions PIC 10B, Spring 2016

CS201 - Introduction to Programming Glossary By

Concepts Review. 2. A program is the implementation of an algorithm in a particular computer language, like C and C++.

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

Introduction to Programming I COS1511 School of Computing Revision Notes

Midterm Exam #2 Spring (1:00-3:00pm, Friday, March 15)

Name Section: M/W T/TH Number Definition Matching (6 Points)

Arrays. Arizona State University 1

1) What of the following sets of values for A, B, C, and D would cause the string "one" to be printed?

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

Week 2. Relational Operators. Block or compound statement. if/else. Branching & Looping. Gaddis: Chapters 4 & 5. CS 5301 Spring 2018.

CS2255 HOMEWORK #1 Fall 2012

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

Exam 1. CSI 201: Computer Science 1 Fall 2018 Professors: Shaun Ramsey

2 nd Week Lecture Notes

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

This test is OPEN Textbook and CLOSED notes. The use of computing and/or communicating devices is NOT permitted.

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

7.1. Chapter 7: Arrays Hold Multiple Values. Array - Memory Layout. A single variable can only hold one value. Declared using [] operator:

Variable Definitions and Scope

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING

Chapter 3 Problem Solving and the Computer

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

CS31 Discussion 1E Spring 17 : week 08

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

LAB 4.1 Relational Operators and the if Statement

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team

Abstract Data Types (ADT) and C++ Classes

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS242 ARRAYS

CSCI 101L - Data Structures. Practice problems for Final Exam. Instructor: Prof Tejada

CSCE 110 PROGRAMMING FUNDAMENTALS

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat

2. It is possible for a structure variable to be a member of another structure variable.

Review Problems for Final Exam. 1. What is the output of the following program? #include <iostream> #include <string> using namespace std;

REPETITION CONTROL STRUCTURE LOGO

Lecture-5. Miscellaneous topics Templates. W3101: Programming Languages C++ Ramana Isukapalli

Transcription:

CSCE 2004 Final Exam Spring 2017 Version A Student Name: Student UAID: Instructions: This is a two-hour closed book final exam. Students are allowed one 8.5 by 11 page of notes. No calculators or cell phones are allowed. Please raise your hand if you have questions. Reminder: This class is governed by the University of Arkansas code of ethics. Any instances of cheating will result in referral to the All University Academic Integrity Board. -1-

Conditionals - 15 points [5 points] Which statement below best matches there are fewer than 10 numbers and the total is more than 100? a) ((Num <= 10) && (Total >= 100)) b) ((Num < 10) (Total > 100)) c) ((Num < 10) && (Total > 100)) d) ((Num <= 10) (Total >= 100)) [5 points] What will the following code output when executed? int Age = 18; string Name = "David"; if (Age >= 18) if (Name[0] == 'D') cout << "Hello. "; else cout << "Goodbye. "; cout << "Congratulations!"; a) Hello. Congratulations! b) Goodbye. Congratulations! c) Congratulations! d) Hello. Goodbye. [5 points] Which statement below best matches the person is 18 years old or older and they are more than 70 inches tall? a) (!(Age <= 18) &&!(Height < 70) ) b) ( (Age >= 18) && (Height > 70) ) c) (!(Age <= 18) && (Height >= 70)) d) ( (Age >= 18) && (Height < 70)) -2-

Iteration - 20 points [5 points] What will the following code output when executed? int Num = 0; int Sum = 1; while (Sum < 10) Sum = Sum + Num; Num = Num + 1; cout << "Sum = " << Sum << ", Num = " << Num << endl; a) Sum = 11, Num = 5 b) Sum = 10, Num = 5 c) Sum = 14, Num = 5 d) Sum = 11, Num = 4 [5 points] How many times will "Hello" be printed by the following code? int num = 0; while (num < 4) for (int cnt = 0; cnt < 6; cnt = cnt + 3) cout << "Hello\n"; num = num + 1; a) 2 times. b) 4 times. c) 6 times. d) 8 times. -3-

[5 points] What will the following code output when executed? int Outer, Inner; for (Outer = 0; Outer < 4; Outer++) Inner = Outer + 1; while (Inner <= 5) cout << Outer; Inner++; cout << " "; cout << endl; a) 0000 111 22 3 b) 1234 234 34 4 c) 00000 1111 222 33 d) 12345 2345 345 45 [5 points] What will the following code output when executed? int n = 0; while ((n <= 5) (n > 0)) n++; cout << n << ' '; cout << endl; a) 0 1 2 3... and so on forever b) 1 2 3 4 and so on forever c) 0 1 2 3 4 d) 1 2 3 4 5 e) 2 3 4 5 6-4-

Arrays 10 points [5 points] Assume that the one-dimensional array data contains 10 integers with values between [-100..100]. Which of the following pieces of code will find and print the maximum value in this array? a) b) c) d) int val = data[0]; for (int i = 0; i < 10; i++) if (data[i] < val) val = data[i]; cout << val << endl; int val = -100; for (int i = 1; i <= 10; i++) if (data[i] < val) val = data[i]; cout << val << endl; int val = 100; for (int i = 0; i < 10; i++) if (val < data[i]) val = data[i]; cout << val << endl; int val = data[0]; for (int i = 1; i < 10; i++) if (val < data[i]) val = data[i]; cout << val << endl; [5 points] Which one of the following C++ declarations will create a twodimensional array of integers called number with 4 rows and 6 columns? a) int[4][6] number; b) int[6][4] number; c) int number[4][6]; d) int number[6][4]; e) None of the above -5-

Functions 20 points [10 points] Assume we are given the following variables and function prototypes. Which of the function calls below are syntactically correct and use the return values from functions properly? // Variable declarations int A, B; float X, Y, Z; char C, D; // Function prototypes float ReadNum(); int GetMax(int Value1, int Value2); void Difference(float Num1, float Num2, float &Diff); GetMax(A, B, C); A = GetMax(2+2, 4); cout << GetMax(5, 10); B = GetMax(GetMax(1,2), 3); Difference(X, Y, 6.0); Z = Difference(X, Y); Difference(X, Y, Z); Y = ReadNum(); cin >> ReadNum(); cout << ReadNum(); -6-

Consider the following C++ code: int work(int num) num = num * 2; return num; int play(int & val) val = val / 3; if (val > 10) return val; else return work(val); int main() int A, B; A = 12; B = work(a); cout << A << " " << B << endl; B = 21; A = play(b); cout << A << " " << B << endl; return 0; // ONE // TWO [5 points] What values will be printed at position ONE in the code? a) 21 42 b) 42 21 c) 12 24 d) 24 12 e) None of the above [5 points] What values will be printed at position TWO in the code? a) 4 8 b) 14 7 c) 8 4 d) 7 14 e) None of the above -7-

Files 10 points Assume that the following information is stored in a text file called "data.txt". 1 Jane 3.5 2 Joseph 0.6 3 Jennifer 4.0 4 John 2.2 5 Jessie 2.3 Consider the following C++ code: int main() int num; string name; float score; ifstream din; din.open( data.txt ); // CHECK OPEN // READ DATA din.close(); return 0; [5 points] What code should be used in place of CHECK OPEN above to check if the input file has been opened correctly, and end the program if an error is detected? a) if (din.fail() == false) return -1; b) if (!din.eof()) cout << Error detected end program\n ; c) if (din.fail()) return -1; d) if (din.open() == false) din.close(); e) None of the above -8-

[5 points] What code should be used in place of READ DATA above to read and print all of the information in the data file to the screen? a) b) c) d) din >> name >> num >> score; while (!din.eof()) cout << num << << name << << score << endl; din >> name >> num >> score; while (din >> num >> name >> score) cout << name << << num << << score << endl; while (!din.eof()) cout << din.getline(); while (din >> num, name, score) cout << num << << name << << score << endl; e) None of the above -9-

Classes 25 points [10 points] Circle true or false to answer the following questions. The constructor method in a class is automatically called when we declare an object. One advantage of private variables is that they take less memory space than public variables. The copy constructor is automatically called when we pass an object as a value parameter. It is possible to declare public variables in a class, but this violates the information hiding principle of classes. When we have a method in a class with more than three parameters, this is called parameter overloading. The destructor method is automatically called inside the constructor method. All methods in a class must have at least one parameter, or return a data value of some type. The private variables in a class can be accessed and modified by any method in the class. Private methods can be called in the main program just like public methods; there is no difference between them. Classes in C++ are intended to make it easier for groups of programmers to work together and call each others code. -10-

Consider the following C++ class definition: class Sphere public: Sphere(); Sphere(const float R); void SetRadius(const float R); float GetRadius(); float Modify(); void Change(float &S); void Print(); private: float radius; bool IsNotZero() const; ; [10 points] Assume the following C++ variables are declared in the main function and the method calls below are made after the declarations. Which method calls are syntactically correct and use the return values properly? Sphere UnitSphere(1); Sphere Ball; Sphere Several[5]; float Radius = 0; float Number = 0.5; if (Ball.IsNotZero()) Ball.Print(); Change(UnitSphere, 2.5); Ball.GetRadius(Radius); cout << Ball.Modify(); UnitSphere.Modify(Number); Radius = Several[3].GetRadius(); Several[2].SetRadius(3); UnitSphere.Change(Number); Ball = Several[2]; Ball.radius = UnitSphere.radius; -11-

[5 points] Consider the following C++ program with one class called Math. We have provided inline implementations of the class methods to reduce the size of the program. What will this program output when it is executed? class Math public: Math() num = 5; Math(int val) num = val; void Work() num = num * num; int Play(int val) num = num + val; return num; void Print(string name) cout << name << " = " << num << ", "; private: int num; ; int main() Math x; Math y(6); x. Work(); y. Work(); x.print("x"); y.print("y"); int a = x.play(2); int b = y.play(4); x.print("x"); y.print("y"); return 0; a) x = 5, y = 6, x = 4, y = 2, b) x = 25, y = 36, x = 21, y = 34, c) x = 5, y = 6, x = 25, y = 36, d) x = 25, y = 36, x = 27, y = 40, e) None of the above -12-