The Hong Kong Polytechnic University Faculty of Engineering

Size: px
Start display at page:

Download "The Hong Kong Polytechnic University Faculty of Engineering"

Transcription

1 The Hong Kong Polytechnic University Faculty of Engineering Programme(s) : BEng(Hons) in Transportation Systems Engineering (41481, 41481SY) BSc(Hons) in Internet and Multimedia Technologies (42477) Higher Diploma in Electrical Engineering (41373, 41373NDS) BSc(Hons) in Biomedical Engineering (47401, 47401SY) BEng(Hons) in Electrical Engineering (41470) BEng(Hons) in Mechanical Engineering (43478) BEng(Hons) in Electronic and Information Engineering (42470) BEng(Hons) in Electronic Engineering (42479) Subject : Computer Programming Subject Code : ENG2002 Session : Semester 1, 2015/2016 Date : 10 December 2015 Time Allowed : 2 hours Time : 12:30 p.m. 2:30 p.m. Subject Lecturer(s) : Dr Frank Leung, Dr Dan Wang, Dr W.L. Chan This question paper has 14 pages including this cover page. Instructions to Candidates : This question paper contains TWO (2) sections. Section A contains 36 multiple-choice questions. Follow the instructions on the paper and answer all questions by marking the answers on the Answer Sheet provided. This section carries 60 marks. Section B contains 2 questions. Follow the instructions in the questions and fill in the blanks directly on the Question Paper. This section carries 40 marks. Attachment : Answer Sheet 1

2 Section A Instruction: When specified, you may choose more than one answer otherwise, choose ONE answer for each question. Choose the answer(s) by using the Answer Sheet provided. Questions 1-12 are allocated 1 mark each Questions are allocated 2 marks each. The total marks are 60. 1) On storing a string in memory, how many byte(s) will the null character at the end of the string occupy? a) 0 byte b) 1 byte c) 2 bytes d) 4 bytes e) 8 bytes 2) To perform file I/O operations, which of the following preprocessor directive must be present in the source file? (You may choose more than one answer.) a) #include <ifstream> b) #include <ofstream> c) #include <fstream> d) e) None of the above. 3) Consider the following C++ class, where the constructor is overloaded: class Example{ public: Example(){a=b=c=1 //Constructor 1 Example(int a1){a=a1b=c=1 //Constructor 2 Example(int a1, int b1){a=a1b=b1c=1 //Constructor 3 Example(int a1, int b1, int c1){a=a1b=b1c=c1 //Constructor 4 private: int a, b, c On declaring an object by writing: Example obj(1,2,3) which constructor will be called? a) Constructor 1 b) Constructor 2 c) Constructor 3 d) Constructor 4 e) None of the above. 4) On executing the following C++ declaration statement, what is the value of b[1][0]? int b[2][2] = {{1,{34 a) 0 b) 1 c) 34 d) The statement contains error(s) and cannot be executed. e) None of the above. 5) On executing the C++ declaration statement below, which of the following choices has the same value as represented by ex? int ex[10] a) &ex[0] b) &ex[9] c) *ex[0] d) *ex e) None of the above. 6) Which of the following is not a valid C++ statement? a) enum A {me=0, you =0, them=0 b) enum A {me=1, you =2, them=3 c) enum A {me, you, them d) enum A {me, you, me e) enum A {me=2, you=1 2

3 7) Which of the following commands in Command Prompt is for showing the names of files and folders in the current folder? a) dir b) directory c) cd d) type e) chdir 8) Which of the following is the default opening mode on opening an output file? a) ios:: app b) ios:: ate c) ios:: trunc d) ios::in e) None of the above. 9) Which of the following is NOT a valid C++ statement? a) char a='a' b) char a="a" c) char a=97 d) char a='\n' e) char a='\0' 10) Which of the following C++ statement will NOT lead to a change of the value of the variable c? a) c+1 b) c=c+1 c) c+=1 d) c++ e) ++c 11) Which of the following about C++ is correct? a) A variable of bool type can have two possible values, which can be the result of a logical operation. b) A bool variable's value of false is displayed as 1 when it is streamed to the standard output. c) The result of a relational operation has a type of char. d) bool cannot be the returned data type of a function. e) None of the above. 12) What is wrong with the following C++ code? const int SIZE =5 float scores[size] //Line 2 for(int i=0 i<=size i++) //Line 3 { cout << "Enter a score\n" cin >> scores[i] a) Line 2 cannot be compiled successfully. b) In Line 3, i should be initialized to 1 instead of 0. c) The array scores[] must be of type int. d) In Line 3, "<=" should be replaced by "<". e) None of the above. Instruction: Each of the following questions below takes TWO marks. When specified, you may choose more than one answer otherwise, choose ONE answer for each question. 13) On executing the following C++ program, what will be displayed on the output screen? int main () { int x[10] = {1,2,3,4,5,6,7,8,9,10 for (int i=1i<10i++) cout<<x[i] << " " 3

