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

Size: px
Start display at page:

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

Transcription

1 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 allocated 1 mark each; questions are allocated 2 marks each. The total marks are 60. Q1 Given the C++ declaration statement below, which of the following represents the value of exforsys? int exforsys[10]; a) &exforsys[9] b) &exforsys[0] c) *exforsys[9] d) *exforsys[0] Q2 Given that k is an integer array starting at address 3000, kptr is a pointer to the array as declared by the C++ statements below. If each integer is stored in 4 bytes of memory, what is the value of kptr+2?. int k[20]; int *kptr=k; a) 3000 b) 3004 c) 3008 d) 3012 Consider the following C++ program named CBWT_3.exe that is executed inside the Command Prompt window using the command line CBWT_3 EIE236 programming test. Answer questions Q3 - Q4. int main(int argc, char *argv[]) cout << argv[argc-1]; Q3 What is the value of the variable argc after executing the above program? a) 5 b) 4 c) 3 d) 2 e) 1 Q4 What will be shown on the screen after executing the above program? a) CBWT b) CBWT_3 c) EIE236 d) programming e) test 1

2 Q5 Which of the following is/are true for describing the function prototype char * GetName()? (You may choose more than one answer.) a) GetName() is a pointer. b) GetName() may return a character pointer s value. c) GetName() requires no input parameters. d) GetName() may return the address of a character array in the heap. e) GetName() may return the address of a character in the heap. 1A Q6 Which of the following prototype describes the function that converts an unmanaged character array to an integer? a) int System::Convert::ToInt32(String); b) int System::Convert::ToInteger(String); c) int atoi (char *); d) int atof (char *); e) int itoa (char *); Q7 Which of the following statement about GDI+ is false? a) It involves a set of namespaces and library functions for the rendering of 3D graphics. b) It provides support for colors, pens, fonts, image transformations, etc. c) By using it, outputs of graphics can be shown on screens and printers. d) When starting a Windows Forms project in Visual C , GDI+ has been included by default. Q8 Consider the following event handler for a button in a managed application with GUI: private: System::Void button1_click(system::object ^ sender, System::EventArgs ^ e) no = 1; Form2 ^ F2 = gcnew Form2(no); F2->ShowDialog(); //Line 5 Which of the following description(s) about Line 5 is/are correct? (You may choose more than one answer.) a) A modal form will be shown on the screen. b) A form object will be instantiated. c) We cannot access other forms of this application unless we close the form generated by Line 5. d) We can access other forms of this application without closing the form generated by Line 5. e) Line 5 contains error(s) and cannot be successfully compiled. Q9 Which of the following statement(s) is/are declaring variable(s) of type supplied by the.net Framework Class Library? (You may choose more than one answer.) a) String ^ message; b) float i; c) char * message; d) Char text; e) char text[10]; Q10 Which of the following must return a number between 50 and 69 inclusively? a) rand()/20; b) rand()%70-50; c) rand()%70-1; d) rand()% ; 2

3 1A Q11 Consider the following event handler for a button in a managed application with GUI: private: System::Void button1_click(system::object^ sender, System::EventArgs^ e) String^ name = "Matt"; String^ group = "Gp. 84"; char* welcome = "Hello, "; strcat(welcome, name); // line 6 What should be the code in line 6 in order to make the output below shown on the screen on clicking the button? a) MessageBox::Show(welcome+name, group, MessageBoxButtons::OKCancel); b) MessageBox::Show(group, welcome+name, MessageBoxButtons::OKCancel); c) MessageBox::Show(welcome, group, MessageBoxButtons::OKCancel); d) MessageBox::Show(group, welcome, MessageBoxButtons::OKCancel); Q12 On executing the following C++ program, what will be the output shown on the screen? int y[8] = 8, 3, 2, 1, 4, 6, 7, 0; int *s; s = y + 2; cout << *s << " " << s[3] << endl; a) 8 1 b) 2 6 c) 2 1 d) 8 4 e) The program contains error(s) and cannot run. 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. Q13 On executing the following C++ program, what will be the output shown on the 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 3

