Test 1: CPS 08 Owen Astrachan February 17, 1995 Name: Honor code acknowledgement (signature) Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Extra T

Similar documents
PROBLEM 1 : (Vocabulary: 12 points) For each of the words/phrases below, circle the denition that is the best description as it pertains in the contex

Test 2: CPS Owen Astrachan. November 17, Name: Honor code acknowledgement (signature)

PROBLEM 1 : (Vocabulary: 8 points) For each of the words/phrases below, circle the denition that is the best description as it pertains in the context

"apple" "grape" "grape" "grape" "apple"

Programming Language. Functions. Eng. Anis Nazer First Semester

PROBLEM 1 : (Vocabulary: 8 points) For each of the words/phrases below, circle the denition that is the best description as it pertains in the context

Before calling Prepend(list,13) After calling Prepend(list,13) After calling RemoveLast(list)

Test 1: CPS 06 Owen Astrachan Susan Rodger October 2, 1995 Name: Honor code acknowledgement èsignatureè Problem 1 Problem 2 Problem 3 Problem 4 Proble

cameron grace derek cameron

Test 1: CPS 100. Owen Astrachan. February 23, 2000

Test 2: CPS 103 Owen Astrachan November 19, 1993 Name: Honor code acknowledgement (signature) Problem 1 value 9 pts. grade Problem 2 12 pts. Problem 3

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

PROBLEM 1 : (Trouble?: (14 pts)) Part A: (6 points) Consider the function Trouble below. int Trouble (const Vector<int> & numbers, int size) if (size

1) What of the following sets of values for A, B, C, and D would cause the string "one" to be printed?

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

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

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

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

Arrays in C++ Instructor: Andy Abreu

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

Test 1: CPS 100. Owen Astrachan. October 1, 2004

double d0, d1, d2, d3; double * dp = new double[4]; double da[4];

CSCE 206: Structured Programming in C++

class for simulating a die (object "rolled" to generate a random number) Dice(int sides) -- constructor, sides specifies number of "sides" for the die

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

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

PROBLEM 1 : (Short Answer: 13 points) Three points each, except for last two which are two points 1. Both bubble-sort and selection sort are O(n 2 ) s

Test 1: CPS 100. Owen Astrachan. October 11, 2000

Functions! Objectives! 1E3! Topic 9! programming! n This topic should allow students to! n Read chapter 6 of the textbook now.!

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

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:

CSE 333 Midterm Exam Cinco de Mayo, 2017 (May 5) Name UW ID#

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.

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