4 a) b) c) d) The program cannot be compiled and executed. e) A run-time error message will prompt out. 14) On executing the following C++ program, what will be displayed on the output screen? void greeting (int x, int y) { if (x > 5) if (y < 3) cout << "Hello " else cout << "Hi " cout << "Bye " if (x > 5) { if (y < 3) cout << "Hello " else { cout << "Hi " cout << "Bye " int main () { greeting (3, 2) greeting (1, 1) a) Bye Bye b) Bye Hi Bye Hi Bye c) Bye Hi Bye d) Bye Hi Bye Bye Hi Bye e) None of the above. Consider the following C++ program and answer Questions int main() { int x = 0 for(int i=0 i<3 i++) for(int j=0 j<4 j++) x++ cout << x++ << " " << x << endl //Line A 15) On executing the above C++ program, what will be displayed on the output screen? a) 0 0 b) 0 1 c) d) e) None of the above. 16) If x++ in Line A is replaced by ++x, what will be displayed on the output screen? a) 0 0 b) 0 1 c) d) e) None of the above. 17) On executing the following C++ program, how many '*' will be displayed on the output screen? int i = 20 4

5 void iplusplus(int i) { i=i-3 for(i = 0 i <10 iplusplus(i)) { i=i+3 cout << '*' a) 1 b) 3 c) 4 d) 10 e) Unknown as the program is trapped in an infinite loop. 18) On executing the following C++ program, what will be displayed on the output screen? int power(int a, int b) { int c=0 for(int i=0 i<b i++) c *= a return c cout << power(2, 3) << endl a) 0 b) 2 c) 8 d) 9 e) None of the above. Consider the following C++ program and answer Questions #define _CRT_SECURE_NO_WARNINGS 1 class Book { char* bookname public: Book() {cout << "Book Constructor" << endl bookname = new char[10] ~Book() {cout << "Book Destructor" << endl delete [] bookname void setname(char* thename) {strncpy(bookname,thename,9) class BookStore { public: BookStore() {cout << "BookStore Constructor" << endl booklist = new Book ~BookStore() {cout << "BookStore Destructor" << endl private: Book *booklist BookStore mystore cout << "Program finished" << endl 19) Should the variable bookname of the class Book be assumed to be under public or private? a) private b) public by default c) neither pubic nor private d) public because it appears in the class e) None of the above. 5

