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

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

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

COMPUTER PROGRAMMING (ECE 431) TUTORIAL 9

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

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

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

Classes and Objects. Types and Classes. Example. Object Oriented Programming

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

CMSC 202 Midterm Exam 1 Fall 2015

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

Review Questions for Final Exam

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

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

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

EECS 183 Fall 2015 Exam 2 Free Response (134 points)

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

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

Computer Programming : C++

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

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

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

CS101 PLEDGED SPRING 2001

CS242 COMPUTER PROGRAMMING

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

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

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.

ComS 228 Exam 1. September 27, 2004

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

Abstract Data Types (ADTs) 1. Legal Values. Client Code for Rational ADT. ADT Design. CS 247: Software Engineering Principles

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am

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

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

CS 247: Software Engineering Principles. ADT Design

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

Do not turn to the next page until the start of the exam.

Final Exam. COMP Summer I June 26, points

Introduction to Programming EC-105. Lecture 2

CSCI 1370 APRIL 26, 2017

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

CS1500 Algorithms and Data Structures for Engineering, FALL Virgil Pavlu, Jose Annunziato,

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.

Lecture 7. Log into Linux New documents posted to course webpage

COMPUTER APPLICATION

Agenda / Learning Objectives: 1. Map out a plan to study for mid-term Review the C++ operators up to logical operators. 3. Read about the tips

LECTURE 02 INTRODUCTION TO C++

IT 1033: Fundamentals of Programming Data types & variables

Midterm Practice Exam

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

COSC 320 Exam 2 Key Spring Part 1: Hash Functions

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

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each).

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

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

CSC 210, Exam Two Section February 1999

Programming. C++ Basics

CS 376b Computer Vision

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

CSCE 206: Structured Programming in C++

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

CS201 Latest Solved MCQs

C++ For Science and Engineering Lecture 15

REVIEW. The C++ Programming Language. CS 151 Review #2

CS 240 Data Structure Spring 2018 Exam I 03/01/2018

Variables. Data Types.

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

CSCI-1200 Computer Science II Fall 2008 Lecture 15 Associative Containers (Maps), Part 2

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

Chapter 2: Introduction to C++

Circle all of the following which would make sense as the function prototype.

CS 115 Exam 3, Spring 2010

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

2 nd Week Lecture Notes

6.096 Introduction to C++

Fundamentals of Programming CS-110. Lecture 2

Integer Data Types. Data Type. Data Types. int, short int, long int

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

CSCI 102L - Data Structures Midterm Exam #1 Fall 2011

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

Computer Science II Lecture 1 Introduction and Background

University of Toronto

Makefiles Makefiles should begin with a comment section of the following form and with the following information filled in:

Sol. Sol. a. void remove_items_less_than(int arr[], int size, int value) #include <iostream> #include <ctime> using namespace std;

Tenka1 Programmer Contest/Tenka1 Programmer Beginner Contest 2018

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 2. C++ Basics

CSCE 110 PROGRAMMING FUNDAMENTALS

Part 1 (80 points) Multiple Choice Questions (20 questions * 4 points per question = 80 points)

Final Exam CS 152, Computer Programming Fundamentals December 9, 2016

Chapter 3 Problem Solving and the Computer

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

21. Exceptions. Advanced Concepts: // exceptions #include <iostream> using namespace std;

Linked List using a Sentinel

True or False (12 Points)

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

Exercise 1.1 Hello world

PROGRAMMING EXAMPLE: Checking Account Balance

PIC 10A. Lecture 17: Classes III, overloading

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

Object Oriented Design

Transcription:

Name: Print legibly! Section: COMPUTER SCIENCE 261 PROGRAMMING CONCEPTS EXAM 2 VERSION 1 Fall 2014 150 Points Absolutely no electronic devices may be used during this exam. 1. No cell phones, computers, calculators, music players, headphones, etc. 2. Set your cell phone to be completely silent, not vibrate. If it vibrates during the exam, it will be confiscated. 3. Place these and any other electronic devices in your backpack, out of immediate reach. Failure to follow these instructions will result in a zero for the exam. You are expected to complete this exam in its entirety before leaving the exam room. CLOSED BOOK CLOSED NOTES YOUR SCORE: POINTS 0

