CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

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

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

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 & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

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

Computer Programming : C++

Chapter 1 INTRODUCTION

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

Introduction. Arizona State University 1

CSc Introduction to Computing

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II:

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

LECTURE 02 INTRODUCTION TO C++

A First Program - Greeting.cpp

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

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

Fundamentals of Programming CS-110. Lecture 2

Chapter 2: Introduction to C++

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

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

CSCE Practice Midterm. Data Types

CSCE 206: Structured Programming in C++

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

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

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

Chapter 2: Basic Elements of C++

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

Introduction to Programming EC-105. Lecture 2

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

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

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

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

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

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

Getting started with C++ (Part 2)

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

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

2 nd Week Lecture Notes

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

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

Chapter 1: An Overview of Computers and Programming Languages. Objectives. Objectives (cont d.) Introduction

CHAPTER 3 BASIC INSTRUCTION OF C++

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

Programming Language. Functions. Eng. Anis Nazer First Semester

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

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

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

3. Functions. Modular programming is the dividing of the entire problem into small sub problems that can be solved by writing separate programs.

Characters, c-strings, and the string Class. CS 1: Problem Solving & Program Design Using C++

CMSC 202 Midterm Exam 1 Fall 2015

READ THIS NOW! Do not start the test until instructed to do so!

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

Week 0: Intro to Computers and Programming. 1.1 Why Program? 1.2 Computer Systems: Hardware and Software. Hardware Components

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

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

BITG 1233: Introduction to C++

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?

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

Introduction to Algorithms and Data Structures. Lecture 6 - Stringing Along - Character and String Manipulation

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

4. Structure of a C++ program

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

Exercise 1.1 Hello world

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

CS242 COMPUTER PROGRAMMING

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

CS 376b Computer Vision

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

Input And Output of C++

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

Scientific Computing

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

Chapter 2: Overview of C++

Week 3: Pointers (Part 2)

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

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

Physics 234: Computational Physics

True or False (14 Points)

Objectives. In this chapter, you will:

The C++ Language. Arizona State University 1

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

Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A

Lecture 2 Tao Wang 1

UNIT- 3 Introduction to C++

Understanding main() function Input/Output Streams

Reviewing all Topics this term

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

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

True or False (12 Points)

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

CS2255 HOMEWORK #1 Fall 2012

CSCE Practice Midterm. Data Types

WARM UP LESSONS BARE BASICS

1. In C++, reserved words are the same as predefined identifiers. a. True

BITG 1113: Array (Part 1) LECTURE 8

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

BITG 1233: Array (Part 1) LECTURE 8 (Sem 2, 17/18)

Midterm Practice Exam

Transcription:

CSC 126 FINAL EXAMINATION Spring 2011 Version A Name (Last, First) Your Instructor Question # Total Possible 1. 10 Total Received 2. 15 3. 15 4. 10 5. 10 6. 10 7. 10 8. 20 TOTAL 100

Name: Sp 11 Page 2 of 13 For each of the following exam questions, place your answers on the question paper. There will be no scrap paper given. If you need scrap, two blank pages are provided at the back of this exam paper. Your name must appear at the top of each page, including the scrap pages in the back. CALCULATORS and CELL PHONES MAY NOT BE USED DURING THE EXAM!! 1. (10 points) Match the term in COLUMN A with the phrase in COLUMN B which defines the term. Write the letter of the phrase in the blank space to the left of the term. Note that as there are more phrases than terms, not every phrase matches a term. COLUMN A 1. ASCII 2. compiler 3. input device 4. CPU 5. syntax 6. header file 7. algorithm 8. bool 9. semicolon 10. bug COLUMN B A. The set of rules for formulating grammatically correct language statements. B. Contains the fundamental instructions that initially control the computer. These instructions cannot be lost or changed by the computer user. C. a data type with two values: true and false. D. an encoding of characters into a sequence of 0s and 1s E. The machine language version of the high level language program. F. Volatile memory where your programs and data are stored while you use the computer. G. libraries containing functions and symbols that can be included in a C++ program using preprocessor directives H. A program which translates instructions written in a highlevel language into the equivalent machine language I. examples are keyboard, mouse, USB drive J. Used as a terminator of each statement in C++ source code K. Hardware which performs control functions and arithmetic and logical operations L. An error in a program M. A step by step problem solving process in which a solution is arrived in a finite amount of time.