6 20) How many bytes of memory leaks will occur on running the above program? a) 0 b) 4 c) 10 d) 14 e) The program contains error(s) and cannot run. Consider the following C++ program and answer Questions int main(){ int i enum month { JAN = 1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC for (i = MAR i <= NOV ++i) cout << i << " " //Line A 21) On executing the above C++ program, what will be displayed on the output screen? a) b) c) d) e) None of the above. 22) If i in Line A is changed to i++, what will be shown on the output screen? a) b) c) d) e) None of the above. Consider the following C++ program and answer Questions void print(char arg[], int length) { for (short c = 0 c<length c++) //Line 4 cout << arg[c] cout << " & " char first[] = { 'e','x','a','m' char second[] = { 'e','n','g','2','0','0','2' print(first, 3) print(second, 6) 23) On executing the above C++ program, what will be displayed on the output screen? a) exa & eng200 & b) exa & en & 200 c) ex & eng200 & d) exa & g200 & e) A run-time error message will prompt out. 24) If c=0 and c++ in Line 4 are changed to c=1 and ++c respectively, what will be shown on the output screen on executing this program? a) xam & ng200 & b) xa & ng200 & c) xa & eng200 & d) xam & eng200 & e) A run-time error message will prompt out. Consider the following C++ program and answer Questions

7 #include <fstream> int position ofstream output("test.txt") output.write("do you want to", 17) //Line 6 position = output.tellp() output.seekp(position - 3) //Line 8 output.write("*pass?", 8) //Line 9 output.close() 25) On executing the above C++ program, what will be the content of the file test.txt? a) Do you want*pass? b) Do you want to *p? c) Do you want to*pass? d) you want to*pass? e) ant to*pass? 26) If Line 6, Line 8 and Line 9 are changed to output.write ("Do you want to", 18), output.seekp (pos -16) and output.write ("*pass?.",0) respectively, what will be shown on the output screen on executing the program? a) Do you want to b) Do*pass?.nt to c) Do you want t d) Do you wan e) *pass?. 27) On executing the C++ program below, what will be displayed on the output screen? int mult (int x, int y) { int result = 0 while (y!= 0) { result = result + x y = y - 1 return(result) int x = 5, y = 5 cout << mult(x, y) a) 20 b) 25 c) 30 d) 35 e) A run-time error message will prompt out. 28) On executing the C++ program below, what will be displayed on the output screen? void func(int a = 100, bool flag = true) { if (flag == true ) cout << "Flag is true. a = " << a else cout << "Flag is false. a = " << a func(200, false) a) Flag is true. a = 200 b) Flag is false. a = 100 c) Flag is false. a = 200 7

8 d) Flag is true. a = 100 e) None of the above. 29) On executing the C++ program below, what will be displayed on the output screen? void Values(int, int = 10) Values(1) Values(3, 4) void Values(int n1, int n2) { cout << n1 <<" "<< n2 <<" " a) b) c) d) A run-time error message will prompt out. e) The program cannot be successfully compiled and executed. 30) Consider the following C++ program. What should be written in Line 6 in order to convert the decimal integer value of input into a string stored in str1[]? #define _CRT_SECURE_NO_WARNINGS 1 int input = 10 char str1[3] //Line 6 std::cout << str1 //Display 10 on the screen a) _itoa(str1, input, 2) b) str1= _itoa(input) c) input= _itoa(str1) d) _itoa(input,str1,10) e) _itoa(input,str1,2) 31) On executing the C++ program below, what will be displayed on the output screen? int number=1001 int pl= 1int output=0 while (number!= 0 ) { output += number % 10 * pl number /= 10 pl *= 2 cout << output a) 9 b) 11 c) 13 d) 15 e) 1 32) On executing the C++ program below, what will be displayed on the output screen? int Array1[]={3, 7, 1, 9, 5 int Array2[5] for (int i = 0 i < 5 i++) Array2[4 - i] = Array1[i] for (int i = 0 i < 5 i++) Array1[i] = Array2[i] 8

9 cout << Array1[1] a) 1 b) 3 c) 5 d) 7 e) 9 33) On executing the C++ program below, what will be displayed on the output screen? int x=40 void fun(int x, int y) { x = 20 y = 30 int x = 10 fun(x, x) cout << x a) 10 b) 20 c) 30 d) 40 e) The program cannot be successfully compiled and executed. 34) On executing the following C++ program, what will be displayed on the output screen? int a=1, b=2 int add(int a, int b) int i = 5, j = 6 cout << add(i, j) << endl int add(int a, int b ) { int sum = a + b a = 7 return a + b a) 3 b) 11 c) 12 d) 13 e) The program cannot be successfully compiled and executed. 35) On executing the following C++ program, what will be displayed on the output screen? int func(int m = 10, int n) { int c c = m + n return c cout << func(5) a) 15 b) 10 c) A run-time error message will prompt out. d) The program cannot be successfully compiled and executed. e) None of the above. 9

10 36) On executing the following C++ program, what will be displayed on the output screen? void print(int i) { cout << i void print(double f) { cout << f int main(void) { print(5) print( ) a) b) c) d) 5500 e) 5 10

11 Section B Q1 It is assumed that the current folder contains a file named "exam.txt", which has only one line "ENG2002*exam*" as its content. The file content is shown below. Write a program that uses an array to store the content of the above file. The user needs to input the starting position of the file to read for storing to the array. The position of the first character 'E' has a value of 0. Complete the program below. (20 marks) #include // Header file for standard I/O (1 mark) #include // Header file for file I/O (1 mark) ifstream fin("exam.txt") // Open exam.txt as an input file /*Check whether the file could be opened or not. If the file cannot be opened for whatever reason, display the error message "File could not be opened." and the program ends. (3 marks)*/ if ( ) { /* File has been opened successfully. */ /* Read from the beginning to the end of the file to determine the number of characters in the file. Then, close the file. (3 marks)*/ char ch int ccount = 0 //Count the number of characters in the file while ( ) // After the above while loop, ccount stores the no. of characters in file. // Close the file // Ask the user to enter the starting position to read from the file. // Notice that the first position is position 0. int seek_position //Repeatly ask the user to enter starting position if outside 0 to ccount-1 do { //2 marks cout << "Enter the starting position to read from the file:(0-" cout << ccount-1 << "): " cin >> seek_position while ( ) ifstream fin2("exam.txt") 11