4 cout << "Hi " ; cout << "Bye "; int main () greeting (3, 2); greeting (1, 1); a) Bye Bye b) Hi Bye Hi Bye Hi Bye Hi Bye c) Bye Hi Bye Bye Hi Bye d) Hi Bye Hi Bye e) The above program contains error(s) and cannot be executed. Consider the following C++ function that opens an input file. Then answer questions Q14 - Q16. int Count(char * filename) char ch; int count = 1; ifstream fin(filename); if( ) //Line 6 cout<<"no such file!"<<endl; while(fin.get(ch)) if( ch == '\n') count++; fin.close(); return count; Q14 Which of the following header file(s) should be included into the project before the statement ifstream fin(filename); can be successfully compiled? a) iostream b) fstream c) string.h d) Both a) and b) Q15 What should be put as the missing condition in Line 6 if the above function is supposed to show the message No such file! when the input file does not exist? a) filename b) fin c)!filename d)!fin Q16 Which of the following can be the job done by the above function? a) Return the number of characters in a file. b) Return the number of lines in a file. c) Return the number of words in a file. d) No job can be done as the function contains error(s). 2A Consider the following C++ program and answer questions Q17 - Q18. double *aa = new double[3];//assume aa store the address 0x00537ae0 aa[2] = 10; double *b = aa + 2; //Line 3 cout <<*b <<endl; delete [] aa; Q17 Which of the following is/are true for the above program? (You may choose more than one answer.) 4

5 a) The address of the memory storing the value of b is 0x00537ae8. b) Memory leak will occur after executing this program. c) The statement commented as Line 3 can be replaced by *b=10; d) The above program cannot be successfully compiled. 2E Q18 What will be shown on the screen on executing the above program? a) 0x00537AE8 b) 0x00537AF0 c) 10 d) Irrelevant as the above program cannot be successfully compiled. Consider the following 3 program segments for a managed application. Then answer questions Q19 - Q21. 1 using namespace System::Runtime::InteropServices; 2 #include <string.h> 3 private: System::Void button1_click(system::object^ sender, System::EventArgs^ e) 4 char message[100] = " Welcome "; 5 String ^ tbstr = textbox1->text; 6 char *name = (char*)marshal::stringtohglobalansi(tbstr).topointer(); 7 strcat(message,name); 8 String^ Mmge=Marshal::PtrToStringAnsi((IntPtr)message); 9 String^ title = " Hello "; 10 MessageBox::Show(Mmge,title,MessageBoxButtons:: OKCancel); 11 Marshal::FreeHGlobal((IntPtr)name); 12 Q19 Which of the following line(s) will generate compilation error(s) if line 1 is missing? (You may choose more than one answer.) a) Line 6 b) Line 7 c) Line 8 d) Line 10 e) Line 11 Q20 Which of the following line(s) will generate compilation error(s) if line 2 is missing? (You may choose more than one answer.) a) Line 4 b) Line 5 c) Line 6 d) Line 7 e) Line 8 Q21 What is the output shown on the screen if the application executes the above event handler when the user types nothing into the text box of handle textbox1? a) b) c) d) e) A run-time error message will be shown. 5

6 Q23 What will be seen on the screen on executing the program below? char a[10]="testing"; char b[10]="hello"; char *t = a; char *f = b; while (*t++=*f++); cout<<a<<" "; cout<<b<<endl; a) testing hello b) testing testing c) hello hello d) Many characters as the application is trapped into an infinite loop. 2E Consider the following C++ program and answer questions Q24 - Q25. #include <fstream> ofstream test1file("test1.txt"); test1file << " "; test1file.seekp(4); test1file << "test"; cout << test1file.tellp(); test1file.close(); 6

7 Q24 On executing the above C++ program, what will be shown on the screen? a) 0 b) 4 c) 8 d) 9 e) 10 Q25 On executing the above C++ program, what will be the content of the file test1.txt? a) 123test b) test c) 1234test90 d) 123test890 e) 1234test Q26 What will be shown on the screen on executing the program below? #include <fstream> ofstream test1file("test1.txt"); test1file << " "; test1file.close(); ifstream tin("test1.txt"); char ch; for (int i=2; i<5; i++) tin.get(ch); cout << ch; tin.close(); a) 123 b) 234 c) 2345 d) 345 Q27 On executing the following C++ program, what will be shown on the screen? #include <fstream> ofstream fout("myfile.txt"); fout << "This line is written to file. "; fout.close(); char fname[]="myfile.txt"; ofstream fout2(fname,ios::ate); fout2 << "Wonderful world. "; fout2.close(); ifstream fin("myfile.txt"); char ch; while (fin.get(ch)) cout << ch; fin.close(); a) This line is written to file. Wonderful world. b) Wonderful world. ten to file. c) Wonderful world. d) Wonderful world. This line is written to file. 2A Assume that on executing the following C++ program, the user inputs the 3 characters a, s and p and then presses the enter key. Answer the questions Q28 - Q29. 7

