CS 115 Exam 3, Spring 2010

Similar documents
CS 115 Exam 3, Spring 2011

CS 115 Exam 3, Fall 2009

Introduction to Computer Science Midterm 3 Fall, Points

CS 115 Final Exam, Spring 2009

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

System Design and Programming II

Object Oriented Programming COP3330 / CGS5409

Fast Introduction to Object Oriented Programming and C++

Name. CPTR246 Spring '17 (100 total points) Exam 2

Starting Out with C++: Early Objects, 9 th ed. (Gaddis, Walters & Muganda) Chapter 2 Introduction to C++ Chapter 2 Test 1 Key

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

C-String Library Functions

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

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 (!

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

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 1/9/ Review. Here s a simple C++ program:

CMSC 202 Midterm Exam 1 Fall 2015

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program:

Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A

Note 11/13/2014. They are like those i s, j s, and temp s that appear and disappear when the function starts and finishes...

Pointers, Dynamic Data, and Reference Types

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

Engineering Problem Solving with C++, Etter

Assignment #1 (50 points; due 11:59 P.M.)

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

Arrays. Week 4. Assylbek Jumagaliyev

CS 31 Review Sheet. Tau Beta Pi - Boelter Basics 2. 2 Working with Decimals 2. 4 Operators 3. 6 Constants 3.

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

CS201- Introduction to Programming Current Quizzes

Higher Secondary Second Year COMPUTER SCIENCE Model question Paper - 3

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

Introduction to Algorithms and Data Structures. Lecture 6 - Stringing Along - Character and String Manipulation

String Class in C++ When the above code is compiled and executed, it produces result something as follows: cin and strings

CS 115 Final Review Quiz

CSCE 2004 Final Exam Spring Version A

Chapter 8 Arrays and Strings. Objectives. Objectives (cont d.) Introduction. Arrays 12/23/2016. In this chapter, you will:

Linked List using a Sentinel

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

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

For example, let s say we define an array of char of size six:

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

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

CS 103 Lab - Party Like A Char Star

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

Chapter 10 Characters, Strings, and the string class

Chap 0: Overview. Overview of basic C++ syntax Refresh programming basics C++ Vs. Java differences Coding conventions used. EECS 268 Programming II 1

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

Chapter 10. Arrays and Strings

EX3 Code Review. Instructor: Tsung-Che Chiang

3. Functions. Modular programming is the dividing of the entire problem into small sub problems that can be solved by writing separate programs.

Short Notes of CS201

Strings in C++ Dr. Ferdin Joe John Joseph Kamnoetvidya Science Academy

! Mon, May 5, 2:00PM to 4:30PM. ! Closed book, closed notes, clean desk. ! Comprehensive (covers entire course) ! 30% of your final grade

Characters, c-strings, and the string Class. CS 1: Problem Solving & Program Design Using C++

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

CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING Chapter 6: One Dimensional Array

Review Questions for Final Exam

Problem Solving: Storyboards for User Interaction

CS201 - Introduction to Programming Glossary By

CS250 Final Review Questions

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

Chapter 10: Character Testing. From Program Character Case Conversion 8/23/2014. Character Testing. Character Case Conversion

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

Chapter 10: Characters, C- Strings, and More About the string Class

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

CSE030 Fall 2012 Final Exam Friday, December 14, PM

CSE 333 Midterm Exam Cinco de Mayo, 2017 (May 5) Name UW ID#

CMPS 221 Sample Final

Strings and Streams. Professor Hugh C. Lauer CS-2303, System Programming Concepts

cout << "How many numbers would you like to type? "; cin >> memsize; p = new int[memsize];

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

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):

Discussion 1E. Jie(Jay) Wang Week 10 Dec.2

I BSc(IT) [ Batch] Semester II Core: Object Oriented Programming With C plus plus - 212A Multiple Choice Questions.

True or False (15 Points)

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

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

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

Object Oriented Design

! Determine if a number is odd or even. ! Determine if a number/character is in a range. ! Assign a category based on ranges (wind speed)

2013 Academic Challenge

Exam 1 Practice CSE 232 Summer 2018 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty!

CSCI 6610: Intermediate Programming / C Chapter 12 Strings

Instructions. Quiz #2. Name: Solutions Student Number: Signature:

OBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES II

EECE.2160: ECE Application Programming Fall 2017

CS 216 Exam 1 Fall SOLUTION

CS 141, Introduction to Computer Science Fall Midterm Exam

Chapter 5. Section 5.4 The Common String Library Functions. CS 50 Hathairat Rattanasook

PROGRAMMING IN C AND C++:

EE 355 Lab 4 - Party Like A Char Star

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

CS150 Intro to CS I. Fall Fall 2017 CS150 - Intro to CS I 1

Object Oriented Pragramming (22316)

C Style Strings. Lecture 11 COP 3014 Spring March 19, 2018

Chapter 10: Characters, C- Strings, and More About the string Class Character Testing

Transcription:

Your name: Rules You must briefly explain your answers to receive partial credit. When a snippet of code is given to you, you can assume o that the code is enclosed within some function, even if no function definition is shown o that the main function is properly defined o that the iostream, fstream, string,cstring, and cmath libraries have been included at the beginning of the program. When you are asked to write a snippet of code, you may assume o that your code is enclosed within some function o that any necessary libraries have been included. When you are asked to write a complete program, you must write the #include statements, the int main(), etc. in your solution to receive full credit. A line consisting solely of represents one or more unspecified C++ statements, some of which may change the values of program variables. Grade (instructor use only) Your Score Max Problem 1 15 Problem 2 15 Problem 3 10 Problem 4 15 Problem 5 30 Problem 6 15 Total Problem 1: 15 points.

