CS 201 (Intro. to Computing) Fall 2015 Sabancı University Sample Questions for Midterm 1

Similar documents
CS 201 (Intro. to Computing) Fall 2015 Sabancı University - Sample Questions and Solutions for Midterm 1

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

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

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.

CSCE Practice Midterm. Data Types

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

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

Computer Engineering Department CMPE110 Midterm Sample Questions, 2017/ Fall

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

CSci 1113 Midterm 1. Name: Student ID:

Why Is Repetition Needed?

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

Chapter 1 INTRODUCTION

CSCE Practice Midterm. Data Types

VARIABLES & ASSIGNMENTS

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

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

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

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

Getting started with C++ (Part 2)

WARM UP LESSONS BARE BASICS

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

CMSC 202 Midterm Exam 1 Fall 2015

Computer Programming : C++

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

CS242 COMPUTER PROGRAMMING

REVIEW. The C++ Programming Language. CS 151 Review #2

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

PIC 10A. Review for Midterm I

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

BEng (Hons) Electronic Engineering. Resit Examinations for / Semester 1

CSc Introduction to Computing

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

do { statements } while (condition);

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

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

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

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

LAB 4.1 Relational Operators and the if Statement

REPETITION CONTROL STRUCTURE LOGO

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

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:

Chapter 2: Basic Elements of C++

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

int n = 10; int sum = 10; while (n > 1) { sum = sum + n; n--; } cout << "The sum of the integers 1 to 10 is " << sum << endl;

CS1004: Intro to CS in Java, Spring 2005

CSC 126 FINAL EXAMINATION FINAL Spring 2012 B. Name (last, First) Instructor. Total Possible. Received

CS150 Intro to CS I. Fall Fall 2017 CS150 - Intro to CS I 1

C++ Programming: From Problem Analysis to Program Design, Third Edition

Homework #3 CS2255 Fall 2012

Score score < score < score < 65 Score < 50

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

Today in CS161. Week #3. Learn about. Writing our First Program. See example demo programs. Data types (char, int, float) Input and Output (cin, cout)

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

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

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

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

Security Coding Module - Buffer Overflow Data Gone Wild CS1

Review of Important Topics in CS1600. Functions Arrays C-strings

Chapter 01 Arrays Prepared By: Dr. Murad Magableh 2013

Class 2: Variables and Memory. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

Number: Name-Surname :... Group:...

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

Objectives. In this chapter, you will:

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

Lecture 3 Tao Wang 1

Chapter 3 Problem Solving and the Computer

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

Exception with arguments

Reviewing all Topics this term

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

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

Chapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++

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

ENJOY! Problem 2 What does the following code do, in a brief English sentence? int mystery(int k) { int i = 0; if (k < 0) return -1;

Programming Language. Functions. Eng. Anis Nazer First Semester

1. a) What #include statement do you put at the top of a program that does uses cin, cout or endl?

CSci 1113 Final. Name: Student ID:

Local and Global Variables

Reading from and Writing to Files. Files (3.12) Steps to Using Files. Section 3.12 & 13.1 & Data stored in variables is temporary

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

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

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.6

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

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

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

Lab # 02. Basic Elements of C++ _ Part1

pointers + memory double x; string a; int x; main overhead int y; main overhead

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

CS101 PLEDGED SPRING 2001

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

A Freshman C++ Programming Course

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

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

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

CS1500 Algorithms and Data Structures for Engineering, FALL Virgil Pavlu, Jose Annunziato,

Week 2: Console I/O and Operators Arithmetic Operators. Integer Division. Arithmetic Operators. Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.

Today in CS161. Lecture #7. Learn about. Rewrite our First Program. Create new Graphics Demos. If and else statements. Using if and else statements

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

Transcription:

CS 201 (Intro. to Computing) Fall 2015 Sabancı University Sample Questions for Midterm 1 Those questions do not imply any favorite subject or question type for the questions in the actual exam Please also review recitation questions, samples covered in the class, homeworks and the questions in the book as well The amount of questions here is of course much more than the actual exam. QUESTIONS 1) Write a function that takes an integer type of parameter and returns its reciprocal. If the parameter is zero, then the function should return 0. In the main program, first input two integer values. Then find the sum of the reciprocals of all of the numbers between these two inputs. In the main program, you have to use the reciprocal function. 2) Write a function that takes three string values as parameters and displays them in lexicographical order.