8 Q28 char input; cin>>input; // Assume the user inputs "asp" while ((input)!= 'p') // line 7 cout << "input: " << input<< ' '; What will be the output seen on the screen? a) input: a input: s input: p b) input: a input: s c) input: s d) The application is trapped in an infinite loop and continuously displays many characters. Q29 If line 7 is changed to while ((input=cin.get())!= 'p'), what will be the output shown on the screen? a) input: a input: s input: p b) input: s input: p c) input: s d) The application is trapped in an infinite loop and continuously displays many characters. 2A Consider the following event handler in a managed application with GUI. Then answer questions Q30 - Q31. private: System::Void Form1_Paint(System::Object ^ sender, System::Windows::Forms::PaintEventArgs ^ e) Graphics ^g = e->graphics; Drawing::Rectangle Head = Drawing::Rectangle(30, 30, 50, 50); g->fillellipse(brushes::yellow, Head); // Line 6 Q30 Which of the following description(s) is/are correct? (You may choose more than one answer.) a) The size of the drawn rectangle is b) The size of the drawn rectangle is c) The x and y coordinates of the drawn rectangle are for the bottom-left corner. d) The x and y coordinates of the drawn rectangle are for the top-left corner. Q31 Which of the following statement(s) about the above event handler is/are correct? (You may choose more than one answer.) a) The event handler can be called by this->invalidate(); b) The event handler can be called by Form1->Invalidate(); c) Line 6 can be changed to e->graphics->fillellipse(brushes::yellow, Head); d) A timer must be present in order to run this event handler. Q32 On executing the following C++ program in the Command Prompt window, the user enters test in the command line. What will be shown on the output screen? #include <stdlib.h> int main(int argc, char *argv[]) int temp=0; 8

9 for (int i = 1; i<argc; i++) temp=temp+atoi(argv[i]); cout<<temp<<endl; a) 0 b) 10 c) 24 d) 6 Q33 Consider the following Windows Forms application: If the event handler of the ok button is given as follows, what will be the output shown on the screen? private: System::Void button1_click(system::object^ sender, System::EventArgs^ e) int no1 = 5; String^ no2 = "2"; textbox1->text = no1+no2; a) b) c) d) e) The program contains error(s) and cannot run. 2E Q34 On executing the following C++ program, what will be shown on the screen? 9

10 int i=0; for(int j=0; j<9; j++) for(int j=0; j<9; j++) i++; cout<<i<<endl; a) 0 b) 80 c) 81 d) The program contains error(s) and cannot run. 2A Q35 On executing the following C++ program, what will be shown on the screen? int GPA=4; int *p1,*p2; p1=0; p2=0; p1=&gpa; p2=&gpa; *p1 = 2; *p2 = 3; cout<<*p1<<","<<*p2<<endl; a) 2,3 b) 4,4 c) 3,3 d) The program contains error(s) and cannot run. 2A Q36 On executing the following C++ program, what will be shown on the screen? #include <string.h> const int MaxLength = 80; char string1[] = "I like Maths and Programming."; char string2[] = "I like C++ and English."; cout<<strlen(string1)<<", "; cout<<strlen(string2)<<", "; strncpy(string1,string2,11); cout << string1 << endl; a) 30, 24, I like C++ a and programming. b) 30, 24, I like C++ s and programming. c) 29, 23, I like C++ a and programming. d) 29, 23, I like C++ s and programming. 2E - End - 10

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

Strings and Stream I/O

Strings and Stream I/O Strings and Stream I/O C Strings In addition to the string class, C++ also supports old-style C strings In C, strings are stored as null-terminated character arrays str1 char * str1 = "What is your name?

