This test is OPEN Textbook and CLOSED notes. The use of computing and/or communicating devices is NOT permitted.
|
|
- Georgina O’Connor’
- 6 years ago
- Views:
Transcription
1 University of Toronto Faculty of Applied Science and Engineering ECE 244F PROGRAMMING FUNDAMENTALS Fall 2014 Midterm Test Examiners: T.S. Abdelrahman and M. Stumm Duration: 110 minutes This test is OPEN Textbook and CLOSED notes. The use of computing and/or communicating devices is NOT permitted. Do not remove any sheets from this test book. Answer all questions in the space provided. No additional sheets are permitted. Work independently. The value of each question is indicated. The total value of all questions is 100. Write your name and student number in the space below. Do the same on the top of each sheet of this exam book. Name: (Underline last name) Student Number: Q1. Q7. Q2. Q8. Q3. Q9. Q4. Q10. Q5. Q11. Q6. Q12. Total Page 1 of 25
2 Question 1. (8 marks). Pointers. (a) Consider the following declarations int i; int *pi; double d; double *pd; Which of the following statements is valid? Circle all the ones that are valid i=π *pi=&i; pd=π pd=i; pi=&i; (b) What would be printed from the following C++ code segment? int i=10; int *p; int **q; int ***r; p=&i; *p=15; q=&p; **q=20; r=&q; ***r= (*p) + 1; cout<< i; (c) What is the output of the following C++ code segment? #include <iostream> using namespace std; int do_something (int* & ptr1, int* ptr2) {\ int* t; *ptr1 = *ptr1 + *ptr2; *ptr2 = *ptr1 + *ptr2; t = ptr1; ptr1 = ptr2; ptr2 = ptr1; return (*ptr1 + *ptr2); int main () { int* p = new int; int* q = new int; int z; *p = 5; *q = 8; z = do_something (p, q); z = z + *p + *q; cout << z << endl; return (0); Page 2 of 25
3 Question 2. (5 marks). Functions. Assume there exists four classes: Mystery, StoryLine, Novel and Author. We wish to write a member function of class Author, called WriteIt, which takes two arguments. The first is an object of type Mystery, passed by value. The second is a pointer to an object of type StoryLine, passed by reference. The function returns an object of type Novel, by reference. Write the declaration (prototype) of the function below. Page 3 of 25
4 Question 3. (5 marks). Classes. Consider the following code. It may contain several errors. Identify these lines of code with errors and list them in the table shown on the next page, along with a short explanation of what the error is. To make it easy to refer to lines of code, lines numbers are shown (they are not part of the code). Where a line is not numbered, you may assume it is error-free. You may need all the rows of the table. class PossiblyBad { private: 01 int x; 02 int negate(); public: 03 float y; 04 PossiblyBad(int i, float f); 05 PossiblyBad(PossiblyBad source); 06 ~PossiblyBad(int k); 07 void Mystery(float f); ; 08 PossiblyBad::PossiblyBad(int i, float f) { 09 x = i; PossiblyBad::PossiblyBad(PossiblyBad source) { 12 x = source.x; y = source.y; void PossiblyBad::~PossiblyBad (int k) { 15 x = k; void PossiblyBad::Mystery(float f) { 18 y = (float) -1*x; int main () { 21 PossiblyBad a; 22 PossiblyBad b(1); 23 PossiblyBad c(1,3.5); 24 c.x = 2; 25 c.y = 5.8; 26 c.negate(); 27 c.mystery(6.8); return (0); Page 4 of 25
5 Line Number Explanation of Error Page 5 of 25
6 Question 4. (5 marks). Constructors and Destructors. Consider the following definition of a class Foo. class Foo { private: int x; public: Foo(int i); // call this the Integer constructor int getx() const; void setx(int i); Foo Mystery(Foo one, Foo & two); ; Foo::Foo(int i) { x = i; int Foo::getX() const { return x; void Foo::setX(int i) { x = i; Foo Foo::Mystery(Foo one, Foo & two) { Foo t(8); t.x = one.x + two.x; two.x = t.x; return (*this); Consider the code in the main functions below. int main () { Foo a(0); Foo b(1); // point A a.mystery(a,b); // point B return (0); Page 6 of 25
7 (a) How many constructors of class Foo are called between points A and B in the code? (b) Name the constructors that are called between points A and B. Use the table below to name the constructors, one per line. (c) How many constructors are called in the execution of main? (d) How many destructors are called between points A and B in the code? (e) How many destructors are called in the execution of main? Page 7 of 25
8 Question 5. (5 marks). C++ I/O. We wish to write a program that prompts the user to enter her first and last names at the standard input and then print her initials to the standard output. #include <iostream> using namespace std; int main () { char firstinitial; char lastinitial; cout << "Enter your first name followed by your last name: "; cout << "Your initials are: " << firstinitial << lastinitial << endl; return (0); Complete the program by writing code in the box shown above. You are not to declare/use any other variables than the ones shown in the program. However, you may use any of the functions of iostream (e.g., cin.peek(), cin.ignore() or cin.fail()). You may also assume that the user will always enter her first name followed by her last name. Your answer should be at most 3 lines of code. You will lose marks for additional lines. Here are example inputs and outputs for the program (user input is shown in italics): Enter your first name followed by your last name: Patricia Williams Your initials are PW Enter your first name followed by your last name: Sandy Your initials are SS Smith Enter your first name followed by your last name: Rachel McDonalds Your initials are RM Page 8 of 25
9 Question 6. (13 marks). Constructors and Destructors. Consider the following declaration of a class that represents a day of the year. You may assume that this class is implemented correctly and is error-free. using namespace std; #include <iostream> class DayOfYear { private: int day; int month; ; public: DayOfYear(); DayOfYear(int d, int m); DayOfYear(const DayOfYear & other); ~DayOfYear(); int getday() const; int getmonth() const; void setday(int d); void setmonth(int m); DayOfYear & operator=(const DayOfYear & src); void print() const; We wish to be able to write the following code in the function main. #include <iostream> #include <DayOfYear.h #include <string> #include <sstream> using namespace std; int main () { string s; s = ; // Day is 28 and month is 10 DayOfYear today(s); today.print(); return (0); The above code requires demands that one member function be added to the class. Write this function in the space below. Your answer should not exceed a few lines of code. { Write function header here Write function body here Page 9 of 25
10 Question 7. (8 marks). Operator Overloading. The following class is used to create objects that represent rectangles. Each rectangle is represented by a pair of coordinates: (x top,y top ) and (x bottom,y bottom ) corresponding respectively to the x and y coordinates of the top left and bottom right corners of the rectangle. using namespace std; #include <iostream> class Rectangle { private: int x_top; int y_top; int x_bottom; int y_bottom; ; public: Rectangle(int x_t, int y_t, int x_b, int y_b); int getxtop() const; int getytop() const; int getxbottom() const; int getybottom() const; void setxtop (int x_t); void setytop (int y_t); void setxbottom (int x_b); void setybottom (int y_b); Rectangle::Rectangle (int x_t, int y_t, int x_b, int y_b) { x_top = x_t; y_top = y_t; x_bottom = x_b; y_bottom = y_b; int Rectangle::getXtop() const {return (x_top); int Rectangle::getYtop() const {return (y_top); int Rectangle::getXbottom() const {return (x_bottom); int Rectangle::getYbottom() const {return (y_bottom); void Rectangle::setXtop(int x_t) {x_top = x_t; void Rectangle::setYtop(int y_t) {y_top = y_t; void Rectangle::setXbottom(int x_b) {x_bottom = x_b; void Rectangle::setYbottom(int y_b) {y_bottom = y_b; Page 10 of 25
11 We wish to overload the == operator for the Rectangle class to be able to write code like this in a non-member function (say main): Rectangle X(0,0,2,3); Rectangle Y(4.8,20,10); : if (X == Y) ; The function returns true if the areas of the two rectangles being compared are equal, otherwise returns false. Thus, for the example declarations above, (X == Y) returns in false. Write the implementation of the overloaded operator== function, once as a member of Rectangle and once as a non-member function. Clearly show the function header and its body. Write the overloaded operator== function as a member of Rectangle below Write the overloaded operator== function as a non-member function below Page 11 of 25
12 Question 8. (5 marks). Functions. Consider the following code of a class Foo. You may assume that the code is error free. class Foo { private: int x; ; public: Foo(int i); int getx() const; void setx(int i); Foo::Foo(int i) { x = i; int Foo::getX() const { return x; void Foo::setX(int i) { x = i; Consider the following non-member function printnagative: #include <iostream> using namespace std; void printnagative(const Foo & source) { cout << -1*source.x << endl; (a) This function, as written, has a problem with it. Describe what the problem is (one short sentence). (b) If we do not wish to change the function nor make it a member function of Foo, what change must be made to the class Foo to make printnegative correct? You may write your answer in the code of Foo above. (c) If we can change the function but still not make it a member function of Foo, re-write the body of the function to make it correct? Write your answer below. Page 12 of 25
13 Question 9. (4 marks). Program Organization. Consider the program below, which is organized into two header files and three.cpp files. A.h #ifndef A_H #define A_H class A { private: double d1; public: A(); ; #endif B.h #ifndef A_H #define A_H #include A.h class B { private: A a1; public: B(); ; #endif A.cpp B.cpp main.cpp #include A.h A::A () { #include A.h B::B () { #include A.h #include B.cpp int main () { A mya; B myb; return (0); What command would you use to compile your program? Write your answer below. Page 13 of 25
14 Question 10. (5 marks). Classes. Consider the following code of a class Mystery. You may assume that the declaration of the class is correct. However, the implementation of the class functions does contain several errors. Identify these errors and provide a brief explanation of each error in the table on the following page. To help you refer to lines of code, lines numbers are added to the left of the code (they are not part of the code). Note that you may not need all rows of the table. class Mystery { private: int x; int y; char* str; public: Mystery() const; int getx () const; int gety () const; void setx(int i); void sety(int i); ; int operator-(const Foo & rhs) const; Mystery::Mystery () const { x = 0; y = 0; str = new char[1]; str[0]= `\0`; 01 Mystery::~Mystery (){ delete str; 02 int Mystery::getX () const { if (x>10) x=10; return x; 03 int Mystery::getY () const { if (y>10) y=10; return y; 04 void Mystery::setX(int i) { x = i; 05 void Mystery::setY(int i) { y = i; 06 int operator-(const Mystery & rhs) const { 07 Mystery t; 08 int temp; 09 temp = x; 10 t.x = x rhs.x; 11 x = rhs.x - x; 12 t.x = x rhs.x; 13 x = rhs.x - x; 14 t.str[0] = rhs.str[0]; 15 rhs.str[0] = \0 ; 16 str[0] = t.str[0]; 17 return (temp); Page 14 of 25
15 Line Number Explanation of Error Page 15 of 25
16 Question 11. (5 marks). Classes and Objects. Consider the following declaration and implementation of the class Complex: #include <iostream> using namespace std; class Complex { private: float* real; float* imag; ; public: Complex(); Complex(float r, float i); float getreal() const; float getimag() const; void setreal(float r); void setimag(float i); void print() const; #include Complex.h Complex::Complex() { real = new float; *real = 0.0; imag = new float; *image = 0.0; Complex::Complex(float r, float i) { real = new float; *real = r; imag = new float; *image = i; float Complex::getReal() const { return (*real) ; int Complex::getImag() const { return (*imag) ; void Complex::setReal(float r) { *real = r; void Complex::setImag(float i) { *imag = i; void Complex::print() const { cout << ( << real <<, << imag << ) << endl; Page 16 of 25
17 Now consider the program below that uses the above Complex class. #include <iostream> #include Complex.h using namepace std; void flip(complex x, Complex &y) { x.setreal(y.getimag()); y.setimag(x.getimag)); void main() { Complex a(5.0,4.6); Complex b(3.7,1.5); flip(a,b); a.print(); b.print(); return (0); (a) What is the output produced by the program above? (b) Does the program above suffer from any memory leaks? If so, then how many variables (ints, floats, or objects of type Complex) end up being memory leaks? (c) There are problems with the above implementation of Complex that can be fixed by the addition of three member functions. In the space below, write the implementation of two of these functions (any two). Make sure to include the function header and the function body for each. Write the first function below Write the second function below Page 17 of 25
18 Question 12. (5 marks). Constructors and operator overloading. Consider the following C++ program: class Complex { private: double re ; double im ; static int ctorcount ; public: Complex() { re=im=0 ; cout << ++ctorcount << " "; Complex(const Complex& c) { re = c.re ; im = c.im ; cout << "copy" << ++ctorcount << " " ; Complex(double r, double i) { re = r ; im - i ; cout << ++ctorcount << " " ; ~Complex() { cout << "~" << ctorcount-- << " " ; Complex operator+( const Complex & rhs ) const { return Complex( re+rhs.re, im+rhs.im ) ; Complex operator-() const { return Complex( -re, im ) ; ; int Complex::ctorCount = 0 ; int main() { Complex *p ; Complex a(1,1) ; Complex b(-2,2) ; p = new Complex[3] ; cout << "A " <<endl ; p[0] = a ; cout << "B " <<endl ; p[1] = a + b ; cout << "C " <<endl ; p[2] = -a ; cout << "D" << endl; What is the output of this program? Page 18 of 25
19 Question 13. (5 marks). A Str class. Joe Programmer wrote a Str class to implement strings in a way that uses less memory than the C++ String or the C++ string class. The Str class is to behave just like the String class. For the following lines of code, provide a valid header for the constructor that would be invoked: Str s1 = abc ; Str s2 ; Str s3 = s2 ; Now, Joe wishes to write concatenate operators so that the following code works as expected: s3 = s1 + s2 ; s3 = abc + s2 ; s3 = s1 + bcd ; s3 = abc + cba ; How many operator+ functions does Joe have to define and implement? How many of those can be a member of the class? Page 19 of 25
20 Question 14. (5 marks). Operators. Assume C++ has a binary! valid C++ statements: operator defined. And assume the following two statements are c = a! b ; e = a! b! c! d ; where the operator in the first statement is guaranteed not to modify a and b, and second statement is interpreted as follows: e = ((a! b)! c)! d ; Programmer Suzy Hacker has defined a class T and started writing the declaration for operator!: T::operator!( T & ) ; (a) Place a in the code above where the cost keyword should be. (b) What should the return type be and does the operator return by value or by reference? (c) What goes in the space above in the code? Page 20 of 25
21 Question 15. (5 marks). Compilation. A program, prog.cpp, makes use of five classes, A, B, C, D, and E that are defined in the files A.cpp, B.cpp, C.cpp, D.cpp, and E.cpp, respectively, and declared in their corresponding.h files: A.h, B.h, C.h, D.h, and E.h, respectively. The following table describes which.h files are included in which files using the #include preprocessor statement: File prog.cpp A.cpp B.cpp B.h C.cpp D.cpp E.cpp Includes: A.h, C.h A.h, B.h B.h C.h C.h D.h, E.h E.h Assume that (i) the program has been compiled so that the executable prog has been generated along with all of the.o files: A.o, B.o, C.o, D.o, E.o, and prog.o, and subsequently (ii) the file C.h is modified. List below the precise Unix compiler commands required, in the correct order, to obtain the executable prog so that (i) the minimal number of.cpp files are compiled and so that (ii) subsequent changes to the source files allow the compilation of the minimal number of.cpp files. Page 21 of 25
22 Question 16. (5 marks). perhaps as part of a collection of short simple questions a) A C++ class can have multiple constructors. Can it have multiple destructors? If so, how many destructors can be there for any class that has n constructors? Explain. b) The C++ statement T a = b ; a. invokes the assignment operator b. invokes the default constructor c. invokes the copy constructor d. this is an incorrect statement c) True or False: In your C++ program, the input operator, <<, and the output operator, >>, can be overloaded either as a member function or as a non-member function d) What is wrong with the following code fragment: int *p1, *p2 ; p1 = new int ; p2 = new int ; *p1 = 11 ; *p2 = 0 ; p2 = p1 ; cout << *p1 << << *p2 << endl ; delete p1 ; delete p2 ; A: nothing B: p1 and p2 both have the same value, so the delete p2 will cause an error C: you have a memory leak D: B and C Page 22 of 25
23 e) Linked Lists Which of the following code fragment correctly inserts a new node containing num into a linked list after the node pointed to by afterme? void insert( Node *afterme, int num) { // code goes here A: afterme->link = new Node ; afterme->link ->number = num ; afterme->link->link = afterme->link ; B: Node * tmp = new Node ; tmp->number = num ; afterme->link = tmp ; tmp->link = afterme->link ; C: Node *tmp = new Node ; tmp->number = num ; tmp->link = afterme->link ; afterme->link = tmp ; D: Node *tmp = new Node ; tmp->number = num ; afterme->link = tmp ; tmp->link = NULL ; Page 23 of 25
24 Question 17. (5 marks). Constructors. Consider the following class definition: class A { private: B b; B *bp ; int value ; public: Write a copy constructor that does a deep copy in the space provided below: Page 24 of 25
25 Question 18. (5 marks). Call-by-reference, pointers and arrays. Write the output of the following program. (Note that int x[3]={1,2,3 initializes array x with x[0]=1, x[2]=2, and x[2]=3.) #include <iostream> using namespace std; void fun1 (int *p, int *&q) { *p = 100; p = p + 2; *p = *q; *q = *(p+1); cout << "p=" << *p << " q=" << *q << "\n"; bool fun2 (int x[], int size) { int *p = x; int *q; q = p; for (int i=1; i<size; i++) { x[i] += x[i-1]; cout << x[i] << " "; cout << "\n"; fun1 (p, q); return (*p == *q); int main ( ) { int a[5] = {2,4,6,8,10; if (fun2 (a,5)) cout << "true\n"; else cout << "false\n"; for (int i=0; i<5; i++) cout << a[i] << " "; return 0; Page 25 of 25
This test is OPEN Textbook and CLOSED notes. The use of computing and/or communicating devices is NOT permitted.
University of Toronto Faculty of Applied Science and Engineering ECE 244F PROGRAMMING FUNDAMENTALS Fall 2014 Midterm Test Examiners: T.S. Abdelrahman and M. Stumm Duration: 110 minutes This test is OPEN
More informationThis test is OPEN Textbook and CLOSED notes. The use of computing and/or communicating devices is NOT permitted.
University of Toronto Faculty of Applied Science and Engineering ECE 244F PROGRAMMING FUNDAMENTALS Fall 2013 Midterm Test Examiners: T.S. Abdelrahman, V. Betz, M. Stumm and H. Timorabadi Duration: 110
More informationUniversity of Toronto
University of Toronto Faculty of Applied Science and Engineering Midterm October, 2009 ECE244 --- Programming Fundamentals Examiners: Courtney Gibson, Wael Aboelsaadat, and Michael Stumm Instructions:
More informationCOMP322 - Introduction to C++
COMP322 - Introduction to C++ Winter 2011 Lecture 05 - I/O using the standard library & Introduction to Classes Milena Scaccia School of Computer Science McGill University February 1, 2011 Final note on
More informationUniversity of Toronto
University of Toronto Faculty of Applied Science and Engineering Midterm November, 2010 ECE244 --- Programming Fundamentals Examiners: Tarek Abdelrahman, Michael Gentili, and Michael Stumm Instructions:
More informationUniversity of Toronto
University of Toronto Faculty of Applied Science and Engineering Midterm Solutions October, 2008 ECE244 --- Programming Fundamentals Examiners: Courtney Gibson, Ashvin Goel, and Michael Stumm Instructions:
More information1. (25 pts) Short Answer. Provide brief (1-3 sentence) answers to the following:
CSCE A211 Sample Midterm 2 Name: 1. (25 pts) Short Answer. Provide brief (1-3 sentence) answers to the following: a) When defining a class, why is it considered a good practice to declare class variable
More informationMultiple Choice Questions (20 questions * 6 points per question = 120 points)
EECS 183 Fall 2014 Exam 2 Closed Book Minimal Notes Closed Electronic Devices Closed Neighbor Turn off Your Cell Phones We will confiscate all electronic devices that we see including cell phones, calculators,
More informationCircle all of the following which would make sense as the function prototype.
Student ID: Lab Section: This test is closed book, closed notes. Points for each question are shown inside [ ] brackets at the beginning of each question. You should assume that, for all quoted program
More informationCS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015
CS 141 - Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015 You may take this test with you after the test, but you must turn in your answer sheet. This test has the following sections:
More informationCMSC 202 Midterm Exam 1 Fall 2015
1. (15 points) There are six logic or syntax errors in the following program; find five of them. Circle each of the five errors you find and write the line number and correction in the space provided below.
More informationECE 461 Fall 2011, Final Exam
ECE 461 Fall 2011, Final Exam DO NOT START WORKING ON THIS UNTIL TOLD TO DO SO. LEAVE IT ON THE DESK. You have until 9:00PM to take this exam. Your exam should have 17 pages total (including this cover
More informationMARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #1 Examination 12:30 noon, Tuesday, February 14, 2012
MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #1 Examination 12:30 noon, Tuesday, February 14, 2012 Instructor: K. S. Booth Time: 70 minutes (one hour ten minutes)
More informationFunction Overloading
Function Overloading C++ supports writing more than one function with the same name but different argument lists How does the compiler know which one the programmer is calling? They have different signatures
More informationOutline. User-dened types Categories. Constructors. Constructors. 4. Classes. Concrete classes. Default constructor. Default constructor
Outline EDAF50 C++ Programming 4. Classes Sven Gestegård Robertz Computer Science, LTH 2018 1 Classes the pointer this const for objects and members Copying objects friend inline 4. Classes 2/1 User-dened
More informationCSCE 110 PROGRAMMING FUNDAMENTALS
CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class Prof. amr Goneid, AUC 1 Dictionaries(1): A Key Table Class Prof. Amr Goneid, AUC 2 A Key Table
More informationAgenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures
The main body and cout Agenda 1 Fundamental data types Declarations and definitions Control structures References, pass-by-value vs pass-by-references The main body and cout 2 C++ IS AN OO EXTENSION OF
More informationName: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015
CMSC 202 Section 06 Fall 2015 Computer Science II Midterm Exam I Name: Username: Score Max Section: (check one) 07 - Sushant Athley, Tuesday 11:30am 08 - Aishwarya Bhide, Thursday 11:30am 09 - Phanindra
More informationPointers and Arrays CS 201. This slide set covers pointers and arrays in C++. You should read Chapter 8 from your Deitel & Deitel book.
Pointers and Arrays CS 201 This slide set covers pointers and arrays in C++. You should read Chapter 8 from your Deitel & Deitel book. Pointers Powerful but difficult to master Used to simulate pass-by-reference
More informationADTs in C++ In C++, member functions can be defined as part of a struct
In C++, member functions can be defined as part of a struct ADTs in C++ struct Complex { ; void Complex::init(double r, double i) { im = i; int main () { Complex c1, c2; c1.init(3.0, 2.0); c2.init(4.0,
More informationOperator overloading: extra examples
Operator overloading: extra examples CS319: Scientific Computing (with C++) Niall Madden Week 8: some extra examples, to supplement what was covered in class 1 Eg 1: Points in the (x, y)-plane Overloading
More information1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.
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. B. Outputs to the console a floating point number f1 in scientific format
More informationECE 462 Fall 2011, Second Exam
ECE 462 Fall 2011, Second Exam DO NOT START WORKING ON THIS UNTIL TOLD TO DO SO. You have until 9:20 to take this exam. Your exam should have 10 pages total (including this cover sheet). Please let Prof.
More informationCSCS 261 Programming Concepts Exam 2 Fall EXAM 2 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.
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,
More informationName MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
CMPSC11 Final (Study Guide) Fall 11 Prof Hartman Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) This is a collection of statements that performs
More informationNo aids allowed. No books. No notes. No calculators. No computers. No communicating devices.
University of Toronto Faculty of Applied Science and Engineering ECE 244F PROGRAMMING FUNDAMENTALS Fall 2008 Final Examination Examiner: C. Gibson, A. Goel, and M. Stumm Duration: Two and a Half Hours
More informationCE221 Programming in C++ Part 1 Introduction
CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationCMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am
CMSC 202 Section 010x Spring 2007 Computer Science II Final Exam Name: Username: Score Max Section: (check one) 0101 - Justin Martineau, Tuesday 11:30am 0102 - Sandeep Balijepalli, Thursday 11:30am 0103
More informationName: I. 20 II. 20 III. 20 IV. 40. CMSC 341 Section 01 Fall 2016 Data Structures Exam 1. Instructions: 1. This is a closed-book, closed-notes exam.
CMSC 341 Section 01 Fall 2016 Data Structures Exam 1 Name: Score Max I. 20 II. 20 III. 20 IV. 40 Instructions: 1. This is a closed-book, closed-notes exam. 2. You have 75 minutes for the exam. 3. Calculators,
More informationCSCS 261 Programming Concepts Exam 2 Fall EXAM 2 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.
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,
More informationCSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100
CSC 126 FINAL EXAMINATION Spring 2011 Version A Name (Last, First) Your Instructor Question # Total Possible 1. 10 Total Received 2. 15 3. 15 4. 10 5. 10 6. 10 7. 10 8. 20 TOTAL 100 Name: Sp 11 Page 2
More informationCS201 - Introduction to Programming Glossary By
CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with
More informationECE Fall 2017, Third Exam
ECE 30862 Fall 2017, Third Exam DO NOT START WORKING ON THIS UNTIL TOLD TO DO SO. LEAVE IT ON THE DESK. THE LAST PAGE IS THE ANSWER SHEET. TEAR IT OFF AND PUT ALL ANSWERS THERE. TURN IN BOTH PARTS OF THE
More information3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.
3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.
More informationC++_ MARKS 40 MIN
C++_16.9.2018 40 MARKS 40 MIN https://tinyurl.com/ya62ayzs 1) Declaration of a pointer more than once may cause A. Error B. Abort C. Trap D. Null 2Whice is not a correct variable type in C++? A. float
More informationReview Questions for Final Exam
CS 102 / ECE 206 Spring 11 Review Questions for Final Exam The following review questions are similar to the kinds of questions you will be expected to answer on the Final Exam, which will cover LCR, chs.
More informationl 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)
Final Exam Exercises Chapters 1-7 + 11 Write C++ code to: l Determine if a number is odd or even CS 2308 Fall 2016 Jill Seaman l Determine if a number/character is in a range - 1 to 10 (inclusive) - between
More informationComS 228 Exam 1. September 27, 2004
ComS 228 Exam 1 September 27, 2004 Name: University ID: Section: (10 percent penalty if incorrect) This is a one-hour, closed-book, closed-notes, closed-calculator exam. The exam consists of 9 pages (including
More informationMidterm Review. PIC 10B Spring 2018
Midterm Review PIC 10B Spring 2018 Q1 What is size t and when should it be used? A1 size t is an unsigned integer type used for indexing containers and holding the size of a container. It is guarenteed
More informationRoxana Dumitrescu. C++ in Financial Mathematics
Roxana Dumitrescu C++ in Financial Mathematics What have we learnt? Arrays; relation between arrays and pointers.. Returning arrays from functions Passing arrays to functions Intoduction to classes Plan
More informationThe University of Nottingham
The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER 2011-2012 G52CPP C++ Programming Examination Time allowed TWO hours Candidates may complete the front cover of
More informationMultiple Choice Questions (20 questions * 5 points per question = 100 points)
EECS 183 Winter 2014 Exam 1 Closed Book Closed Notes Closed Electronic Devices Closed Neighbor Turn off Your Cell Phones We will confiscate all electronic devices that we see including cell phones, calculators,
More informationReview. Outline. Array Pointer Object-Oriented Programming. Fall 2017 CISC2200 Yanjun Li 1. Fall 2017 CISC2200 Yanjun Li 2
Review Fall 2017 CISC2200 Yanjun Li 1 Outline Array Pointer Object-Oriented Programming Fall 2017 CISC2200 Yanjun Li 2 1 Computer Fall 2017 CISC2200 Yanjun Li 3 Array Arrays are data structures containing
More informationCSC1322 Object-Oriented Programming Concepts
CSC1322 Object-Oriented Programming Concepts Instructor: Yukong Zhang February 18, 2016 Fundamental Concepts: The following is a summary of the fundamental concepts of object-oriented programming in C++.
More informationBasic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces
Basic memory model Using functions Writing functions Basics Prototypes Parameters Return types Functions and memory Names and namespaces When a program runs it requires main memory (RAM) space for Program
More informationUniversity of Michigan EECS 183: Elem. Programming Concepts Fall 2011 Exam 1: Part 1: Form 1. Professors: ML Dorf, Elliot Soloway
University of Michigan EECS 183: Elem. Programming Concepts Fall 2011 Exam 1: Part 1: Form 1 Professors: ML Dorf, Elliot Soloway Wed 9- February- 2011 35 questions * 3 pts each = 105 pts (yes we know there
More informationUniversity of Maryland Baltimore County. CMSC 202 Computer Science II. Fall Mid-Term Exam. Sections
University of Maryland Baltimore County CMSC 202 Computer Science II Fall 2004 Mid-Term Exam Sections 0201 0206 Lecture Hours: Monday Wednesday 5:30 PM 6:45 PM Exam Date: Wednesday 10/20/2004 Exam Duration:
More informationCIS 190: C/C++ Programming. Classes in C++
CIS 190: C/C++ Programming Classes in C++ Outline Header Protection Functions in C++ Procedural Programming vs OOP Classes Access Constructors Headers in C++ done same way as in C including user.h files:
More informationImplementing Abstract Data Types (ADT) using Classes
Implementing Abstract Data Types (ADT) using Classes Class Definition class classname { public: //public member functions private: //private data members and member functions }; // Note the semicolon!
More informationObject oriented programming
Exercises 6 Version 1.0, 21 March, 2017 Table of Contents 1. Operators overloading....................................................... 1 1.1. Example 1..............................................................
More information2. It is possible for a structure variable to be a member of another structure variable.
FORM 1(put name, form, and section number on scantron!!!) CS 162 Exam I True (A) / False (B) (2 pts) 1. What value will the function eof return if there are more characters to be read in the input stream?
More informationReview Questions for Final Exam KEY
CS 102 / ECE 206 Spring 11 Review Questions for Final Exam KEY The following review questions are similar to the kinds of questions you will be expected to answer on the Final Exam, which will cover LCR,
More informationPIC 10A. Lecture 17: Classes III, overloading
PIC 10A Lecture 17: Classes III, overloading Function overloading Having multiple constructors with same name is example of something called function overloading. You are allowed to have functions with
More informationMultiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More information/************************************************ * CSC 309/404 Review for Final -- Solutions * ************************************************/
/************************************************ * CSC 309/404 Review for Final -- Solutions * ************************************************/ #1: Give the output for the following program. #include
More informationCS 117 Programming II, Spring 2018 Dr. Ghriga. Midterm Exam Estimated Time: 2 hours. March 21, DUE DATE: March 28, 2018 at 12:00 PM
CS 117 Programming II, Spring 2018 Dr. Ghriga Midterm Exam Estimated Time: 2 hours March 21, 2018 DUE DATE: March 28, 2018 at 12:00 PM INSTRUCTIONS: Do all exercises for a total of 100 points. You are
More informationpointers & references
pointers & references 1-22-2013 Inline Functions References & Pointers Arrays & Vectors HW#1 posted due: today Quiz Thursday, 1/24 // point.h #ifndef POINT_H_ #define POINT_H_ #include using
More informationThe University of Nottingham
The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, AUTUMN SEMESTER 2009-2010 C/C++ for Java Programmers Time allowed TWO hours Candidates may complete the front cover of their answer
More informationMultiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More informationDefinition Matching (10 Points)
Name SOLUTION Closed notes and book. If you have any questions ask them. Write clearly and make sure the case of a letter is clear (where applicable) since C++ is case sensitive. There are no syntax errors
More informationConstructor - example
Constructors A constructor is a special member function whose task is to initialize the objects of its class. It is special because its name is same as the class name. The constructor is invoked whenever
More informationECE Fall 2018, Test 3
1 ECE 30862 Fall 2018, Test 3 DO NOT START WORKING ON THIS UNTIL TOLD TO DO SO. LEAVE IT ON THE DESK. THE LAST PAGE IS THE ANSWER SHEET. TEAR IT OFF AND PUT ALL ANSWERS THERE. TURN IN BOTH PARTS OF THE
More informationECE Fall 20l2, Second Exam
ECE 30862 Fall 20l2, Second Exam DO NOT START WORKING ON THIS UNTIL TOLD TO DO SO. LEAVE IT ON THE DESK. You have until 12:20 to take this exam. Your exam should have 16 pages total (including this cover
More informationPart I: Short Answer (12 questions, 65 points total)
CSE 143 Sp01 Final Exam Sample Solution page 1 of 14 Part I: Short Answer (12 questions, 65 points total) Answer all of the following questions. READ EACH QUESTION CAREFULLY. Answer each question in the
More informationIntroducing C++ to Java Programmers
Introducing C++ to Java Programmers by Kip Irvine updated 2/27/2003 1 Philosophy of C++ Bjarne Stroustrup invented C++ in the early 1980's at Bell Laboratories First called "C with classes" Design Goals:
More informationReview. Outline. Array Pointer Object-Oriented Programming. Fall 2013 CISC2200 Yanjun Li 1. Fall 2013 CISC2200 Yanjun Li 2
Review Fall 2013 CISC2200 Yanjun Li 1 Outline Array Pointer Object-Oriented Programming Fall 2013 CISC2200 Yanjun Li 2 1 Array Arrays are data structures containing related data items of same type. An
More informationการทดลองท 8_2 Editor Buffer Array Implementation
การทดลองท 8_2 Editor Buffer Array Implementation * File: buffer.h * -------------- * This file defines the interface for the EditorBuffer class. #ifndef _buffer_h #define _buffer_h * Class: EditorBuffer
More informationOverloading Operators in C++
Overloading Operators in C++ C++ allows the programmer to redefine the function of most built-in operators on a class-by-class basis the operator keyword is used to declare a function that specifies what
More informationPointers, Dynamic Data, and Reference Types
Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple
More information2 2
1 2 2 3 3 C:\Temp\Templates 4 5 Use This Main Program 6 # include "Utilities.hpp" # include "Student.hpp" Copy/Paste Main void MySwap (int Value1, int Value2); int main(int argc, char * argv[]) { int A
More informationCHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING. Dr. Shady Yehia Elmashad
CHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING Dr. Shady Yehia Elmashad Outline 1. Introduction to C++ Programming 2. Comment 3. Variables and Constants 4. Basic C++ Data Types 5. Simple Program: Printing
More informationMore Functions. Pass by Value. Example: Exchange two numbers. Storage Classes. Passing Parameters by Reference. Pass by value and by reference
Pass by Value More Functions Different location in memory Changes to the parameters inside the function body have no effect outside of the function. 2 Passing Parameters by Reference Example: Exchange
More informationLecture 7. Log into Linux New documents posted to course webpage
Lecture 7 Log into Linux New documents posted to course webpage Coding style guideline; part of project grade is following this Homework 4, due on Monday; this is a written assignment Project 1, due next
More informationMidterm Exam. Sample Solutions
Name: CS 410 Introduction to Software Engineering Fall 2016 Instructor: Marc Pomplun Midterm Exam Sample Solutions No books, no notes, and no calculators are allowed. Question 1: out of points Question
More informationCS 2604 Homework 1 C++ Review Summer I 2003
Instructions: This homework assignment covers some of the basic C++ background you should have in order to take this course. You will submit your answers to the Curator system. I. Pointers and Memory Management
More informationImplementing an ADT with a Class
Implementing an ADT with a Class the header file contains the class definition the source code file normally contains the class s method definitions when using Visual C++ 2012, the source code and the
More informationIS0020 Program Design and Software Tools Midterm, Fall, 2004
IS0020 Program Design and Software Tools Midterm, Fall, 2004 Name: Instruction There are two parts in this test. The first part contains 22 questions worth 40 points you need to get 20 right to get the
More informationAssignment operator string class c++ Assignment operator string class c++.zip
Assignment operator string class c++ Assignment operator string class c++.zip Outside class definitions; Addition assignment: a += b: The binding of operators in C and C++ is specified (character string)
More informationReference Parameters A reference parameter is an alias for its corresponding argument in the function call. Use the ampersand (&) to indicate that
Reference Parameters There are two ways to pass arguments to functions: pass-by-value and pass-by-reference. pass-by-value A copy of the argument s value is made and passed to the called function. Changes
More informationInitializing and Finalizing Objects
4 Initializing and Finalizing Objects 147 Content Initializing and Finalizing Objects 4 Constructors Default Constructor Copy Constructor Destructor 148 Initializing Objects: Constructors Initializing
More informationDue Date: See Blackboard
Source File: ~/2315/45/lab45.(C CPP cpp c++ cc cxx cp) Input: under control of main function Output: under control of main function Value: 4 Integer data is usually represented in a single word on a computer.
More informationCS201 Latest Solved MCQs
Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability
More informationName: Username: I. 10. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015
CMSC 202 Section 06 Fall 2015 Computer Science II Midterm Exam II Name: Username: Score Max Section: (check one) 07 - Sushant Athley, Tuesday 11:30am 08 - Aishwarya Bhide, Thursday 11:30am 09 - Phanindra
More information2 nd Week Lecture Notes
2 nd Week Lecture Notes Scope of variables All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous
More informationIntroduction to Programming using C++
Introduction to Programming using C++ Lecture One: Getting Started Carl Gwilliam gwilliam@hep.ph.liv.ac.uk http://hep.ph.liv.ac.uk/~gwilliam/cppcourse Course Prerequisites What you should already know
More informationC:\Temp\Templates. Download This PDF From The Web Site
11 2 2 2 3 3 3 C:\Temp\Templates Download This PDF From The Web Site 4 5 Use This Main Program Copy-Paste Code From The Next Slide? Compile Program 6 Copy/Paste Main # include "Utilities.hpp" # include
More informationdouble d0, d1, d2, d3; double * dp = new double[4]; double da[4];
All multiple choice questions are equally weighted. You can generally assume that code shown in the questions is intended to be syntactically correct, unless something in the question or one of the answers
More informationAbstract Data Types. Different Views of Data:
Abstract Data Types Representing information is fundamental to computer science. The primary purpose of most computer programs is not to perform calculations, but to store and efficiently retrieve information.
More informationSuppose we find the following function in a file: int Abc::xyz(int z) { return 2 * z + 1; }
Multiple choice questions, 2 point each: 1. What output is produced by the following program? #include int f (int a, int &b) a = b + 1; b = 2 * b; return a + b; int main( ) int x=1, y=2, z=3;
More informationUniversity of Illinois at Urbana-Champaign Department of Computer Science. First Examination
University of Illinois at Urbana-Champaign Department of Computer Science First Examination CS 225 Data Structures and Software Principles Spring 2007 7p-9p, Thursday, March 1 Name: NetID: Lab Section
More informationProgramming, numerics and optimization
Programming, numerics and optimization Lecture A-4: Object-oriented programming Łukasz Jankowski ljank@ippt.pan.pl Institute of Fundamental Technological Research Room 4.32, Phone +22.8261281 ext. 428
More informationObject Oriented Design
Object Oriented Design Lecture 3: Introduction to C++ (Continue) Examples using declarations that eliminate the need to repeat the std:: prefix 1 Examples using namespace std; enables a program to use
More informationGE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004
GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004 Functions and Program Structure Today we will be learning about functions. You should already have an idea of their uses. Cout
More informationReview: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements
Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja
More information(6) The specification of a name with its type in a program. (7) Some memory that holds a value of a given type.
CS 7A - Fall 2016 - Midterm 1 10/20/16 Write responses to questions 1 and 2 on this paper or attach additional sheets, as necessary For all subsequent problems, use separate paper Do not use a computer
More informationMultiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More informationSlide Set 14. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary
Slide Set 14 for ENCM 339 Fall 2016 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary November 2016 ENCM 339 Fall 2016 Slide Set 14 slide 2/35
More informationLab 2: ADT Design & Implementation
Lab 2: ADT Design & Implementation By Dr. Yingwu Zhu, Seattle University 1. Goals In this lab, you are required to use a dynamic array to design and implement an ADT SortedList that maintains a sorted
More informationUniversity of Illinois at Urbana-Champaign Department of Computer Science. First Examination
University of Illinois at Urbana-Champaign Department of Computer Science First Examination CS 225 Data Structures and Software Principles Spring 2007 7p-9p, Thursday, March 1 Name: NetID: Lab Section
More information