CSCI 111 Midterm 2 Exam Spring Solutions 09.00am 09.50am, Wednesday, May 04, 2016

Similar documents
CSCI 111 Second Midterm Exam Spring Solutions 09.00am 09.50am, Wednesday, May 10, 2017

Problem 1 Write the best title lines for the functions that are called by the following main program. Do not supply the blocks for the functions.

CSCI 111 First Midterm Exam Spring Solutions 09.05am 09.55am, Wednesday, March 14, 2018

Problem 1 Write the best title lines for the functions that are called by the following main program. Do not supply blocks for the functions.

Problem 1 Write the best title lines for the functions that are called by the following main program. Do not supply blocks for the functions.

CSCI 111 Midterm 1, version A Exam Fall Solutions 09.00am 09.50am, Tuesday, November 24, 2015

CSCI 111 First Midterm Exam Fall Solutions 09.00am 09.50am, Wednesday, October 18, 2017

CSCI 111 Midterm 1, version A Exam Fall Solutions 09.00am 09.50am, Tuesday, October 13, 2015

CSCI 111 Second Midterm Exam Fall Solutions 09.00am 09.50am, Wednesday, November 29, 2017

CSCI 111 Second Midterm Exam Spring Solutions 09.05am 09.55am, Monday, May 07, 2018

Problem 1 Write the best title lines for the functions that are called by the following main program. Do not supply blocks for the functions.

CSCI 111 Midterm 1 Exam Spring Solutions 09.00am 09.50am, Monday, March 21, 2016

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

Problem 1 Write the best title lines for the functions that are called by the following main program. Do not supply blocks for the functions.

Problem 1 Write the best title lines for the functions that are called by the following main program. Do not supply blocks for the functions.

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

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

More Examples Using Functions and Command-Line Arguments in C++ CS 16: Solving Problems with Computers I Lecture #6

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

VARIABLES & ASSIGNMENTS

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

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

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

CMPS 221 Sample Final

CSCE Practice Midterm. Data Types

Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A

Global & Local Identifiers

The American University in Cairo Computer Science & Engineering Department CSCE Dr. KHALIL Exam II Spring 2010

CS 117 Programming II, Spring 2018 Dr. Ghriga. Midterm Exam Estimated Time: 2 hours. March 21, DUE DATE: March 28, 2018 at 12:00 PM

Declaring a 2D Array

True or False (15 Points)

CMSC 202 Midterm Exam 1 Fall 2015

Ch 6. Functions. Example: function calls function

Review Problems for Final Exam. 1. What is the output of the following program? #include <iostream> #include <string> using namespace std;

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.

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

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

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

CS32 Midterm Exam E01, F15, Phill Conrad, UC Santa Barbara Wednesday, 10/28/2015, 11am 12:15pm

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

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

Problem 2 Write the best title lines for the functions that are called by the following main program. Do not

Exam 1. CSI 201: Computer Science 1 Fall 2018 Professors: Shaun Ramsey

Lecture 23: Pointer Arithmetic

UEE1302(1066) F12: Introduction to Computers and Programming Function (II) - Parameter

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

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

Apllications. March 03, Indian Institute of Space Science and Technology. MA122 - Computer Programming and. Apllications.

Increment and the While. Class 15

Call-by-Type Functions in C++ Command-Line Arguments in C++ CS 16: Solving Problems with Computers I Lecture #5

CSCE 206: Structured Programming in C++

Practice test for midterm 1

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

COMP 11 Class 17 Outline

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

Announcements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

Midterm Exam #2 Spring (1:00-3:00pm, Friday, March 15)

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

Week 4 EECS 183 MAXIM ALEKSA. maximal.io

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

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

CHAPTER 3 BASIC INSTRUCTION OF C++

Functions. CS111 Lab Queens College, CUNY Instructor: Kent Chin

CSCE Practice Midterm. Data Types

Programming Language. Functions. Eng. Anis Nazer First Semester

CS 31 Discussion 1A, Week 4. Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50 a.m.

CSC 309/404 Section 901/910 Spring 2017 Midterm Exam Due: May 7 (Sun) 2015, 11:59 pm

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

C C C C++ 2 ( ) C C++ 4 C C

CS 225. August 31 Memory. Data Structures. Wade Fagen-Ulmschneider

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

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

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

CS 115 Midterm 2A Solutions

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

CS31 Discussion 1E. Jie(Jay) Wang Week1 Sept. 30

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

Perfect square. #include<iostream> using namespace std; int main(){ int a=1; int square; while(true){ } cout<<square<<endl; }

Philadelphia University Faculty of Engineering Department of Computer Engineering Programming Language (630263)

Al Imam Mohammad Ibn Saud Islamic University College of Computer and Information Sciences Computer Science Department

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement

Student Name and ID CS 32, WINTER 2015, PRACTICE MIDTERM I.

CPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points)

CSCE121: Introduction to Program Design and Concepts Practice Questions for Midterm 1

True or False (12 Points)

Here, type declares the base type of the array, which is the type of each element in the array size defines how many elements the array will hold

Sonoma State University Computer Science Department CS 115 Fall 2010 Watts. Project 3 Part 1

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science. Instructor: Final Exam Fall 2011

Name. CPTR246 Spring '17 (100 total points) Exam 2

Introduction to Programming

Linked List using a Sentinel

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS242 ARRAYS

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

In this chapter you will learn:

COSC 320 Exam 2 Key Spring Part 1: Hash Functions

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. The Increment and Decrement Operators

C++ Scope Resolution Operator ::

A First Program - Greeting.cpp

Fundamentals of Programming CS-110. Lecture 2

Transcription:

QUEENS COLLEGE Department of Computer Science CSCI 111 Midterm 2 Exam Spring 2016 05.04.16 Solutions 09.00am 09.50am, Wednesday, May 04, 2016 Problem 1 ( points) Write the best title lines for the functions that are called by the following main program. Do not supply blocks for the functions. double x = 0.0, y = 1.1, z = 2.5; int array[5] = {3,1,4,1,5; string s = "Hello"; z = average(x, y, z); // (a) sets z to average 1.2 addstar(s); // (b) replaces s by "Hello*" cout << bigger(average(x,y,z), 7.5); // (c) prints 7.5 because it is bigger printarray(array, 5); // (d) prints array: 3 1 4 1 5 subtract(array[0], array, 5); // (e) subtracts array[0] from other elements printarray(array, 5); // output will now be 0-2 1-2 2 (a) Title line for average. double average(double a, double b, double c) (b) Title line for addstar. void addstar(string &x) (c) Title line for bigger. double bigger(double a, double b) (d) Title line for printarray. void printarray(int a[], int cap) (e) Title line for subtract. void subtract(int x, int y[], int cap)

Problem 2 ( points) Consider the following C++ program. #include <iostream> using namespace std; int fun(int x, int &y) { if (x < 0) y = -x; if (x <= 0) return x % 10 + 2 * fun(x/100, y); int c, x = 1, y = 5; if ((x % y) > (y % x)) cout << x; for(c = x; c < y; c++) cout << c; cout << fun(-2, y) << endl; cout << y << endl; cout << fun(31459, y) << endl; // line (a) // line (b) // line (c) // line (d) // line (e) (a) What is the output at line (a)? 1 (b) What is the output at line (b)? 1234 (c) What is the output at line (c)? 0 (d) What is the output at line (d)? 2 (e) What is the output at line (e)? 29

Problem 3 ( points) Write a function called subtractfirst that subtracts the value of the first element from every element in an array. For example, a program that uses the function subtractfirst follows. int array[6] = {3,1,4,1,5,9; subtractfirst(array, 6); for (int i = 0; i < 6; i++) cout << array[i] << " "; // Output will be 0-2 1-2 2 6 void subtractfirst(int array[], int c) { for (int i = c - 1; i >= 0; i--) array[i] -= array[0];

Problem 4 ( points) Write a function called cutafter7 that cuts a positive integer parameter after the first digit 7 that it contains. Parameters that are not positive should be returned without any change. For example, a program that uses the function cutafter7 follows. cout << cutafter7(765) << endl; // prints 7 cout << cutafter7(765765) << endl; // prints 7 cout << cutafter7(666) << endl; // prints 666 cout << cutafter7(107) << endl; // prints 107 cout << cutafter7(107007) << endl; // prints 107 int cutafter7(int x) { if (x <= 0) return x; int y = cutafter7(x/10); if ((y % 10) == 7) return y; return x;

QUEENS COLLEGE Department of Computer Science CSCI 111 Midterm 2 Exam Spring 2016 05.04.16 Solutions 02.45pm 03.35pm, Wednesday, May 04, 2016 Problem 1 ( points) Write the best title lines for the functions that are called by the following main program. Do not supply blocks for the functions. double z = 2.5; int array[5] = {3,1,4,1,5; string s = "Hello"; z = average(array, 5); // (a) sets z to average 2.8 addtwice(s,"**"); // (b) replaces s by "Hello**Hello**" cout << sum(average(array, 5), 1.2); // (c) 4.0 the sum of 1.2 and the average cout << somearray(array, 3); // (d) prints 3 elements: 3 1 4 count(array[1], array, 5); // (e) print count of copies of array[1] in array (a) Title line for average. double average(int a[], int cap) (b) Title line for addtwice. void addtwice(string &x, string y) (c) Title line for sum. double sum(double a, double b) (d) Title line for somearray. string somearray(int a[], int cap) (e) Title line for count. void count(int x, int y[], int cap)

Problem 2 ( points) Consider the following C++ program. #include <iostream> using namespace std; int xy(int x, string &y) { if (x < 0) y = "error"; else y = "ok"; if (x <= 0) return 5; return x % 10 + 10 * xy(x/100, y); int c = 4, x = 1; string y; if ((x % c) == (c % x)) cout << c; for(c = 5; c > x; c--) cout << c; cout << xy(-2, y) << endl; cout << y << endl; cout << xy(31459, y) << endl; // line (a) // line (b) // line (c) // line (d) // line (e) (a) What is the output at line (a)? (b) What is the output at line (b)? 5432 (c) What is the output at line (c)? 5 (d) What is the output at line (d)? error (e) What is the output at line (e)? 5349

Problem 3 ( points) Write a function called subtractaverage that subtracts the average value of an array from every element in an array. For example, a program that uses the function subtractaverage follows. double array[6] = {3,1,4,1,5; // has average 2.8 subtractaverage(array, 5); for (int i = 0; i < 5; i++) cout << array[i] << " "; // Output will be 0.2-1.8 1.2-1.8 2.2 void subtractaverage(double array[], int c) { double total = 0; for (int i = 0; i < c; i++) total += array[i]; double average = total / c; for (int i = 0; i < c; i++) array[i] -= average;

Problem 4 ( points) Write a function called cutbefore7 that cuts a positive integer parameter before the first digit 7 that it contains. Parameters that are not positive should be returned without any change. For example, a program that uses the function cutbefore7 follows. cout << cutbefore7(667) << endl; // prints 66 cout << cutbefore7(677) << endl; // prints 6 cout << cutbefore7(666) << endl; // prints 666 cout << cutbefore7(766) << endl; // prints 0 cout << cutbefore7(567567) << endl; // prints 56 int cutbefore7(int x) { if (x <= 0) return x; int y = cutbefore7(x/10); if ((x % 10) == 7 (y < x/10)) return y; return x;