More information

File I/O Christian Schumacher, Info1 D-MAVT 2013

File I/O Christian Schumacher, Info1 D-MAVT 2013 File I/O Christian Schumacher, chschuma@inf.ethz.ch Info1 D-MAVT 2013 Input and Output in C++ Stream objects Formatted output Writing and reading files References General Remarks I/O operations are essential

More information

The Hong Kong Polytechnic University Faculty of Engineering

The Hong Kong Polytechnic University Faculty of Engineering 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

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

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

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

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

CSc Introduc/on to Compu/ng. Lecture 19 Edgardo Molina Fall 2011 City College of New York

CSc Introduc/on to Compu/ng. Lecture 19 Edgardo Molina Fall 2011 City College of New York CSc 10200 Introduc/on to Compu/ng Lecture 19 Edgardo Molina Fall 2011 City College of New York 18 Standard Device Files Logical file object: Stream that connects a file of logically related data to a program

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

CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings

CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings 19/10/2017 CE221 Part 2 1 Variables and References 1 In Java a variable of primitive type is associated with a memory location

More information

C++ does not, as a part of the language, define how data are sent out and read into the program

C++ does not, as a part of the language, define how data are sent out and read into the program Input and Output C++ does not, as a part of the language, define how data are sent out and read into the program I/O implementation is hardware dependent The input and output (I/O) are handled by the standard

More information

Lecture 2, September 4

Lecture 2, September 4 Lecture 2, September 4 Intro to C/C++ Instructor: Prashant Shenoy, TA: Shashi Singh 1 Introduction C++ is an object-oriented language and is one of the most frequently used languages for development due

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

Week 3: File I/O and Formatting 3.7 Formatting Output

Week 3: File I/O and Formatting 3.7 Formatting Output Week 3: File I/O and Formatting 3.7 Formatting Output Formatting: the way a value is printed: Gaddis: 3.7, 3.8, 5.11 CS 1428 Fall 2014 Jill Seaman spacing decimal points, fractional values, number of digits

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

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

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

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

A SHORT COURSE ON C++

A SHORT COURSE ON C++ Introduction to A SHORT COURSE ON School of Mathematics Semester 1 2008 Introduction to OUTLINE 1 INTRODUCTION TO 2 FLOW CONTROL AND FUNCTIONS If Else Looping Functions Cmath Library Prototyping Introduction

More information

Chapte t r r 9

Chapte t r r 9 Chapter 9 Session Objectives Stream Class Stream Class Hierarchy String I/O Character I/O Object I/O File Pointers and their manipulations Error handling in Files Command Line arguments OOPS WITH C++ Sahaj

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

Object Oriented Programming Using C++ UNIT-3 I/O Streams

Object Oriented Programming Using C++ UNIT-3 I/O Streams File - The information / data stored under a specific name on a storage device, is called a file. Stream - It refers to a sequence of bytes. Text file - It is a file that stores information in ASCII characters.

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

6.096 Introduction to C++ January (IAP) 2009

6.096 Introduction to C++ January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

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

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

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

Strings and Streams. Professor Hugh C. Lauer CS-2303, System Programming Concepts Strings and Streams Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by Walter

More information

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

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

Linked List using a Sentinel

Linked List using a Sentinel Linked List using a Sentinel Linked List.h / Linked List.h Using a sentinel for search Created by Enoch Hwang on 2/1/10. Copyright 2010 La Sierra University. All rights reserved. / #include

More information

SECTION A (15 MARKS) Answer ALL Questions. Each Question carries ONE Mark. 1 (a) Choose the correct answer: (10 Marks)

SECTION A (15 MARKS) Answer ALL Questions. Each Question carries ONE Mark. 1 (a) Choose the correct answer: (10 Marks) SECTION A (15 MARKS) Answer ALL Questions. Each Question carries ONE Mark. 1 (a) Choose the correct answer: (10 Marks) 1. The function is used to reduce function call a. Overloading b. Inline c. Recursive

More information

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ. C BOOTCAMP DAY 2 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Pointers 2 Pointers Pointers are an address in memory Includes variable addresses,

More information

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