3) a) Rewrite the following expression using C++ syntax. a c b c b sin c a a 3 b) What are the results of the following expressions? 5+3/5+72*!(2+5)==12%8*-10 (20*1.5/(2*6-8)-7)*11 c) The range of short unsigned integer is [0.. 65535]. Why is the upper limit is 65535? d) Write the statement to display the sum of the digits of a two-digit integer number (call it num). e) We do not include anything to use int, but we need to include string header file to use string. Why is that? f) Suppose you are writing a program to convert days into seconds. Assuming you are doing integer arithmetic using unsigned long integers for this purpose, what should be the maximum value of days to avoid any overflow problems? g) Rewrite using for statement instead of while while(year<=4002) sum+=year; cout << year << endl; year+=sum;

4) Trace and display the output of the program using the data given below? #include <iostream> using namespace std; int main() int cnt, x, y, dif; cnt=0; cin>>x; do cin>>y; dif=y-x; if (dif > 1) while ( x+1 < y) ++x; cout<< Number= <<x<<endl; x = y; ++cnt; while (cnt!=3); return 0; Data input 12 15 16 20

5) What is the output of the following program? #include <iostream> using namespace std; int A(int i); float B(char c); void C(float x); int main() int p = 0; float q = 0.0; char r = 'D'; p = A(p); q = B(r); C(B(r)); p = A(A(p)); return 0; int A(int i) cout << "A" << endl; return i+1; float B(char c) cout << "B" << endl; return 7; void C(float x) cout << "C" << endl;

6) There are up to five (5) syntax errors of the following program. However, there might be less than five. Find those syntax errors and explain the nature of the error. Give the line numbers of the errors. If your syntax error is not actually a syntax error, that will reduce your grade! 1 #include <iostream> 2 using namespace std; 3 4 void desidero (int hulahop) 5 6 if (hulahop) 7 8 cout << 10; 9 10 11 12 int main() 13 14 cout << "Program is now started"; 15 int hokuspokus = 4.6, five; 16 double = hokuspokus/2.0; 17 18 cin >> hulahop >> five; 19 cin >> hokuspokus; 20 if (hokuspokus+72!= five) cout << "five is " 21 << five; 22 23 return 0; 24 25 26 void function1 27 28 cout <<3 + 5; 29 Syntax Errors: 1) Line: 2) Line: 3) Line: 4) Line: 5) Line:

7) XCELL telephone company is calculating the cost of a telephone conversation by multiplying the duration (in minutes) with the unit cost. The unit cost depends on the area code of the called telephone number. If the area code is between 200-299, then the unit cost per minute is 100 KTL, else if the area code is between 300 499, then the unit cost per minute is 150 KTL, else if the area code is between 500 599, then the unit cost per minute is 300 KTL. In a full program: Write a function that takes area code and duration as parameters and display the total cost of the conversation. Area code is assumed to be between 200 and 599 and the duration is assumed to be non-negative in this function (you will make input checks in the main). In main, input the area code and the duration. First check validity of the input (area code must be between [200.. 599], duration must be non-negative). If the inputs are valid, use the function to calculate the cost of conversation and display it on the screen, otherwise display an error message showing which input is invalid. 8) Write a function that takes a string parameter and copies it to another string by removing the uppercase letters in it. The copied string must be returned back from the function. 9) Write a program that inputs a numeric month value (between 1 and 12) and a year value. The program should calculate and display the month (again in numeric format) and year after 100 months. As a variation, instead of 100 use another input. In this way, any amount of months could be added. 10) Write a program that reads a sequence of integers from keyboard and checks whether that sequence is ordered or not; Sentinel value is 1, i.e., the input entry should finish when 1 is entered and this value should not be considered in the sequence. The program should display a message about the order of the input sequence too.

