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

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

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

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.

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

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

CMSC 202 Midterm Exam 1 Fall 2015

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

Arrays. int Data [8] [0] [1] [2] [3] [4] [5] [6] [7]

CSCE Practice Midterm. Data Types

Computer Programming

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

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

Lab 2: Pointers. //declare a pointer variable ptr1 pointing to x. //change the value of x to 10 through ptr1

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

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

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

CSCE 206: Structured Programming in C++

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

BITG 1113: Function (Part 2) LECTURE 5

True or False (15 Points)

VARIABLES & ASSIGNMENTS

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

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?

7.1. Chapter 7: Arrays Hold Multiple Values. Array - Memory Layout. A single variable can only hold one value. Declared using [] operator:

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

Module 7 b. -Namespaces -Exceptions handling

Programming Language. Functions. Eng. Anis Nazer First Semester

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

C++ For Science and Engineering Lecture 15

Scientific Computing

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

Arrays. Week 4. Assylbek Jumagaliyev

Introduction to Computer Science Midterm 3 Fall, Points

Agenda / Learning Objectives: 1. Map out a plan to study for mid-term Review the C++ operators up to logical operators. 3. Read about the tips

C++ Lecture 5 Arrays. CSci 588: Data Structures, Algorithms and Software Design.

Chapter 1 INTRODUCTION

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

C++ For Science and Engineering Lecture 12

CS31 Discussion 1E. Jie(Jay) Wang Week5 Oct.27

Why Is Repetition Needed?

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

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

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

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

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

Exceptions, Case Study-Exception handling in C++.

2. Functions I: Passing by Value

Chapter 6: Arrays. Starting Out with Games and Graphics in C++ Second Edition. by Tony Gaddis

CS 216 Fall 2007 Midterm 1 Page 1 of 10 Name: ID:

CSCE Practice Midterm. Data Types

11. Arrays. For example, an array containing 5 integer values of type int called foo could be represented as:

9. Arrays. Compound Data Types: type name [elements]; int billy [5];

EECS402 Lecture 02. Functions. Function Prototype

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;

Lab Instructor : Jean Lai

C++ Casts and Run-Time Type Identification

CS 240 Computer Programming 1 Arrays

Programming. C++ Basics

6.1. Chapter 6: What Is A Function? Why Functions? Introduction to Functions

Exercise 1.1 Hello world

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

C and C++ I. Spring 2014 Carola Wenk

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

CSI33 Data Structures

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

BTE2313. Chapter 2: Introduction to C++ Programming

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

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

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

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

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

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

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

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

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

1st Midterm Exam: Solution COEN 243: Programming Methodology I

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

The University Of Michigan. EECS402 Lecture 02. Andrew M. Morgan. Savitch Ch. 3-4 Functions Value and Reference Parameters.

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

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

Chapter 1: Why Program? Computers and Programming. Why Program?

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

Week 3: Pointers (Part 2)

Homework Assignment #2 (revised)

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 6: User-Defined Functions I

Introduction to C++ Programming. Adhi Harmoko S, M.Komp

1a Computers, Problem Solving!

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

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

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

4. C++ functions. 1. Library Function 2. User-defined Function

CMPS 221 Sample Final

6.096 Introduction to C++ January (IAP) 2009

1) You want to determine whether time has run out. The following code correctly implements this:

CS 241 Computer Programming. Introduction. Teacher Assistant. Hadeel Al-Ateeq

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

CAAM 420 Fall 2012 Lecture 29. Duncan Eddy

CS31 Discussion. Jie(Jay) Wang Week6 Nov.4

Transcription:

Name: Sample Final Exam 1) (24 points) Show what is printed by the following segments of code (assume all appropriate header files, etc. are included): a) int start = 10, end = 21; while (start < end && end > 19) { cout << start<< '\t' << end << endl; start++; end--; } cout << start << '\t' << end << endl;

Sample Final b) int semestercredits[6] = { 10, 14, 16, 15, 12, 11}; int i; int course = 3; for (i = 0; i < 6; i++) { cout << semestercredits[i] << " - "; if (semestercredits[i] < 12) { cout << "\nadd for full time status!\n"; semestercredits[i] += course; } } cout << endl; for (i = 0; i < 6; i++) cout << semestercredits[i] << " # "; 2

Sample Final c) char word[20] = "Holidays!"; int x; x = strlen(word); if (word[3] == 'i' x == 18) cout << "-----\n"; else cout << 'X' << endl; if (6 > 15 && 45 % 3 == 1 'Y' > 'a') cout << "******\n"; else cout << 'O' << endl; cout << word << ' ' << x << endl; 3