#include <iostream> #include <algorithm> #include <cmath> using namespace std; int f1(int x, int y) { return (double)(x/y); } 1. (9 pts) Show what will be output by the cout s in this program. As in normal program execution, any update to a variable should affect the next statement. (Note: boolalpha simply causes Booleans to

More information

a data type is Types

a data type is Types Pointers Class 2 a data type is Types Types a data type is a set of values a set of operations defined on those values in C++ (and most languages) there are two flavors of types primitive or fundamental

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

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function CMPT 127 Spring 2019 Grade: / 20 First name: Last name: Student Number: Lab Exam 1 D400 1. [1 mark] Give an example of a sample input which would make the function scanf( "%f", &f ) return -1? Answer:

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

File Operations. Lecture 16 COP 3014 Spring April 18, 2018

File Operations. Lecture 16 COP 3014 Spring April 18, 2018 File Operations Lecture 16 COP 3014 Spring 2018 April 18, 2018 Input/Ouput to and from files File input and file output is an essential in programming. Most software involves more than keyboard input and

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

Exercise 1.1 Hello world

Exercise 1.1 Hello world Exercise 1.1 Hello world The goal of this exercise is to verify that computer and compiler setup are functioning correctly. To verify that your setup runs fine, compile and run the hello world example

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

Pointers. Addresses in Memory. Exam 1 on July 18, :00-11:40am

Pointers. Addresses in Memory. Exam 1 on July 18, :00-11:40am Exam 1 on July 18, 2005 10:00-11:40am Pointers Addresses in Memory When a variable is declared, enough memory to hold a value of that type is allocated for it at an unused memory location. This is the

More information

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

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 1/9/ Review. Here s a simple C++ program: Welcome Back CSCI 262 Data Structures 2 - Review What you learned in CSCI 261 (or equivalent): Variables Types Arrays Expressions Conditionals Branches & Loops Functions Recursion Classes & Objects Streams

More information

A stream is infinite. File access methods. File I/O in C++ 4. File input/output David Keil CS II 2/03. The extractor and inserter form expressions

A stream is infinite. File access methods. File I/O in C++ 4. File input/output David Keil CS II 2/03. The extractor and inserter form expressions Topic: File input/output I. Streams II. Access methods III. C++ style Input, output, random access Stream classes: ifstream, ofstream IV. C style The FILE data type Opening files Writing to, reading text

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

File handling Basics. Lecture 7

File handling Basics. Lecture 7 File handling Basics Lecture 7 What is a File? A file is a collection of information, usually stored on a computer s disk. Information can be saved to files and then later reused. 2 File Names All files

More information

Unit-V File operations

Unit-V File operations Unit-V File operations What is stream? C++ IO are based on streams, which are sequence of bytes flowing in and out of the programs. A C++ stream is a flow of data into or out of a program, such as the

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

Object-Oriented Programming in C++

Object-Oriented Programming in C++ Object-Oriented Programming in C++ Pre-Lecture 2: Prof Niels Walet (Niels.Walet@manchester.ac.uk) Room 7.07, Schuster Building January 30, 2015 Prelecture 2 Outline In this pre-lecture we will cover more

More information

Unified Modeling Language a case study

Unified Modeling Language a case study Unified Modeling Language a case study 1 an online phone book use case diagram encapsulating a file 2 Command Line Arguments arguments of main arrays of strings 3 Class Definition the filesphonebook.h

More information

CS 1428 Review. CS 2308 :: Spring 2016 Molly O Neil

CS 1428 Review. CS 2308 :: Spring 2016 Molly O Neil CS 1428 Review CS 2308 :: Spring 2016 Molly O Neil Structure of a C++ Program Hello world // This program prints a greeting to the screen #include using namespace std; int main() { cout

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

C++ Structures Programming Workshop 2 (CSCI 1061U)

C++ Structures Programming Workshop 2 (CSCI 1061U) C++ Structures Programming Workshop 2 (CSCI 1061U) Faisal Qureshi http://faculty.uoit.ca/qureshi University of Ontario Institute of Technology C++ struct struct keyword can be used to define new data types

More information

Lecture 5 Files and Streams

Lecture 5 Files and Streams Lecture 5 Files and Streams Introduction C programs can store results & information permanently on disk using file handling functions These functions let you write either text or binary data to a file,

