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

Similar documents
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

Strings and Stream I/O

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

The Hong Kong Polytechnic University Faculty of Engineering

Writing a Good Program. 7. Stream I/O

Pointers, Dynamic Data, and Reference Types

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

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

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

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

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

Lecture 2, September 4

CS2255 HOMEWORK #1 Fall 2012

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

2 2

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

Chapter 2. Procedural Programming

Come and join us at WebLyceum

A SHORT COURSE ON C++

Chapte t r r 9

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

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

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

6.096 Introduction to C++ January (IAP) 2009

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

C++_ MARKS 40 MIN

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

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

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

Linked List using a Sentinel

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

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

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

a data type is Types

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

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

Introduction to C ++

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

CSCE 206: Structured Programming in C++

Exercise 1.1 Hello world

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

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

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:

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

Summary of basic C++-commands

File handling Basics. Lecture 7

Unit-V File operations

CS 376b Computer Vision

Object-Oriented Programming in C++

Unified Modeling Language a case study

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

Exam 3 Chapters 7 & 9

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

Lecture 5 Files and Streams

Assignment 2 Solution

377 Student Guide to C++

Spring 2008 Data Structures (CS301) LAB

Scientific Computing

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

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

Structured Data. CIS 15 : Spring 2007

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

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

Implementing an ADT with a Class

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

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

CMPS 221 Sample Final

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

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:

Program Organization and Comments

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

Programming Language. Functions. Eng. Anis Nazer First Semester

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

CS201 Latest Solved MCQs

Introduction to C ++

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

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

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

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

Memory Allocation in C

Memory and Pointers written by Cathy Saxton

The University of Nottingham

PRINCIPLES OF OPERATING SYSTEMS

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

Simple C++ Program. #include <iostream> using namespace std; int main() { //Note cout << Hello World << endl; return 0;

CS201- Introduction to Programming Current Quizzes

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

LAB 4.1 Relational Operators and the if Statement

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

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

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.

CSE 333 Final Exam June 6, 2017 Sample Solution

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

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

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.

A First Program - Greeting.cpp

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

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

BITG 1113: Array (Part 2) LECTURE 9

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

Transcription:

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 13-36 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

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++ 2008, 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()%20 + 50; 2

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

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

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

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 << "1234567890"; test1file.seekp(4); test1file << "test"; cout << test1file.tellp(); test1file.close(); 6

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) 1234567890test 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 << "1234567890"; 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

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 30 30. b) The size of the drawn rectangle is 50 50. 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 1 2 3 4 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

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

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