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

Similar documents
Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

Question 2. [5 points] Given the following symbolic constant definition

1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A.

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

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

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

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

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. Instructor: Final Exam Fall Section No.

Functions that Return a Value. Approximate completion time Pre-lab Reading Assignment 20 min. 92

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.

University of Michigan EECS 183: Elem. Programming Concepts Fall 2011 Exam 1: Part 1: Form 1. Professors: ML Dorf, Elliot Soloway

2 nd Week Lecture Notes

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

Object Oriented Design

WARM UP LESSONS BARE BASICS

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.

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

Name Section: M/W or T/TH. True or False (14 Points)

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

BITG 1233: Introduction to C++

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

True or False (12 Points)

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

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

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

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

Lecture 4. 1 Statements: 2 Getting Started with C++: LESSON FOUR

CS242 COMPUTER PROGRAMMING

Integer Data Types. Data Type. Data Types. int, short int, long int

Ch 6. Functions. Example: function calls function

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

LECTURE 02 INTRODUCTION TO C++

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

CMSC 202 Midterm Exam 1 Fall 2015

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

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

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

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

A First Program - Greeting.cpp

Laboratory 7. Programming Workshop 2 (CSCI 1061U) Faisal Qureshi.

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

CSCI 102L - Data Structures Midterm Exam #1 Fall 2011

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

Computer Programming : C++

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Chapter 4: Subprograms Functions for Problem Solving. Mr. Dave Clausen La Cañada High School

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

True or False (15 Points)

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

VARIABLES & ASSIGNMENTS

Honors Computer Science C++ Mr. Clausen Program 3A, 3B, 3C

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

ECE 461 Fall 2011, Final Exam

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

Introduction to C++ 2. A Simple C++ Program. A C++ program consists of: a set of data & function definitions, and the main function (or driver)

Outline. Review of Last Week II. Review of Last Week. Computer Memory. Review Variables and Memory. February 7, Data Types

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):

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

Increment and the While. Class 15

EECS 183, Week 5. General. Variables I/O. 0. At which location do you have to take the exam? 1. Source code vs. object code? 2. What s a library?

Review for COSC 120 8/31/2017. Review for COSC 120 Computer Systems. Review for COSC 120 Computer Structure

CHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING. Dr. Shady Yehia Elmashad

This test is OPEN Textbook and CLOSED notes. The use of computing and/or communicating devices is NOT permitted.

Starting Out with C++: Early Objects, 9 th ed. (Gaddis, Walters & Muganda) Chapter 2 Introduction to C++ Chapter 2 Test 1 Key

Introduction to Programming EC-105. Lecture 2

CMPS 221 Sample Final

3.1. Chapter 3: The cin Object. Expressions and Interactivity

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

Definition Matching (10 Points)

ECE 462 Fall 2011, Third Exam

CSC 222: Computer Programming II. Spring 2004

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

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

Programming. C++ Basics

Chapter Four: Loops II

Computing and Statistical Data Analysis Lecture 3

Basic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces

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

CSCE Practice Midterm. Data Types

C++ basics Getting started with, and Data Types.

CS16 Midterm Exam 2 E02, 10W, Phill Conrad, UC Santa Barbara Tuesday, 03/02/2010

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

Introduction to the C++ Programming Language

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

Module 7 b. -Namespaces -Exceptions handling

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

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

Pre- Defined Func-ons in C++ Review for Midterm #1

Chapter Four: Loops. Slides by Evan Gallagher. C++ for Everyone by Cay Horstmann Copyright 2012 by John Wiley & Sons. All rights reserved

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

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

16.216: ECE Application Programming Fall 2011

Chapter 1 INTRODUCTION

Objectives. In this chapter, you will:

Chapter 6: User-Defined Functions. Objectives (cont d.) Objectives. Introduction. Predefined Functions 12/2/2016

Homework Assignment #1

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

Transcription:

Exam #2 CISC1110, MW 10:35-12:40pm Fall 2011 Name 1 Evaluate each expression according to C++ rules (8 pts) Given: Integers a = 3, b = 2, c = 5, and float d = 40 a a * c - 10 = b a % b + (a * d) + 7 = c b / 4 + (a - c) = d b / (a + c) * d = 2 Convert to Base 10 (decimal) (4 pt) a 10101001 (Binary) b DE (Hex) 3 Use the segment of code below to answer the questions (8 pts) float cube(float x) { return pow(x, 3); a What is the name of the function? b How many parameters does it take? c Does the function return a value? If yes then what type of value? d Write an example statement using the function to cube the number 4

Use the code below to answer Question #4 void funcret1(int); void funcret2(int, int); void funcret3(); int radius, height, one; int main() { int one, two, three, b; string lastname; return 0; double quantity; void funcret1(int num1) { double accountnumber; int limit = 10; void funcret2(int x, int y) { string firstname; static int count = 1; while (count < limit) { int die1; char roll; string firststring; void funcret3() { int a;

4 Fill in the scope (accessibility) of each identifier in the table below (15 pts) Identifier Accessible In main() Accessible In funcret1(int) Accessible In funcret2(int, int) Accessible In funcret3() radius Y Y Y Y height one two b firstname lastname num1 accountnumber x y roll count limit die1 a firststring 5 Write the header and body for the following function (10 pts) // Parameters: start and end time in military format, ie 14:30 is 2:30pm // Returns: the number of minutes that has elapsed from the start to the // end time in hours and minutes // For example minutes(13, 20, 14, 45) would return 1 hour 25 minutes void minutes(int hr1, int min1, int hr2, int min2, int& hours, int& minutes)

6 Show exactly what will be printed out by the following program (15 pts) #include <iostream> using namespace std; void foo(int, int, char); void bar(int&, int, char&); int baz(int&); int main() { int x = 1, y = 7; char c = 'C'; cout << "1: x " << x << ", y " << y << ", c " << c << ", d "; cout << baz(++x) << endl; foo(x, y, c); cout << "2: x " << x << ", y " << y << ", c " << c << ", d "; cout << baz(x++) << endl; bar(x, y, c); cout << "3: x " << x << ", y " << y << ", c " << c << endl; return 0; // end of main void foo(int a, int b, char c) { a *= 3; b = a * 2; c = 'B' + a; cout << "foo: a " << a << ", b " << b << ", c " << c << endl; void bar(int& x, int y, char& z) { x++; y = y % 2; z = 'G'; cout << "bar: x " << x << ", y " << y << ", z " << z << endl; int baz(int a&) { return a + 5;

7 Write the definition for each function (include the header) Name all function foo (20 pts) a Write the definition of a function that takes as input a decimal number and returns the decimal portion of the number only For example, given 3278, the function would return 078 b Write the definition of a void function that takes as input two decimal numbers If the first number is not zero, it outputs the second number divided by the first number; otherwise, it outputs a message indicating that the second number cannot be divided by the first number because the first number is 0 c Write the definition of a boolean function with two parameters of type int The function should return true if the first integer is divisible by the second integer d Write the definition of a void function that takes as input two parameters of type int, for example sum and x The function updates the value of sum by adding the value of x to sum Use a reference variable to pass the value of sum to the calling function

8 Write a complete C++ program to do following (20 pts) The following formula gives the distance between two points, (x1, y1) and (x2, y2) in the Cartesian plane: Given the center and a point on the circle, you can use this formula to find the radius of the circle Write a program that prompts the user to enter the center and a point on the circle The program should then output the circle's radius, diameter, circumference and area Your program must have and utilize the following functions: // Parameters: 4 integers representing 2 points (x1, y1) (x2, y2) // Returns: distance between two points float distance(int x1, int y1, int x2, int y2); // Parameters: 4 integers representing 2 points (x1, y1) (x2, y2) // Returns: calls the distance function and returns the radius of the // circle float radius(int x1, int y1, int x2, int y2); // Parameters: 1 float, the radius of a circle // Returns: Circumference of a circle float circumference(float radius); // Parameters: 1 float, the radius of a circle // Returns: Area of a circle float area(float radius); Assume pi = 314