More information

Assignment 2 Solution

Assignment 2 Solution Assignment 2 Solution Date.h #ifndef DATE_H #define DATE_H #include class Date time_t date; public: Date(); Date(const Date&) = default; Date(time_t); // Date in time_t format Date(const char*);

More information

377 Student Guide to C++

377 Student Guide to C++ 377 Student Guide to C++ c Mark Corner, edited by Emery Berger January 23, 2006 1 Introduction C++ is an object-oriented language and is one of the most frequently used languages for development due to

More information

Spring 2008 Data Structures (CS301) LAB

Spring 2008 Data Structures (CS301) LAB Spring 2008 Data Structures (CS301) LAB Objectives The objectives of this LAB are, o Enabling students to implement Singly Linked List practically using c++ and adding more functionality in it. o Enabling

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

EECS402 Lecture 08. Intro To The Standard string Class. Some string Functionality

EECS402 Lecture 08. Intro To The Standard string Class. Some string Functionality The University Of Michigan Lecture 08 Andrew M. Morgan Savitch Ch. 9.0 C++ String Data Type C-Strings Intro To The Standard string Class C++ has a standard class called "string" Strings are simply a sequence

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

Structured Data. CIS 15 : Spring 2007

Structured Data. CIS 15 : Spring 2007 Structured Data CIS 15 : Spring 2007 Functionalia HW4 Part A due this SUNDAY April 1st: 11:59pm Reminder: I do NOT accept LATE HOMEWORK. Today: Dynamic Memory Allocation Allocating Arrays Returning Pointers

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

Homework 5. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

Homework 5. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine Homework 5 Yuji Shimojo CMSC 330 Instructor: Prof. Reginald Y. Haseltine July 13, 2013 Question 1 Consider the following Java definition of a mutable string class. class MutableString private char[] chars

More information

Implementing an ADT with a Class

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

1. Which of the following best describes the situation after Line 1 has been executed?

1. Which of the following best describes the situation after Line 1 has been executed? Instructions: Submit your answers to these questions to the Curator as OQ3 by the posted due date and time. No late submissions will be accepted. For the next three questions, consider the following short

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

CMPS 221 Sample Final