12 // Move the reading position to seek_position (2 marks) int array_size = 100 //Create a character array of size array_size in the heap (2 marks) char * parray = int aindex = 0 // Index of array /* Read from file starting from seek_position to end of file into array started from the first element. (3 marks)*/ while (fin2.get(ch)) { // Update aindex //Add a null character at the end of the string in the array. //Display the string stored in the array. (1 mark) cout << endl // Close the file (1 mark) //Release the memory for storing the array in the heap. (1 mark) Sample outputs on executing the program inside Visual Studio. (The numbers 13, -1, 0 and 11 are entered by the user.) 12

13 Q2 Build a static library for the class Arithmetic, which includes two member variables of type int and provides functions to compute addition and power for them. The project name for this static library is ariproj. The class is declared in the header file Arithmetic.h. Complete the header file and implement the member functions in the file ArithCodes.cpp for the static library below. (11 marks) Arithmetic.h // Arithmetic.h is the header file's name for the class Arithmetic class Arithmetic { public: //constructor: set the inputs to be values of the member variables //by calling member function SetNum() Arithmetic::Arithmetic(int number1, int number2) //set the inputs to be values of num1 and num2 respectively void SetNum(int number1, int number2) int GetNum1() //return the value of num1 int GetNum2() //return the value of num2 int Add() // return the sum of two member variables int Power() // return num1 to the power of num2 private: int num1 //store the first input number int num2 //store the second input number ArithCodes.cpp // Member function implementation for class Arithmetic. //End class Arithmetic //Include header file. //Constructor: set the inputs to be values of the member variables //by calling member function SetNum() Arithmetic::Arithmetic(int number1, int number2) { //Set the inputs to be values of num1 and num2 respectively void Arithmetic::SetNum(int number1, int number2) { //Return the value of num1 int Arithmetic::GetNum1() { //Return the value of num2 int Arithmetic::GetNum2() { //Return the sum of the two member variables int Arithmetic::Add() { /*Return num1 to the power of num2 (you are not allowed to call library functions for the implementation)*/ 13

14 int Arithmetic::Power() { What is the name of the library file created after you have built the static library project? (1 mark) A new project is opened to use the above static library. Its main() function is in the A.cpp file. Give the names of the files this project needs for using the class Arithmetic and its static library. (2 marks) Complete the program in the A.cpp file below (assuming that the appropriate files of the static library have been added to the project in the correct location) in order to obtain the sample output given. (6 marks) A.cpp #include //Include definition of the class. int n1, n2 cout<<"please enter two numbers:" cin>>n1>>n2 //Create Arithmetic object named calc with input values of n1 and n2 /*Show the 2 input nos. by calling member functions of the object.*/ cout<<"the two input numbers are: "<< cout<<" "<< <<endl //Show the sum of the 2 nos. by calling the member function of the object cout<<"the sum of two numbers is: "<< <<endl //Show the power of the 2 nos. by calling the member function of the object cout<<"the power of two numbers is: "<< <<endl Sample output (2 and 3 in the first line are entered by the user): END 14

THE HONG KONG POLYTECHNIC UNIVERSITY Faculty of Engineering. Computer Programming Closed-book Written Test 3 Date: 28 March 2009 Time: 2:30 3:30 pm

THE HONG KONG POLYTECHNIC UNIVERSITY Faculty of Engineering. Computer Programming Closed-book Written Test 3 Date: 28 March 2009 Time: 2:30 3:30 pm THE HONG KONG POLYTECHNIC UNIVERSITY Faculty of Engineering Computer Programming Closed-book Written Test 3 Date: 28 March 2009 Time: 2:30 3:30 pm Name: Programme Code: Student No. This test aims at assessing

More information

C++_ MARKS 40 MIN

C++_ 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 information

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

Computer Department. Question (1): State whether each of the following is true or false. Question (2): Select the correct answer from the following: Computer Department Program: Computer Midterm Exam Date : 19/11/2016 Major: Information & communication technology 1 st Semester Time : 1 hr (10:00 11:00) Course: Introduction to Programming 2016/2017

More information

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

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points) Name Definition Matching (8 Points) 1. (8 pts) Match the words with their definitions. Choose the best definition for each word. Relational Expression Iteration Counter Count-controlled loop Loop Flow

More information

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

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II: FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each): 1. The declaration below declares three pointer variables of type pointer to double that is

More information

Given the C++ declaration statement below, which of the following represents the value of exforsys? e) None of the above. 1K

Given the C++ declaration statement below, which of the following represents the value of exforsys? e) None of the above. 1K Instruction: When specified, you may choose more than one answer; otherwise, choose ONE answer for each question. Choose the answer(s) by circling it/them on the Answer Sheet provided. Questions 1-12 are

More information

Multiple Choice (Questions 1 14) 28 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) 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

Fundamentals of Programming Session 25