All of your answers must be written in clear, readable text. If we cannot read it, it is not correct. 1. 10 points. True or False. Write T or F to the left of each statement. An int takes up more space than a char in memory. Vectors can hold different types of elements inside the same object. In other words, I can have a vector that contains both ints and doubles. Arrays are stored in contiguous blocks of memory. It is NOT possible to create a multi-dimensional array that has more than three dimensions. C-style strings are dynamic, i.e., the user can change their size during run-time. To declare a 3x4 array of integers called myarray with all values set to 0 you can use: int myarray[3][4] = 0 }; Because of memory restrictions, we can only create multi-dimensional arrays of built-in data-types (int, float, double, char, and bool). The default constructor is always called whenever a class instance (object) is created. A global function in main.cpp has the same access to the members of a class as a member function of the class. Setter functions always require a parameter. 1

2. 10 points. Consider the class declaration for a Widget below. a. How many constructors are declared in the class? b. How many default constructors are declared in the class? c. List the names of the data members of the class. d. How many member functions (both public and private) are declared in the class? e. The member function punch is given a special name. What is it? - A private operator - The default constructor - A helper function - An accessor function Class Widget public: Widget(); Widget(double h); Widget(char n); Widget(double h, int f, char n); double gethappy(); int getfun(); void setfun(int f); void attack(widget &w); bool havingfun(); private: double happy; int fun; char name; int punch(widget &w); }; 3. 5 points. Circle all the valid constructor prototypes for a class named MyAccount? Assume the appropriate header files and namespace statements are provided. a. myaccount(double balance); b. MyAccount() const; c. void MyAccount(); d. MyAccount(const string& accountnumber, double balance); e. MyAccount(); 2

4. 8 points. Draw a conceptual picture of the array that would be created by the following code. Include both the indices and values. int data[] = 42, 37, 23, 88, 51, 91, 12, 67 }; int x = 5; data[x] = data[6]; data[6] = data[x]; data[x-1] = data[x] - 2; data[1] = 1; 5. 10 points. Suppose your program contains the following class definition: class Automobile public: Automobile(); Automobile(double newprice, double newprofit); void setprice(double newprice); void setprofit(double newprofit); double getprice() const; double getprofit() const; private: double price, double profit; }; and suppose the main part of your program contains the following declarations. Automobile prius, jaguar; double aprice, aprofit; First state YES or NO for each of the following statements on whether the statement would compile in the main part of your program. For those that you answer NO, briefly explain why not. a). aprice = prius.getprice; b). prius.price = 25999.99; c). aprofit = jaguar.getprofit(); d). jaguar.setprice(37999.97); e). Automobile myauto(429.5, 67.8); 3

6. 2 points. Which of the following statements are TRUE? Circle all that apply. a. Objects are required to be passed by reference. b. A header file is where data members of a class are defined. c. getters and setters provide managed access to data members. d. The class implementation file is where function prototypes are declared. 7. 2 points. Which of the following does a constructor perform? Circle all that apply. a. Construct a new class. b. Initialize prototypes. c. Construct a new function. d. Initialize objects. 8. 14 points. Given the following declarations: const int NROWS = 3; const int NCOLS = 4; double numbers[nrows][ncols]; double sums[nrows]; In both questions below, write code with NROWS/NCOLS (so values above can easily be changed). a. Provide code to set all values in the numbers array to 5. b. Provide code to sum the amounts in each row of the numbers array and place the results in the corresponding position in the sums array. 4