Name: Sp 11 Page 3 of 13 2. (15 points) What output will be displayed from each of the following program segments? a) (4 pts) int x = 17; while (x > 3) { x = x - 5; cout << x << endl; cout << '$' << x << '$' << endl; b) (4 pts) const int NUM = 4; int i, j; for (i = 1; i <= NUM; i++) { for (j = 1; j <= 2; j++) { cout << setw(3) << i * j; cout << endl;

Name: Sp 11 Page 4 of 13 c) (3 pts) int x; double y; x = (11 % 3) * 2-3 / 2 + 1; y = (5 / 2.0 + 1.5 + 3) * 2 / 4 + 1; cout << x << '\t' << y << endl; d) (4 pts) int list[7] = {1, 2, 0, -6, 7, 9, 12; int i = 2; while ( i <= 3 ) { list[i] = list[i] + i; i++; for( i = 0; i < 7; i ++ ) cout << list[i] << " ";

Name: Sp 11 Page 5 of 13 3. (15 points) Willowbrook College has a terrific baseball team of 7 players. The following array represents the total number of homeruns scored by each player: int homeruns[7] = { 58, 150, 0, 234, 6, 98, 43 ; a. (3 pts) Draw the array in a diagram. b. (6 pts) Write the code to compute the total number of homeruns scored by the team this year and to determine the maximum number produced by the leading homerun player. c. (6 pts) Write the code to compute the average number of homeruns scored by a player. Print the average.

Name: Sp 11 Page 6 of 13 4. (10 points) a. (2 points) Write a declaration for the array below and name it matrix. -1 7 1 3 4-1 1 3 5 6-3 1 b. (4 points) Given the contents of matrix above, what is printed by this code? int i, j, sum; for ( j = 0; j < 3; j++) { sum = 0; for (i = 0; i < 4; i++) sum = sum + matrix[i][j]; cout << "sum #" << j + 1 << " = " << sum << endl; c. (4 points) Suppose that the contents of matrix changed. Write the code that will print out all elements of matrix that are negative.

Name: Sp 11 Page 7 of 13 5. (10 points) Sub-questions a d are 1 point each. Suppose that you have the following declarations: char linea[20] = "END OF"; char lineb[20] = "SPR 2011"; char linec[20]; int x1, x2; a. What is the value of linea[1]? b. x1 = strlen( lineb ); What value does x1 receive? c. x2 = strcmp( lineb, "YEAR" ); What is the value of x2? d. After strcpy( linec, linea ) what is in linec? e. (6 points) Suppose there was a lined declared similar to linea or lineb above. Further assume that the initial value stored is not known to you. Write a code fragment that finds the number of occurrences of the letter 'E' in lined. DO NOT WRITE AN ENTIRE PROGRAM. EXAMPLE: If lined stored the phrase HELLO THERE, your code would display the following output: There are 3 E s in lined.

Name: Sp 11 Page 8 of 13 6. (10 points) A value-returning function, weeklywage computes and returns the total money that a part-timer makes for a week. The function accepts two parameters: an integer parameter (total hours), a double parameter (pay rate per hour). Write the function prototype for weeklywage Write an example call to the function. Write the function definition (Header and Body) for weeklywage

Name: Sp 11 Page 9 of 13 7. (10 points) What is printed by the following program? #include <iostream> using namespace std; bool fun1( int x, int y ); void fun2( int x, int& y ); int main( ) { int s = 3, t = 7 ; bool retval; cout << "Before fun1: s = " << s << ", t = " << t << endl; retval = fun1( s, t ); if( retval == true ) cout << "Return true\n"; cout << "After fun1: s = " << s << ", t = " << t << endl << endl; s = 9, t = 5; cout << "Before fun2: s = " << s << ", t = " << t << endl; fun2( s, t ); cout << "After fun2: s = " << s << ", t = " << t << endl; return 0; bool fun1( int x, int y ) { x = x + 3; y = y - 3; if( x > y ) return true; return false; void fun2( int x, int& y ) { int tmp = x; x = y; y = tmp;

Name: Sp 11 Page 10 of 13 8. (20 points) Write a complete program to determine some statistics of email messages data A data file named email.txt exists and contains in it the type of email (either character C or W for College or Work), the sending account, and the size in KB (kilo bytes) of the account. An example of a few lines of data is as follows: C john@nyu.edu 3 W sals@supermarket.com 13 W jackie@ymail.com 45 C sue@csi.cuny.edu 4 Assume we don t know the exact amount of lines of data in the file in advance; write a complete C++ program (put your code on the next page) that will do the following. i) Open the file and read in the data. ii) Write a value returning function that classifies the email by the size as LARGE or MEDIUM or SMALL by returning the character L, M, or S. Note: less than 5 KB is SMALL, between 5 and 20 KB is MEDIUM, and over 20 KB is LARGE. iii) Determine the following totals: total number of email messages, total space that all the messages take up in KB, total number of SMALL messages. iv) Print the output so that it is organized as below. (Of course there will be more lines, because this is shown only for the lines above). All printing is done in the main function. TYPE SENDER SIZE CLASSIFICATION ---------------------------------------------------------------------------------------- C john@nyu.edu 3 SMALL W sals@supermarket.com 13 MEDIUM W jackie@ymail.com 45 LARGE C sue@csi.cuny.edu 4 SMALL Total emails: 4 Total KBs: 65 Total SMALL emails: 2

Name: Sp 11 Page 11 of 13 Program code for Question 8 goes here:

Name: Sp 11 Page 12 of 13 DRAFT

Name: Sp 11 Page 13 of 13 DRAFT