FORM 2 (Please put your name and form # on the scantron!!!!)

Computing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer

Outline. Functions. Functions. Predefined Functions. Example. Example. Predefined functions User-defined functions Actual parameters Formal parameters

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:

Programming. C++ Basics

LAB 4.1 Relational Operators and the if Statement

"sort A" "sort B" "sort C" time (seconds) # of elements

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

Program Organization and Comments

WARM UP LESSONS BARE BASICS

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

Test 2: CPS 100. Owen Astrachan. April 3, Name: Login: (1 pt)

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

Functions in C++ Problem-Solving Procedure With Modular Design C ++ Function Definition: a single

Assertions, pre/postconditions

This sheet must be the cover page for every programming assignment. Total

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

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

class Array; // Class template declaration class Array public: // T="type",e.g.,int or float Array(int n); // Create array of n elements Array(); // C

CS 115 Exam 3, Spring 2010

Separate Compilation of Multi-File Programs

Statements execute in sequence, one after the other, such as the following solution for a quadratic equation:

Circle all of the following which would make sense as the function prototype.

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions

C++ Final Exam 2017/2018

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

Notes on the 2015 Exam


BITG 1113: Function (Part 2) LECTURE 5

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking

int x = 5; double y = 3; // Integer division rounds the result down to the nearest whole number. cout << "1a: " << x / 3 << endl; //1

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

CS Semester I. Quiz 1 (version A)

PROBLEM 1 : (ghiiknnt abotu orsst (9 points)) 1. In the Anagram program at the beginning of the semester it was suggested that you use selection sort

Outline. Why do we write functions? Introduction to Functions. How do we write functions? Using Functions. Introduction to Functions March 21, 2006

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

EAS230: Programming for Engineers Lab 1 Fall 2004

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;

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

cout éé "two" éé endl; else if ènum é 10è cout éé "try" éé endl; else cout éé "fry" éé endl; cout éé "sly" éé endl; if ènum é 10è cout éé "one" éé end

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

CISC 1110 (CIS 1.5) Introduc2on to Programming Using C++

For Teacher's Use Only Q No Total Q No Q No

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

Part I: Short Answer (6 questions, 18 points total)

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

Suppose that the following is from a correct C++ program:

CIS 130 Exam #2 Review Suggestions

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

COMPUTER SCIENCE (083)

CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

Honors Computer Science C++ Mr. Clausen Program 4A, 4B, 4C, 4D, 4G

Computer Science II Lecture 1 Introduction and Background

Functions and Recursion

QUIZ Lesson 4. Exercise 4: Write an if statement that assigns the value of x to the variable y if x is in between 1 and 20, otherwise y is unchanged.

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

Honors Computer Science C++ Mr. Clausen Program 6A, 6B, 6C, & 6G

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

2. It is possible for a structure variable to be a member of another structure variable.

Introduction to Programming

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

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

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 03

CSCI 101L - Data Structures. Practice problems for Final Exam. Instructor: Prof Tejada

Transcription:

Test 1: CPS 08 Owen Astrachan February 17, 1995 Name: Honor code acknowledgement (signature) Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Extra TOTAL: value 8 pts. 12 pts. 10 pts. 10 pts. 12 pts. 6 pts. 52 pts. grade This test has 9 pages, be sure your test has them all. Do NOT spend too much time on one question remember that this class lasts 50 minutes. 1

PROBLEM 1 : (Vocabulary: 8 points) For each of the words/phrases below, circle the denition that is the best description as it pertains in the context of computer science, programming, and C/C++. 1. compiler (a) A program that compiles a textual list of all functions used in a program indexed by the line numbers on which the functions appear. (b) A program that translates a high-level language (e.g., C++) into a low-level language directly executable by a computer. (c) A program used to check the semantic content of a C++ program to determine if it will function as the programmer intends. 2. member function 3. ftp (a) A function that is part of a class, that can be applied to variables (objects) of the class, e.g., Length for the the class String. (b) A function that belongs to a library of functions, e.g., sin and sqrt as part of <math.h>. (c) A function whose prototype appears before the body of the function is actually dened. (a) A Unix command that's used to move from one directory to another. (b) A program used to set up an environment in Unix so that it works according to a user's preferences. (c) A program and protocol used to transfer les from one computing system to another. 4. reference parameter (a) A parameter that appears in a function header (or prototype) as opposed to in a function call. (b) A parameter that appears in a function call as opposed to a function header (or prototype). (c) A parameter that permits values to be \passed back" when a function is called. PROBLEM 2 : (Output: 12 points) Indicate the output of each of the cout statements below. Assume each statement is part of a program that compiles and runs. You can show your reasoning for partial credit. int count = 13; double value = 3.5; String word = "lease"; cout << count + 15/6 * 2 << endl; cout << (7.0 + 13)/8 << endl; cout << count + 13 % 2 * value << endl; cout << "p" + word << endl; cout << word[3] << endl; cout << 3.5*3.14159*2.718/0 << endl; 2

PROBLEM 3 : (A Capital Idea: 10 points) A sample run of a program generating quizzes about countries and capitals is shown below. How many questions : 3 What is the capital of Venezuala? Caracas Correct What is the capital of Kenya? Mombasa No, the capital is Nairobi What country has Reykjavik as its capital? Iceland Correct You got 2 out of 3 right output Assume that the function GeoQuiz whose header is given below is accessible by including the header le "geoquiz.h". void GeoQuiz(String & country, String & capital); postcondition: sets country and capital to a random country and its capital e.g., "United States", "Washington D.C." You may call GeoQuiz, you should NOT write GeoQuiz. Complete the program below so that it gives the kind of quiz shown above in the sample run. Each question should either print a country and ask for the capital or print the capital and ask for the country by simulating a \coin ip" (this can be done using a Dice variable). You can put all the code in main. Use the next page if you need more room. #include "dice.h" #include <iostream.h> #include "geoquiz.h" main() int numq; cout << "How many questions : "; cin >> numq; continued on next page 3

GeoQuiz(country,capital); if (die.roll() == 1) cout << "What is the capital of " << country << "? "; if (answer == capital) cout << "Correct" << endl; else else cout << "What country has " << capital << " as its capital? "; cout << "You got " << numright << " out of " << numq << " right" << endl; 4

PROBLEM 4 : (A Perfect World : 10 points) Anumber is called a perfect number if it is equal to the sum of its proper divisors (not including the number itself). For example, 6 and 28 are perfect because 6 = 1+2+3and28=1+2+4+7+14. The partial program below is designed to print all perfect numbers between 6 and a number entered by the user. If run with the input 30 it will print 6 and 28 (each on a separate line). Only the prototype for IsPerfect is given, you are to write the body of the function below main. In writing IsPerfect do NOT worry about the eciency of the function, just its correctness. Include brief pre and post-conditions for IsPerfect. #include <iostream.h> int IsPerfect(int num); main() int num; int limit; cout << "enter upper limit :"; cin >> limit; for(num=6; num <= limit; num++) if ( IsPerfect(num) ) cout << num << endl; 5

PROBLEM 5 : (A Course is a Course of course of course : 12 points) A class AceCourse is designed to allow C++ programs to get information about academic courses at Duke using the designated ACES number. The header le "acecourse.h" is reproduced below. As a sample of its use, the code fragment below AceCourse course(139772); if (course.isvalid()) 139772 is a valid course # cout << course.dept() << ", " << course.title() << ", "; cout << course.instructor() << ", " << course.area() << endl; cout << "enrollment ceiling = " << course.limit() << endl; generates the output below. ART, Art and Cyberculture, K. Stiles, AL enrollment ceiling = 15 Note: all ACES course numbers are six-digit numbers between 100,000 and 160,000. declaration for class AceCourse --- used to get/set information about courses at Duke using ACES call numbers AceCourse(int acenum) -- construct object having ACES call # e.g., AceCourse course(139772); defines course to correspond to Art 49S, Art and Cyberculture String Dept(), Title(), Instructor(), Area() -- return department, title, instructor, and area of knowledge int Limit() -- returns maximum number of students in course void Meeting(String & day, int & period) -- returns day course meets (either "M-W-F" or "T-Th" and period course meets (1-9) void SetNumber(int acenum) -- change course number to acenum (passed as parameter e.g., course.setnumber(144560); makes course CPS 08.01 bool IsValid(); -- returns true if course number used in constructor/setnumber corresponds to valid Duke Course e.g., after course.setnumber(1); course.isvalid() returns false since 1 isn't a valid ACES # 6

class AceCourse public: AceCourse(int acenum); construct course from ACES number String Dept(); dept of course String Title(); title of course String Instructor(); teacher of course String Area(); area of knowledge int Limit(); max # of students void Meeting(String &,int &); time course meets: MWF/Th, 1-9 void SetNumber(int acenum); set course to have ACES # acenum bool IsValid(); true if course is ok, false if not private: stuff here ; Part A: (3 points) The ACES number for Political Science 110 is 129244. Write a code segment that prints the instructor for the course and the day and period that the course meets. You MUST use AceCourse member functions to do this, you CANNOT write cout << "P. Gronke" << endl; to print the instructor, for example. 7

Part B: (9 points) Write the function KnowledgeArea whose header is given below. The function should print the title of every course whose area of knowledge is the value specied by the parameter distrib. A count of the number of courses should be printed too. For example, the call KnowledgeArea("CZ"); might generate output similar to the following:... Health, Healing, History American History/Social Theory The Atlantic Slave Trade # of courses with CZ designation = 152 Complete the function below. void KnowledgeArea(String distrib) postcondition: titles of all courses with area of knowledge = distrib printed with a count of the number of such courses 8

PROBLEM 6 : (Extra Credit: 6 points) This problem is NOT required An Armstrong number is any number of n digits such that the number is equal to the sum of each digit raised to the n th power. Formally: anumber i = d 1 d 2 :::d n is an armstrong number if i = nx (d j ) n j=1 Example: 153=1 3 +5 3 +3 3 =1+125+27 Example: 9=9 1 =9 Write the function IsArmstrong that returns true if num is an Armstrong number and false otherwise. bool IsArmstrong(int num) precondition: 0 < num postcondition: returns true if num is an Armstrong number otherwise returns false 9