9. 9 points. Fill in each of the 10 blanks. a. Consider the declaration below. The size of the array in memory is elements. int a[4] = 0,0}; b. We use the keyword to ensure that a function cannot modify the contents of an array passed to it. c. To loop through all of the elements of a 5x8 2-D array you would use an index for the second dimension that goes from to. d. In a 2D array, the first and second dimensions are normally associated to the and of a table, respectively. e. To pass an integer to a function by reference, we use. f. To access member functions of the string class, we use the. g. Given that an integer takes 4 bytes of storage, and mynumbers[1] is stored at memory location 240, the address of mynumbers[3] is. h. In general, if a class has R private data members, you expect to have setter functions and getter functions. 10. 4 points. a. Write ONE statement that declares a one dimensional character array (called arr) with four elements, such that each of the elements are initialized to 'A'? b. Considering a character requires 1 byte of storage, how much memory is needed to store the array declared above? 11. 6 points. Draw a conceptual picture of the following array for THREE passes of the selection sort algorithm, which was described in both class and in your text required reading. In this example, data should be sorted in descending order. Show each pass of the algorithm in the space provided. int data[] = 25, 30, 101, 76, 5, 99, 15, 64 }; 5

12. 14 points. Write a function implementation (called diffminmax) that has a 1D integer array and array size as its parameters. The function returns the difference between the maximum and minimum numbers in the array. Your function should NOT use more than one for loop; that is, your function should find the max and min numbers in a single pass of the array. Also ensure that the contents of the array being passed cannot be changed. 13. 12 points. Given the following function header: Foo Foo::doIt (const Foo& f) const a. The FIRST Foo in the function header is the (be specific): b. The SECOND Foo in the function header is the (be specific): c. The THIRD Foo in the function head is the (be specific): d. What is the purpose of the FIRST const (be specific)? e. What is the purpose of the SECOND const (be specific)? 6

14. 8 points. Consider the C++ source below. It does not show some of the Time class member function implementations, but you may assume these are implemented and do the right thing. Write what will be printed for the values of the A and B calls to getsecs(). #include <iostream> using namespace std; class Time public: Time( double seconds ); void setsecs( double seconds ); double getsecs() const; void dothetimewarp( const Time& warpfactor ); void dothetimewarp( double warpfactor ); private: double secs; }; void Time::doTheTimeWarp( const Time& warpfactor ) secs = secs * warpfactor.secs; // multiply } void Time::doTheTimeWarp( double warpfactor ) secs = secs + warpfactor; / / add } int main() Time A(3), B(-1); cout << A.getSecs() << " " << B.getSecs() << endl; B.doTheTimeWarp( A ); cout << A.getSecs() << " " << B.getSecs() << endl; A.doTheTimeWarp( B.getSecs() ); cout << A.getSecs() << " " << B.getSecs() << endl; B.doTheTimeWarp( B ); cout << A.getSecs() << " " << B.getSecs() << endl; } return 0; 7

15. 16 points. Write the declaration of a new class, named Thermostat. Use const whenever appropriate. Your Thermostat class must have: a. One private double data member that holds the temperature (in Fahrenheit) at a given hour. b. One private integer data member that holds the hour (0 to 23) that the temperature was taken. c. A default constructor. d. A parameterized constructor that sets both the temperature and the hour. e. Accessor member functions for each data member. f. A member function that returns the callee s temperature in Celsius (i.e., converts Fahrenheit to Celsius. Note: C = (F 32)/1.8. 16. 5 points. Using your Thermostat class from problem 15, write one of the get functions. 8

17. 5 points. Using your Thermostat class from problem 15, write the implementation for the parameterized constructor. 18. 10 points. Using your Thermostat class from problem 15, write a main function that: a. Declares two Thermostat objects that are initialized with (72.1, 14) and (52.8, 4). b. Prints the temperature of the first (72.1, 14) Thermostat object in Fahrenheit. c. Sets the temperature of the second (52.8, 4) Thermostat object to 62.8. d. Prints the temperature of the object just modified in Celsius. 9