11) Write a function that takes a string (let s call it mystr) and an integer (let s call it myint) as parameters. The function should move last myint characters of mystr to the beginning and return the resulting string. For example, if mystr is Bu sinav ne kadar da kolay and myint is 11, then the returned string will be ar da kolaybu sinav ne kad If myint is larger than the length of mystr, then the function should return mystr unchanged. Remark: You can write this function with or without using loops. Do it in both ways just to practice. 12) Write a function that takes an integer parameter (say N) and displays the positive powers of 2 that are smaller than N. For example if N is 3000, then the function displays 1 2 4 8 16 32 64 128 256 512 1024 2048 13) Use only unsigned integers in this question. In a program Write a function that takes a volume value in cubic meters as parameter and displays its equivalent in cubic centimeters (one cubic meter = 1,000,000 cubic centimeters) In main, input the cubic meter information and call the above function to display this volume in cubic centimeters. Before calling the function, check the input so that the result should not overflow. To perform such a check, first you should calculate the maximum value for the cubic meters input and then enforce the input in that limit. 14) Write a program that reads a string from keyboard and displays the characters between the last two commas of that string. Do not display the commas. If the input string has only one comma, then display all the characters after it. If the string does not have any commas, then display the whole string. You can write this program with or without loops. Do it in both ways just to practice. 15) Write a function that takes three string parameters (let s call them s1, s2 and s3) and replaces all of the occurrences of s2 in s1 with s3. The function should return the resulting string. For example, if s1 is hatasiz sinav olmaz, hatamla sev beni, s2 is hata and s3 is kopya, then the function returns kopyasiz sinav olmaz, kopyamla sev beni.

16) Write a program that creates two robots at locations (0.0) and (0,1) respectively. Then set the color of the first robot to red and second one to yellow (you can t use other colors, otherwise you ll get zero from this question ). After that, the robots should move up to (10,10) and (10,11) in harmony. During this journey, the robots should (i) remain at most one cell apart, (ii) follow the diagonal as much as possible. That means, the robots should make a sequence of single steps of moving up and right. You may assume that there are no walls other than world boundaries, but, of course, the robots should not hit into each other. 17) In this program you will draw a triangle using robot class and its things. Read an input value to determine the bottom line length of the triangle. Start from (0,0), then draw triangle by putting only one thing on each cell. The example output is below, for the given number = 6. Of course, your program should work for any input value, not only for 6. Do not forget to deposit necessary amount of things into the robot s bag while creating it; if the robot s bag is empty, it cannot put a thing in a cell. 18) (This question is a bit long for being an exam question but do it just to practice) Write a program using robot class. In this program there is a robot which travels all around the robot world to find a bomb designated with a thing. The bomb can be anywhere, which is put by the user of the program using a mouse click. Once the bomb is found, your program should display a message and quit. The robot will sense the bomb when it is on the cell with the bomb. Robot will be created at (0,0). You can implement several search routines for the robot to find the bomb. However, your search algorithm should guarantee finding it. That means you should use an algorithm that eventually visits all the cells. Since the east and north sides of the robot world is unbounded, this is not an easy task. An algorithm is given below.

Assuming the robot is initially at 0,0 and facing east: k = 1 while (bomb is not found) Move 1 step and check Turn Left Move k steps and check at each step Turn Left Move k steps and check at each step Turn Right Move 1 step and check Turn Right Move k +1 steps and check at each step Turn Right Move k +1 steps and check at each step Turn Left k=k+2 19) Write a function, called findpvalue, to calculate and return the p(x,n,p) given below. x is a parameter of type double, n and p are parameters of type int. p( x, n, p) x* n i3 p ji x j 2 i 20) Write a program that reads a 200 integer numbers and counts the total number of positive numbers among them. 21) Write a program that reads a string from keyboard and displays the alphabetically largest uppercase letter in it. 22) We have seen a palindrome check function in class. Rewrite the palindrome check function, but this time without reversing the parameter string. Hint: in a loop, check the letter pairs that must be the same to be a palindrome. 23) Write a program in which first create a robot at 0,0 position facing east and empty bag. Then move the robot diagonally to (1,1), (2,2), (3,3)... Since there is no diagonal move function in Robot class, you have to move one step up and then one step right for a single diagonal move. While moving, the robot should pick everything only on the diagonal cells. The robot should stop on the cell in which the total number things picked starting from the beginning of the journey exceeds 100.