Sample Final 2) Matching (8 points) a. Source code b. int bb[10][3]; c. Prototype d. Algorithm e. ASCII f. Reference parameter g. Debug h. Object code 1. a step-by-step plan to solve a given problem or task 2. numeric code for representation of characters 3. two dimensional array 4. commands to be compiled or assembled into an executable computer program 5. Using an &, an address is sent to the function 6. code produced by a compiler 7. a header or library file 8. declaration of a function that gives its name and types of parameters without the body of the function 9. convert the source code file into the machine readable code that a CPU can execute 10. identify and remove errors from computer software 4

3) (10 points) Given the following two declarations: double firstarray[90]; double secondarray[90]; Assume that firstarray is filled with values. Write the C++ code that assigns secondarray all the values of firstarray (so that after your code executes, both hold the same exact values!) 5

4) Given the following code: 1 #include <iostream> 2 using namespace std; 3 void printalot(int, char &); 4 int main() 5 { 6 char symbol = '*'; 7 int number = 4; 8 cout << symbol << '\t' << number << '\t' << symbol <<endl; 9 printalot(number, symbol); 10 cout << symbol << '\t' << number << '\t' << symbol << endl; 11 12 13 } 14 void printalot(int x, char & c) 15 { 16 int i; 17 x++; 18 for (i = 0; i < x; i++) 19 cout << c; 20 cout << endl; 21 if (x < 6) 22 c = '%'; 23 } 24 6

a) (8 points) What is printed by the code above? b) (2 points) Which line(s) in the code above contains function headers? c) (2 points) Which line(s) contains function prototypes? d) (2 points) Which parameter(s) is a reference parameter? 7

5) Write a value returning function named sumrange that takes two int parameters. The function returns the sum of all the integers between the first and the second parameters. For example, if the two parameters are 6 and 12, the function returns 63 (which is 6 + 7 + 8 + 9 = 10 + 11 + 12). YOU MAY ASSUME THAT THE VALUE OF THE FIRST PARAMETER IS LESS THAN THE VALUE OF THE SECOND. a) (2 points) Give the function prototype: b) (2 points) Give an example of the function call (from main): c) (10 points) Write the function definition (header and body): 8

6) a) (3 points) Four tutors work for three days each week in CSI s tutoring center. The table below stores one row for each tutor, keeping track of the number of hours that the tutor worked each day. For example, the first row shows that the tutor worked 4.5 hours one day, 5 hours the second day, and 5.5 hours the third day. 4.5 5 5.5 1.5 3.5 3 3 4.5 4 2.5 2.5 4.5 Give a declaration (you don t have to put in the values) for the two-dimensional array above.. b) (7 points) Assume that the values in the array above changed. Write code to print out how many times any tutor worked more than 4 hours in a day (in other words, how many entries in the array are greater than 4). 9

7) (20 points) Write a complete C++ program that accomplishes the task indicated below. Use good form by including comments and meaningful identifiers. Be accurate with the syntax -- as if you were typing the program on the computer. Assume that there is a file on disk named animals.txt that contains information about all the animals in the Bronx Zoo. Each line contains a name of an animal (a string with no spaces), a count for that type of animal in the zoo and a character indicating whether the animal is endangered or not ( y means yes and n means no). Aardvark 3 y AfricanWildDog 2 n.. The first line means that the Bronx Zoo has 3 Aardvarks and it is an endangered species. The second line means that there are 2 African Wild Dogs in the Bronx Zoo and they are NOT endangered. Write the program with the assumption that you do not know how many lines are in the list. You may assume that there are no spaces in the animal names. Write a C++ program that will do the following: <i> Open the file For each line of data, you must: <ii> Read in the line of data from the file <ii> Call a value returning function attention that returns true if the animal needs immediate attention. An animal needs immediate attention if it is endangered and there are less than 10 in the zoo. (The function attention takes two parameters.) Make sure that you write the code for this function. ---Compute the total number of animals (TOTAL NUMBER OF ANIMALS, NOT NUMBER OF LINES IN THE FILE) in the zoo. -- Compute the total number of animals that need special attention. ---Print the output so that it is organized as on the next page. (Of course there will be more lines, because this is shown only for the first two lines above, and we don t know HOW many lines are in the file). All printing is done in the main function. 10

ANIMAL AMOUNT NEEDS ATTENTION --------------------------------------------------------------------------------------------------- Aardvark 3 yes AfricanWildDog 2 no There are 5 animals in the zoo. There are 3 animals that need special attention. 11