Parts (a)- (d): Match the following descriptions with the terms they describe by writing those terms in the space provided. The choices of terms are: this overloading constructor operator destructor bubble sort class selection sort struct linear search object binary search method reference pointer dereference Not all terms will be used. (a) An algorithm that puts an array in order by finding the smallest (or largest) element and getting it into place, then finding the second- smallest element, then the third- smallest, etc. (b) A function that is called automatically when an object is declared (c) A variable containing the address of another variable (d) A user- defined data type whose members are all public and can all be accessed directly with the dot- notation Page 2 of 13

Part (e): Given the following code: int num; int* p = &num; Write code that will do the same thing as cout << num << endl; without directly using the variable name num. Page 3 of 13

Problem 2: 15 points. Answer the following questions about the binary search code on the next page, which works identically to the binary search code from your labs. ARRAY CONTENTS Chuao Dagoba Godiva Hershey Lindt Tcho Valrhona Vosges Fill out the following table tracing a binary search for Scharffen-Berger in this array. You should fill out one row per iteration of the loop. If there are more rows than iterations, leave the extra rows blank. In the Compare To: column, you should give the VALUE (Chuao, Dagoba, etc.) that will be compared to Scharffen-Berger. Old value of first Old value of last Compare to: New value of first New value of last 0 7 Page 4 of 13

Code for Problem 2. You may tear this page out of your exam. In this code: arr is our 8- element array size is 8 searchstr is Scharffen- Berger int first = 0; int last = size 1; int middle; bool found = false; while ( first <= last and found == false) { } middle = (first + last) / 2; if ( searchstr == arr[middle] ) { found = true; } else if ( searchstr < arr[middle] ) { last = middle - 1; } else { first = middle + 1; } Page 5 of 13

Problem 3: 15 points. Assume the following: A C++ class called Person has been defined for you The cstring class has been included Person has 2 private data members: o char firstname[25]; o char lastname[25]; a) Finish defining the copy constructor for Person: // Copy the first name and last name of the other Person Person::Person( const Person& other) { } b) If p1 and p2 are two variables of type Person, we would like (p1 > p2) to be true if p1 s last name comes after p2 s last name alphabetically OR if their last names are the same and p1 s first name comes after p2 s first name. /* If our last name comes after the other last name, * or if our last names are tied and our first name * comes after the other first name, return true. * Otherwise, return false. */ bool Person::operator > ( const Person& other) const { } Page 6 of 13

Problem 4: 15 points. For this problem, you must write a class definition for a class named Circle that contains the elements listed below. Note that data members should be private and member functions should be public. You do not need to write the definitions of the member functions just the prototypes. You will define the functions in the next problem. The x and y coordinates of the center of the circle (both as float) The radius of the circle (as a float) Prototype for a default constructor Prototype for a function called SetCenter. This function will take two numeric values as inputs. It will not return anything. Prototype for a function called SetRadius. This function will take a numeric value as an input and return a bool. Prototype for a function called GetArea that will return the area of the circle Prototype for a function called IsInsideCircle. This function will take two numbers x1 and y1 as parameters and return true if the point (x1, y1) is inside the circle. Page 7 of 13

Page 8 of 13

Problem 5: 30 points. In this problem, you will write definitions for the functions in the class Circle. Here is a little bit more information about the functions. You may assume that cmath has been included. Note that none of your code for this problem should include cin or cout statements! The default constructor will initialize the center coordinates and the radius to 0. The SetCenter function will set x equal to its first input and y equal to its second input. The SetRadius function will: o return false if its input is less than 0. o otherwise, set the radius equal to its input parameter and return true. The GetArea function will return the area of the circle. Remember that the area is equal to pi times the square of the radius. The IsInsideCircle function should return true if the input point (x1, y1) is inside the circle and false otherwise. Here s how to figure that out: o If the distance between (x1, y1) and the center of the circle (x, y) is smaller than the radius, then the point is inside the circle. o To get the distance between (x1, y1) and (x, y), you can imagine a right triangle whose hypotenuse is the distance. In other words: (x- x1) 2 + (y- y1) 2 = distance 2 You can take it from here J Page 9 of 13

Page 10 of 13

Problem 6: 15 points. Assume that the class definitions you wrote in Problems 4 and 5 are located in a file called Circle.h in the same directory as the program you re about to write. Write a complete program that uses the Circle class from Circle.h to do the following: Create a Circle object. Ask the user to supply the center coordinates and the radius. Print an error message and exit the program if the radius is negative. Set the center and radius of your object. Use the GetArea function to calculate the area of this circle, and print it Ask the user to supply the x and y coordinates of another point. Create a new circle with the same radius and with the center at these new coordinates. If the center of one circle is inside the other circle, print a message: Your points are too close together! Page 11 of 13

Page 12 of 13

REFERENCE C- string functions: strlen Input is a C- string. Returns the length of the string (not including the null terminator). Usage example: length = strlen(name); strcat Input is two C- strings. Appends the second string to the end of the first string (the first string is changed, but the second is not). Usage example: strcat(str1, str2); strcpy Input is two C- strings. Copies the second string to the first string, overwriting the original contents. Usage example: strcpy(str1, str2); strcmp Input is two C- strings. Returns 0 if they are the same, a negative number if str2 is alphabetically greater than str1, and a positive number if str1 is greater than str2. Usage example: if(strcmp(str1, str2) > 0) Page 13 of 13