CMPS 221 Sample Final Name: 1 CMPS 221 Sample Final 1. What is the purpose of having the parameter const int a[] as opposed to int a[] in a function declaration and definition? 2. What is the difference between cin.getline(str,

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

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

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program: Welcome Back CSCI 262 Data Structures 2 - Review What you learned in CSCI 261 (or equivalent): Variables Types Arrays Expressions Conditionals Branches & Loops Functions Recursion Classes & Objects Streams

More information

Program Organization and Comments

Program Organization and Comments C / C++ PROGRAMMING Program Organization and Comments Copyright 2013 Dan McElroy Programming Organization The layout of a program should be fairly straight forward and simple. Although it may just look

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

Programming Language. Functions. Eng. Anis Nazer First Semester

Programming Language. Functions. Eng. Anis Nazer First Semester Programming Language Functions Eng. Anis Nazer First Semester 2016-2017 Definitions Function : a set of statements that are written once, and can be executed upon request Functions are separate entities

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

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

Introduction to C ++

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

More information

More on Func*ons Command Line Arguments CS 16: Solving Problems with Computers I Lecture #8

More on Func*ons Command Line Arguments CS 16: Solving Problems with Computers I Lecture #8 More on Func*ons Command Line Arguments CS 16: Solving Problems with Computers I Lecture #8 Ziad Matni Dept. of Computer Science, UCSB Announcements Homework #7 due today Lab #4 is due on Monday at 8:00

More information

Consider the following example where a base class has been derived by other two classes:

Consider the following example where a base class has been derived by other two classes: Class : BCA 3rd Semester Course Code: BCA-S3-03 Course Title: Object Oriented Programming Concepts in C++ Unit IV Polymorphism The word polymorphism means having many forms. Typically, polymorphism occurs

More information

Piyush Kumar. input data. both cout and cin are data objects and are defined as classes ( type istream ) class

Piyush Kumar. input data. both cout and cin are data objects and are defined as classes ( type istream ) class C++ IO C++ IO All I/O is in essence, done one character at a time For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Concept: I/O operations act on streams

More information

Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6

Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6 Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6 Ziad Matni Dept. of Computer Science, UCSB A reminder about Labs Announcements Please make sure you READ

More information

Memory Allocation in C

Memory Allocation in C Memory Allocation in C When a C program is loaded into memory, it is organized into three areas of memory, called segments: the text segment, stack segment and heap segment. The text segment (also called

More information

Memory and Pointers written by Cathy Saxton

Memory and Pointers written by Cathy Saxton Memory and Pointers written by Cathy Saxton Basic Memory Layout When a program is running, there are three main chunks of memory that it is using: A program code area where the program itself is loaded.

More information

The University of Nottingham

The University of Nottingham The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, AUTUMN SEMESTER 2008 2009 C/C++ for Java Programmers Time allowed TWO hours Candidates may complete the front cover of their answer

More information

PRINCIPLES OF OPERATING SYSTEMS

PRINCIPLES OF OPERATING SYSTEMS PRINCIPLES OF OPERATING SYSTEMS Tutorial-1&2: C Review CPSC 457, Spring 2015 May 20-21, 2015 Department of Computer Science, University of Calgary Connecting to your VM Open a terminal (in your linux machine)

More information

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

Introduction to Algorithms and Data Structures. Lecture 6 - Stringing Along - Character and String Manipulation Introduction to Algorithms and Data Structures Lecture 6 - Stringing Along - Character and String Manipulation What are Strings? Character data is stored as a numeric code that represents that particular

More information

CS201- Introduction to Programming Current Quizzes

CS201- Introduction to Programming Current Quizzes CS201- Introduction to Programming Current Quizzes Q.1 char name [] = Hello World ; In the above statement, a memory of characters will be allocated 13 11 12 (Ans) Q.2 A function is a block of statements

More information

Programming II with C++ (CSNB244) Lab 10. Topics: Files and Stream

Programming II with C++ (CSNB244) Lab 10. Topics: Files and Stream Topics: Files and Stream In this lab session, you will learn very basic and most common I/O operations required for C++ programming. The second part of this tutorial will teach you how to read and write

More information

LAB 4.1 Relational Operators and the if Statement

LAB 4.1 Relational Operators and the if Statement LAB 4.1 Relational Operators and the if Statement // This program tests whether or not an initialized value of num2 // is equal to a value of num1 input by the user. int main( ) int num1, // num1 is not

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

(6) The specification of a name with its type in a program. (7) Some memory that holds a value of a given type.

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

CSE 333 Final Exam June 6, 2017 Sample Solution

CSE 333 Final Exam June 6, 2017 Sample Solution Question 1. (24 points) Some C and POSIX I/O programming. Given an int file descriptor returned by open(), write a C function ReadFile that reads the entire file designated by that file descriptor and

More information

C++ Programming Classes. Michael Griffiths Corporate Information and Computing Services The University of Sheffield

C++ Programming Classes. Michael Griffiths Corporate Information and Computing Services The University of Sheffield C++ Programming Classes Michael Griffiths Corporate Information and Computing Services The University of Sheffield Email m.griffiths@sheffield.ac.uk Presentation Outline Differences between C and C++ Object

More information

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

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

Lab 8. Follow along with your TA as they demo GDB. Make sure you understand all of the commands, how and when to use them.

Lab 8. Follow along with your TA as they demo GDB. Make sure you understand all of the commands, how and when to use them. Lab 8 Each lab will begin with a recap of last lab and a brief demonstration by the TAs for the core concepts examined in this lab. As such, this document will not serve to tell you everything the TAs

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

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee. Midterm Exam Nov 8th, 2012 COMS W3157 Advanced Programming Columbia University Fall 2012 Instructor: Jae Woo Lee About this exam: - There are 4 problems totaling 100 points: problem 1: 30 points problem

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

BITG 1113: Array (Part 2) LECTURE 9

BITG 1113: Array (Part 2) LECTURE 9 BITG 1113: Array (Part 2) LECTURE 9 1 LEARNING OUTCOMES At the end of this lecture, you should be able to: 1. Describe the fundamentals of C-strings (character arrays) 2. Use C-string functions 3. Use

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