Fundamentals of Programming Session 25 Fundamentals of Programming Session 25 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2013 These slides have been created using Deitel s slides Sharif University of Technology Outlines

More information

Data Types. 9. Types. a collection of values and the definition of one or more operations that can be performed on those values

Data Types. 9. Types. a collection of values and the definition of one or more operations that can be performed on those values Data Types 1 data type: a collection of values and the definition of one or more operations that can be performed on those values C++ includes a variety of built-in or base data types: short, int, long,

More information

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

CPE Summer 2015 Exam I (150 pts) June 18, 2015 Name 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. You can assume that there is one

More information

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

Name Section: M/W T/TH Number Definition Matching (8 Points) Name Section: M/W T/TH Number Definition Matching (8 Points) 1. (8 pts) Match the words with their definitions. Choose the best definition for each word. Iteration Counter Event Counter Loop Abstract Step

More information

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

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible) 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

C++ Programming Assignment 3

C++ Programming Assignment 3 C++ Programming Assignment 3 Author: Ruimin Zhao Module: EEE 102 Lecturer: Date: Fei.Xue April/19/2015 Contents Contents ii 1 Question 1 1 1.1 Specification.................................... 1 1.2 Analysis......................................

More information

Multiple Choice (Questions 1 14) 28 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) 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

Suppose we find the following function in a file: int Abc::xyz(int z) { return 2 * z + 1; }

Suppose 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 information

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

Name Section: M/W T/TH Number Definition Matching (6 Points) Name Section: M/W T/TH Number Definition Matching (6 Points) 1. (6 pts) Match the words with their definitions. Choose the best definition for each word. Event Counter Iteration Counter Loop Flow of Control

More information

Pointers, Dynamic Data, and Reference Types

Pointers, 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 information

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

CS2141 Software Development using C/C++ C++ Basics CS2141 Software Development using C/C++ C++ Basics Integers Basic Types Can be short, long, or just plain int C++ does not define the size of them other than short

More information

CS2255 HOMEWORK #1 Fall 2012

CS2255 HOMEWORK #1 Fall 2012 CS55 HOMEWORK #1 Fall 01 1.What is assigned to the variable a given the statement below with the following assumptions: x = 10, y = 7, and z, a, and b are all int variables. a = x >= y; a. 10 b. 7 c. The

More information

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

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible) 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

A First Program - Greeting.cpp

A First Program - Greeting.cpp C++ Basics A First Program - Greeting.cpp Preprocessor directives Function named main() indicates start of program // Program: Display greetings #include using namespace std; int main() { cout

More information

Short Notes of CS201

Short 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 information

CS Programming I: Arrays

CS Programming I: Arrays CS 200 - Programming I: Arrays Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624 Array Basics

More information

Review for COSC 120 8/31/2017. Review for COSC 120 Computer Systems. Review for COSC 120 Computer Structure

Review for COSC 120 8/31/2017. Review for COSC 120 Computer Systems. Review for COSC 120 Computer Structure Computer Systems Computer System Computer Structure C++ Environment Imperative vs. object-oriented programming in C++ Input / Output Primitive data types Software Banking System Compiler Music Player Text

More information

Solved Exercises from exams: Midterm(1)

Solved Exercises from exams: Midterm(1) Solved Exercises from exams: Midterm(1) 1431-1432 1. What is the output of the following program: #include void fun(int *b) *b = *b+10; main() int a=50; fun(&a); cout

More information

CS201 - Introduction to Programming Glossary By

CS201 - 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 information

Scientific Computing

Scientific Computing Scientific Computing Martin Lotz School of Mathematics The University of Manchester Lecture 1, September 22, 2014 Outline Course Overview Programming Basics The C++ Programming Language Outline Course

More information

ComS 228 Exam 1. September 27, 2004

ComS 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 information

2 2

2 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 information

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

Review: C++ Basic Concepts. Dr. Yingwu Zhu Review: C++ Basic Concepts Dr. Yingwu Zhu Outline C++ class declaration Constructor Overloading functions Overloading operators Destructor Redundant declaration A Real-World Example Question #1: How to

More information

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

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable Basic C++ Overview C++ is a version of the older C programming language. This is a language that is used for a wide variety of applications and which has a mature base of compilers and libraries. C++ is

More information

Come and join us at WebLyceum

Come and join us at WebLyceum Come and join us at WebLyceum For Past Papers, Quiz, Assignments, GDBs, Video Lectures etc Go to http://www.weblyceum.com and click Register In Case of any Problem Contact Administrators Rana Muhammad

More information

Lecture 14. Dynamic Memory Allocation

