a) What is the major difference between a program that runs under a virtual machine vs. one that does not?

Similar documents
Midterm Exam #2 Solutions November 10, 1999 CS162 Operating Systems

Practice Questions. CS161 Computer Security, Fall 2008

Midterm Exam #2 November 10, 1999 CS162 Operating Systems

Computer Science 217

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage

18 Software. design. Learning outcomes. Credit value: 10

The FTS Interactive Trader lets you create program trading strategies, as follows:

The FTS Real Time System lets you create algorithmic trading strategies, as follows:

Why? A central concept in Computer Science. Algorithms are ubiquitous.

Lab 4.4 Secret Messages: Indexing, Arrays, and Iteration

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Visual Basic Programming. An Introduction

Introduction to Algorithms March 10, 2004 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser Quiz 1.

TRANSITION FROM TEACHING VB6 TO VB.NET

One Dimension Array: Declaring a fixed-array, if array-name is the name of an array

PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms

EKT150 Introduction to Computer Programming. Wk1-Introduction to Computer and Computer Program

ECON 103, ANSWERS TO HOME WORK ASSIGNMENTS

Chapter 12 Programming Concepts and Languages

Visual Basic distinguishes between a number of fundamental data types. Of these, the ones we will use most commonly are:

Arithmetic Coding: Introduction

Unit One: The Basics of Investing

Positional Numbering System

Management Information Systems 260 Web Programming Fall 2006 (CRN: 42459)

CSE 123: Computer Networks Fall Quarter, 2014 MIDTERM EXAM

VB.NET - WEB PROGRAMMING

HY345 Operating Systems

Computer Programming I

Hands-on Exercise 1: VBA Coding Basics

Udacity cs101: Building a Search Engine. Extracting a Link

Problem Solving Basics and Computer Programming

There are several ways of creating a PDF file using PDFCreator.

#include <Gamer.h> Gamer gamer; void setup() { gamer.begin(); } void loop() {

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

Lesson 8: Simon - Arrays

CSCI 1301: Introduction to Computing and Programming Summer 2015 Project 1: Credit Card Pay Off

Goals. Unary Numbers. Decimal Numbers. 3,148 is s 100 s 10 s 1 s. Number Bases 1/12/2009. COMP370 Intro to Computer Architecture 1

Course MS10975A Introduction to Programming. Length: 5 Days

1. Convert the following base 10 numbers into 8-bit 2 s complement notation 0, -1, -12

Programming the VEX Robot

ALLIED PAPER : DISCRETE MATHEMATICS (for B.Sc. Computer Technology & B.Sc. Multimedia and Web Technology)

Objectives. Python Programming: An Introduction to Computer Science. Lab 01. What we ll learn in this class

customer rewards Use this guide to create customized customer rewards and redeem points earned by customers.

Instructor Özgür ZEYDAN BEU Dept. of Enve. Eng. CIV 112 Computer Programming Lecture Notes (1)

Exemplar Work for SAMs. Units A452 and A453

Computer Science 281 Binary and Hexadecimal Review

Useful Number Systems

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Software development and programming. Software

Syllabus for CS 134 Java Programming

APPROACHES TO SOFTWARE TESTING PROGRAM VERIFICATION AND VALIDATION

CS/COE

7.1 Our Current Model

Writing Simple Programs

Wage Calculator Application

Programming and Software Development CTAG Alignments

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

Flowchart Techniques

Developing MapReduce Programs

SPHOL326: Designing a SharePoint 2013 Site. Hands-On Lab. Lab Manual

Chapter 1: Key Concepts of Programming and Software Engineering

NUMBER SYSTEMS. William Stallings

Chapter 2: Elements of Java

Using C# for Graphics and GUIs Handout #2

In following this handout, sketch appropriate graphs in the space provided.

Introduction to Python

Unit 1 Number Sense. In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions.

The Adwords Companion

CXQuotes Doors and Windows Quotation software. Cogitrix

Lumousoft Visual Programming Language and its IDE

TECHNOLOGY Computer Programming II Grade: 9-12 Standard 2: Technology and Society Interaction

Stop the Pop Display

Term Project: Roulette

CSI 333 Lecture 1 Number Systems

Euler Paths and Euler Circuits

CS177 MIDTERM 2 PRACTICE EXAM SOLUTION. Name: Student ID:

Encoding Text with a Small Alphabet

Visual Logic Instructions and Assignments

Product: DQ Order Manager Release Notes

Primes. Name Period Number Theory

GCE Computing. COMP3 Problem Solving, Programming, Operating Systems, Databases and Networking Report on the Examination.

C A R I B B E A N E X A M I N A T I O N S REPORT ON CANDIDATES S WORK IN THE CARIBBEAN SECONDARY EDUCATION CERTIFICATE EXAMINATION MAY/JUNE 2012

KENO TRAINING MANUAL

RTAP Database Lifecycle Management

First Bytes Programming Lab 2

Windows PowerShell Essentials

Drawing a histogram using Excel

The programming language C. sws1 1

Introduction to Programming System Design. CSCI 455x (4 Units)

CS Matters in Maryland CS Principles Course

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

Introduction to Java

BRAZOSPORT COLLEGE LAKE JACKSON, TEXAS SYLLABUS ITSE 1432 INTRODUCTION TO VISUAL BASIC.NET PROGRAMMING

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

VISUAL ALGEBRA FOR COLLEGE STUDENTS. Laurie J. Burton Western Oregon University

Demo: Controlling.NET Windows Forms from a Java Application. Version 7.3

Transcription:

CS109 Midterm Exam, Total = 100 Points Name: Please write neatly and show as much of your work as possible for partial credit. Scan through all problems first, and attack the easiest problems first. Use the last page or the back if you need more space. Good luck! 1. (15 pts) Short Answer. Provide brief (1-3 sentence) answers to the following: a) What is the major difference between a program that runs under a virtual machine vs. one that does not? b) Given a textbox control on your form named txtinfo, what line of code would make the textbox display the following? c) What happens when a program is compiled? d) What is the difference in the binary representation between the String 5 and the number 5 represented as an Integer? (You can be general, i.e. you don t have to specifically say exactly what bits differ) e) What does Option strict on force the programmer to do?

2. (6 pts) Arithmetic Operations Show the output of the following code fragment: Console.WriteLine(CInt(5 / 6)) Console.WriteLine(1 + 2 * 3 + 4) Console.WriteLine(10 Mod 3) 3. (9 pts) Bug Hunt All of the following code snippets have a bug. Identify each one and fix the bug. Assume the necessary code is in place to make a working program (e.g. the necessary TextBoxes exist, the code is within some event, etc.). a) The following code should print Big or Bigger Dim i As Integer i = CInt(InputBox("Enter an integer.")) If (0 < i < 10) Then Console.WriteLine("Big") ElseIf (10 <= i) Then Console.WriteLine("Bigger") End If b) The following should set n to the greater of two numbers entered in textboxes: Dim n As Integer If (TextBox1.Text < TextBox2.Text) Then n = TextBox2.Text Else n = TextBox1.Text End If c) The following should prompt the user to enter 1 or 2 and if the user enters anything else then re-display the prompt to enter 1 or 2 : Dim i As Integer Do i = CInt(InputBox("Enter 1 or 2")) Loop Until ((i = 1) And (i = 2))

4. (15 pts) Burning Calories One way to measure the amount of energy that is expended during exercise is to use metabolic equivalents (MET). Here are some METs for various activities: Running 6 MPH: 10 METs Sleeping: 1 MET The number of calories burned per minute may be estimated using the formula: Calories/Minute = 0.00795 METs Weight_In_Pounds Write code that goes into a button click that calculates the total calories burned given inputs of weight, minutes spent running 6 MPH, and minutes spent sleeping. Output the answer in a MessageBox. Here is the form, where the names of the textboxes are indicated by the text within them: Here is the event handler where you can fill in your code: Private Sub btncalculate_click( ) Handles btncalculate.click ' Write your code here

5. (20 pts) Loops and Drawing Your form has a PictureBox named PictureBox1 that occupies the entire form. Here is the code that is in the Paint event for the PictureBox: Private Sub PictureBox1_Paint(...) Handles PictureBox1.Paint Dim i As Integer Dim g As Graphics g = e.graphics i = 0 While (i < 150) g.drawrectangle(pens.black, i, i, 100, 50) i = i + 50 End While In the screen shot below, sketch out what will be drawn in the PictureBox when the program is executed.

6. (15 pts) Scoping Here is a program with two buttons: Here is the code: Public Class Form1 Inherits System.Windows.Forms.Form Dim var1 As Integer = 10 Private Sub Button1_Click(...) Handles Button1.Click Dim var2 As Integer Console.WriteLine("Var 1 = " & var1) Console.WriteLine("Var 2 = " & var2) var2 = var2 + 1 var1 = var1 + 10 Private Sub Button2_Click(...) Handles Button2.Click Dim var1 As Integer var1 = 5 Console.WriteLine("Var 1 = " & var1) var1 = var1 + 25 End Class Show what is output to the Console when the program is executed and the user clicks on Button1 twice and then Button2 twice: 1) Button1 clicked: Output: 2) Button1 clicked again: Output: 3) Button 2 clicked: Output: 4) Button 2 clicked again: Output:

7. (10 points) Algorithm Design Maximize Candy Intake Suppose we can buy a chocolate bar from the vending machine for $1 each. Inside every chocolate bar is a golden coupon. The machine allows us to redeem 6 coupons for one chocolate bar. We would like to know, if given n dollars, how many chocolate bars can be eaten? Also, how many coupons will we have leftover? For example, for 6 dollars, we can buy six chocolate bars from the machine and get 6 coupons. We can then redeem the coupon for one more chocolate bar. This means we can get a total of 7 chocolate bars with 1 coupon leftover. For 11 dollars, we could have consumed 13 chocolate bars and still have one coupon left. For 12 dollars, we could have consumed 14 chocolate bars and have two coupons left. Describe an algorithm that computes the number of chocolate bars we can eat and the number of coupons leftover if you start with n dollars. You do not have to write any actual code, just describe the algorithm in English or pseudocode. For up to 5 extra credit points (but max score on the exam < 100) write code that could go into a Button Click event that computes the number of candy bars we can eat and the number of leftover coupons.

8. (10 points) The Time Machine Complete the program described below so that it inputs time in AM/PM format (given hours, minutes, and AM/PM) and converts it to 24 hour military time. The form is laid out as follows, where the text indicates the names of the controls: Here is a sample run, where upon clicking the button, the program computes 1415: Complete the code in the button click event to make this program functional. You will find the following function useful: Format(number, "00") This function returns a string containing number with a leading zero if possible. For example: Format(2, "00") returns "02" Format(15, "00") returns "15" Make sure your program correctly handles times between 12 AM and 1 AM! Space for your solution is on the next page.

Fill in the code in the button click event for the time conversion program: Private Sub btnconvert_click( ) Handles btnconvert.click ' Write your code here

(this page intentionally left blank if you need extra space for your answer)