Lecture 14. Dynamic Memory Allocation Copyright 1996 David R. Hanson Computer Science 126, Fall 1996 14-1 Lecture 14. Dynamic Memory Allocation The number of variables and their sizes are determined at compile-time before a program runs /*

More information

CS 376b Computer Vision

CS 376b Computer Vision CS 376b Computer Vision 09 / 25 / 2014 Instructor: Michael Eckmann Today s Topics Questions? / Comments? Enhancing images / masks Cross correlation Convolution C++ Cross-correlation Cross-correlation involves

More information

Operator overloading: extra examples

Operator 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 information

Definition: Data Type A data type is a collection of values and the definition of one or more operations on those values.

Definition: Data Type A data type is a collection of values and the definition of one or more operations on those values. Data Types 1 Definition: Data Type A data type is a collection of values and the definition of one or more operations on those values. Base Data Types All the values of the type are ordered and atomic.

More information

C++ Quick Guide. Advertisements

C++ Quick Guide. Advertisements C++ Quick Guide Advertisements Previous Page Next Page C++ is a statically typed, compiled, general purpose, case sensitive, free form programming language that supports procedural, object oriented, and

More information

POINTERS - Pointer is a variable that holds a memory address of another variable of same type. - It supports dynamic allocation routines. - It can improve the efficiency of certain routines. C++ Memory

More information

CSCS 261 Programming Concepts Exam 1 Fall EXAM 1 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. Name: Print legibly! Section: COMPUTER SCIENCE 261 PROGRAMMING CONCEPTS EXAM 1 VERSION 1 Fall 2014 150 Points Absolutely no electronic devices may be used during this exam. 1. No cell phones, computers,

More information

Text File I/O. #include <iostream> #include <fstream> using namespace std; int main() {

Text File I/O. #include <iostream> #include <fstream> using namespace std; int main() { Text File I/O We can use essentially the same techniques we ve been using to input from the keyboard and output to the screen and just apply them to files instead. If you want to prepare input data ahead,

More information

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

EEE145 Computer Programming

EEE145 Computer Programming EEE145 Computer Programming Content of Topic 2 Extracted from cpp.gantep.edu.tr Topic 2 Dr. Ahmet BİNGÜL Department of Engineering Physics University of Gaziantep Modifications by Dr. Andrew BEDDALL Department

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

The University of Nottingham

The 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 information

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

More information

CS242 COMPUTER PROGRAMMING

CS242 COMPUTER PROGRAMMING CS242 COMPUTER PROGRAMMING I.Safa a Alawneh Variables Outline 2 Data Type C++ Built-in Data Types o o o o bool Data Type char Data Type int Data Type Floating-Point Data Types Variable Declaration Initializing

More information

Writing a Good Program. 7. Stream I/O

Writing a Good Program. 7. Stream I/O Writing a Good Program 1 Input and Output I/O implementation is hardware dependent C++ does not, as a part of the language, define how data are sent out and read into the program The input and output (I/O)

More information

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

Quiz Start Time: 09:34 PM Time Left 82 sec(s) 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 information

COMP322 - Introduction to C++

COMP322 - 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 information

CS201 Latest Solved MCQs

CS201 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 information

University 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 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 information

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.

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. 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 information

DYNAMIC ARRAYS; FUNCTIONS & POINTERS; SHALLOW VS DEEP COPY

DYNAMIC ARRAYS; FUNCTIONS & POINTERS; SHALLOW VS DEEP COPY DYNAMIC ARRAYS; FUNCTIONS & POINTERS; SHALLOW VS DEEP COPY Pages 800 to 809 Anna Rakitianskaia, University of Pretoria STATIC ARRAYS So far, we have only used static arrays The size of a static array must

More information

Definition Matching (10 Points)

Definition 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 information

Preview 8/28/2018. Review for COSC 120 (File Processing: Reading Data From a File)

Preview 8/28/2018. Review for COSC 120 (File Processing: Reading Data From a File) Preview Relational operator If, if--if, nested if statement Logical operators Validating Inputs Compare two c-string Switch Statement Increment decrement operator While, Do-While, For Loop Break, Continue

More information

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++ CSCE 206: Structured Programming in C++ 2017 Spring Exam 2 Monday, March 20, 2017 Total - 100 Points B Instructions: Total of 13 pages, including this cover and the last page. Before starting the exam,

More information

C:\Temp\Templates. Download This PDF From The Web Site

C:\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 information

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

Starting Out with C++: Early Objects, 9 th ed. (Gaddis, Walters & Muganda) Chapter 2 Introduction to C++ Chapter 2 Test 1 Key Starting Out with C++ Early Objects 9th Edition Gaddis TEST BANK Full clear download (no formatting errors) at: https://testbankreal.com/download/starting-c-early-objects-9thedition-gaddis-test-bank/ Starting

More information

Collected By Anonymous

Collected By Anonymous CS201- Introduction to Programming Mega Collection for Final Term Only Solved Paper Year Session Paper # 01 2012 Unknown Paper # 02 2011 (session_02) Paper # 03 2011 (session_03) Paper # 04 2010 Unknown

More information

Programming Language. Control Structures: Repetition (while) Eng. Anis Nazer Second Semester

Programming Language. Control Structures: Repetition (while) Eng. Anis Nazer Second Semester Programming Language Control Structures: Repetition (while) Eng. Anis Nazer Second Semester 2017-2018 Repetition statements Control statements change the order which statements are executed Selection :

More information

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

FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): 1. The basic commands that a computer performs are input (get data), output (display result),

More information

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

5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (! FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): 1. Assume that all variables are properly declared. The following for loop executes 20 times.

More information

Exam 3 Chapters 7 & 9

Exam 3 Chapters 7 & 9 Exam 3 Chapters 7 & 9 CSC 2100-002/003 29 Mar 2017 Read through the entire test first BEFORE starting Put your name at the TOP of every page The test has 4 sections worth a total of 100 points o True/False

More information

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!

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! READ THIS NOW! Failure to read and follow the instructions below may result in severe penalties. Print your name in the space provided below. Print your name and ID number on the Opscan form; be sure to

More information

Chapter 2. Procedural Programming

Chapter 2. Procedural Programming Chapter 2 Procedural Programming 2: Preview Basic concepts that are similar in both Java and C++, including: standard data types control structures I/O functions Dynamic memory management, and some basic

More information

CSI33 Data Structures

CSI33 Data Structures Outline Department of Mathematics and Computer Science Bronx Community College November 9, 2016 Outline Outline 1 Chapter 9: C++ Classes Outline Chapter 9: C++ Classes 1 Chapter 9: C++ Classes Class Syntax

More information

This chapter introduces the notion of namespace. We also describe how to manage input and output with C++ commands via the terminal or files.

This chapter introduces the notion of namespace. We also describe how to manage input and output with C++ commands via the terminal or files. C++ PROGRAMMING LANGUAGE: NAMESPACE AND MANGEMENT OF INPUT/OUTPUT WITH C++. CAAM 519, CHAPTER 15 This chapter introduces the notion of namespace. We also describe how to manage input and output with C++

More information

For Teacher's Use Only Q No Total Q No Q No

For Teacher's Use Only Q No Total Q No Q No Student Info Student ID: Center: Exam Date: FINALTERM EXAMINATION Spring 2010 CS201- Introduction to Programming Time: 90 min Marks: 58 For Teacher's Use Only Q No. 1 2 3 4 5 6 7 8 Total Marks Q No. 9

More information

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++ Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++ 0.1 Introduction This is a session to familiarize working with the Visual Studio development environment. It

More information

Due Date: See Blackboard

Due 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 information

I/O Streams and Standard I/O Devices (cont d.)

I/O Streams and Standard I/O Devices (cont d.) Chapter 3: Input/Output Objectives In this chapter, you will: Learn what a stream is and examine input and output streams Explore how to read data from the standard input device Learn how to use predefined

More information

Syntax and Variables

Syntax and Variables Syntax and Variables What the Compiler needs to understand your program, and managing data 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line

More information

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

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 2013 Midterm Test Examiners: T.S. Abdelrahman, V. Betz, M. Stumm and H. Timorabadi Duration: 110

More information

CS201 Spring2009 Solved Sunday, 09 May 2010 14:57 MIDTERM EXAMINATION Spring 2009 CS201- Introduction to Programming Question No: 1 ( Marks: 1 ) - Please choose one The function of cin is To display message

More information

Chapter 1 INTRODUCTION

Chapter 1 INTRODUCTION Chapter 1 INTRODUCTION A digital computer system consists of hardware and software: The hardware consists of the physical components of the system. The software is the collection of programs that a computer

More information

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords. Chapter 1 File Extensions: Source code (cpp), Object code (obj), and Executable code (exe). Preprocessor processes directives and produces modified source Compiler takes modified source and produces object

More information

I SEMESTER EXAM : : XI :COMPUTER SCIENCE : MAX MARK a) What is the difference between Hardware and Software? Give one example for each.

I SEMESTER EXAM : : XI :COMPUTER SCIENCE : MAX MARK a) What is the difference between Hardware and Software? Give one example for each. I SEMESTER EXAM : : XI :COMPUTER SCIENCE : MAX MARK 70. a) What is the difference between Hardware and Software? Give one example for each. b) Give two differences between primary and secondary memory.

More information

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

Name SECTION: 12:45 2:20. True or False (12 Points) Name SECION: 12:45 2:20 rue or False (12 Points) 1. (12 pts) Circle for true and F for false: F a) Local identifiers have name precedence over global identifiers of the same name. F b) Local variables

More information

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

Multiple 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 information

University of Toronto

University 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 information

EP241 Computer Programming

EP241 Computer Programming EP241 Computer Programming Topic 2 Dr. Ahmet BİNGÜL Department of Engineering Physics University of Gaziantep Modifications by Dr. Andrew BEDDALL Department of Electric and Electronics Engineering Sep

More information

Distributed Real-Time Control Systems. Lecture 17 C++ Programming Intro to C++ Objects and Classes

Distributed Real-Time Control Systems. Lecture 17 C++ Programming Intro to C++ Objects and Classes Distributed Real-Time Control Systems Lecture 17 C++ Programming Intro to C++ Objects and Classes 1 Bibliography Classical References Covers C++ 11 2 What is C++? A computer language with object oriented

More information

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)

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

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

CSCI 102L - Data Structures Midterm Exam #1 Fall 2011 Print Your Name: Page 1 of 8 Signature: Aludra Loginname: CSCI 102L - Data Structures Midterm Exam #1 Fall 2011 (10:00am - 11:12am, Wednesday, October 5) Instructor: Bill Cheng Problems Problem #1 (24

More information

Summary of basic C++-commands

Summary of basic C++-commands Summary of basic C++-commands K. Vollmayr-Lee, O. Ippisch April 13, 2010 1 Compiling To compile a C++-program, you can use either g++ or c++. g++ -o executable_filename.out sourcefilename.cc c++ -o executable_filename.out

More information

CS 115 Exam 3, Spring 2010

CS 115 Exam 3, Spring 2010 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

More information

CSCE 2004 Final Exam Spring Version A

CSCE 2004 Final Exam Spring Version A 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

More information

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

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming

More information

2 nd Week Lecture Notes

2 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 information

Do not start the test until instructed to do so!

Do not start the test until instructed to do so! Fall 1999 Page 1 of 10 READ THIS NOW! Failure to read and follow the instructions below may result in severe penalties. Failure to adhere to these directions will not constitute an excuse or defense. Print

More information

CSE143 Exam with answers MIDTERM #1, 1/26/2001 Problem numbering may differ from the test as given.

CSE143 Exam with answers MIDTERM #1, 1/26/2001 Problem numbering may differ from the test as given. CSE143 Exam with answers MIDTERM #1, 1/26/2001 Problem numbering may differ from the test as given. All multiple choice questions are equally weighted. You can generally assume that code shown in the questions

More information

Introduction to Programming using C++

Introduction 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 information

! Operators such as =, +, <, can be defined to. ! The function names are operator followed by the. ! Otherwise they are like normal member functions:

! Operators such as =, +, <, can be defined to. ! The function names are operator followed by the. ! Otherwise they are like normal member functions: Operator Overloading, Lists and Templates Week 6 Gaddis: 14.5, 16.2-16.4 CS 5301 Spring 2016 Jill Seaman Operator Overloading! Operators such as =, +,

More information

The C++ Language. Arizona State University 1

The C++ Language. Arizona State University 1 The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

More information

double d0, d1, d2, d3; double * dp = new double[4]; double da[4];

double 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 information

Introduction to C ++

Introduction to C ++ Introduction to C ++ Thomas Branch tcb06@ic.ac.uk Imperial College Software Society October 18, 2012 1 / 48 Buy Software Soc. s Free Membership at https://www.imperialcollegeunion.org/shop/ club-society-project-products/software-products/436/

More information

Come and join us at WebLyceum

Come and join us at WebLyceum Come and join us at WebLyceum For Past Papers, Quiz, Assignments, GDBs, Video Lectures etc Go to http://www.weblyceum.com and click Register In Case of any Problem Contact Administrators Rana Muhammad

More information

DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++

DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++ DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++ Objective: To Learn Basic input, output, and procedural part of C++. C++ Object-orientated programming language

More information

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam Multimedia Programming 2004 Lecture 2 Erwin M. Bakker Joachim Rijsdam Recap Learning C++ by example No groups: everybody should experience developing and programming in C++! Assignments will determine

More information

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

! 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) Final Exam Exercises CS 2308 Spring 2014 Jill Seaman Chapters 1-7 + 11 Write C++ code to: Determine if a number is odd or even Determine if a number/character is in a range - 1 to 10 (inclusive) - between

More information