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

Similar documents
CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

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

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.

Chapter 1 INTRODUCTION

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

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

Introduction. Arizona State University 1

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

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

CSCE 206: Structured Programming in C++

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

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

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++

Exercise 1.1 Hello world

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

Chapter 4 - Notes Control Structures I (Selection)

Pointers, Dynamic Data, and Reference Types

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

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

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

Chapter 2: Introduction to C++

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

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

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

Computer Programming

Module 7 b. -Namespaces -Exceptions handling

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

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

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

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

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

CMSC 202 Midterm Exam 1 Fall 2015

Introduction to Programming EC-105. Lecture 2

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

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;

LECTURE 02 INTRODUCTION TO C++

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

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

VARIABLES & ASSIGNMENTS

Why Is Repetition Needed?

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

Multiple Choice Questions (20 questions * 5 points per question = 100 points)

CSC 309/404 Section 901/910 Spring 2017 Midterm Exam Due: May 7 (Sun) 2015, 11:59 pm

Chapter 2: Overview of C++

Exercise: Using Numbers

Chapter 1 Introduction to Computers and Programming

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

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

Lecture 3 The character, string data Types Files

CSc Introduction to Computing

CSCE Practice Midterm. Data Types

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

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

A First Program - Greeting.cpp

Objectives. In this chapter, you will:

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?

Chapter 2 Basic Elements of C++

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

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

BTE2313. Chapter 2: Introduction to C++ Programming

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

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

Fundamentals of Programming CS-110. Lecture 2

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

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

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Chapter void Test( int, int, int ); // Function prototype int main() // Function heading { int h; // Local variable

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.

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

Study Guide for Test 2

Name. Classes and Objects 1. We re going to develop a class to help out Café Below is the definition for a class called

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

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

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

BITG 1113: Function (Part 2) LECTURE 5

Chapter 8 - Notes User-Defined Simple Data Types, Namespaces, and the string Type

I/O Streams and Standard I/O Devices (cont d.)

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

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

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

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

The University of Alabama in Huntsville Electrical and Computer Engineering CPE Example of Objective Test Questions for Test 4

6.096 Introduction to C++ January (IAP) 2009

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

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

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

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

Definition Matching (10 Points)

Introduction to Computer Science Midterm 3 Fall, Points

CS 115 Exam 3, Spring 2010

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

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

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

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

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

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

True or False (14 Points)

Programming. C++ Basics

Transcription:

CSC 126 FINAL EXAMINATION FINAL Spring 2012 B Name (last, First) Instructor Question # Total Possible Total Received 1. 8 2. 8 3. 8 4. 14 5. 18 6. 10 7. 16 8. 18 TOTAL 100

Final Exam/ Page 2 1) (8 points) Suppose that we have the following declarations: double alpha, x = 5, y = 2; bool flag; What is the value assigned to alpha or flag with each of the following expressions? a) alpha = 3.5 + 10 % 6 / 8; b) flag = (15 * y == 9 4 < 8); 2) a) (4 points) Declare an array to store the hospital bill amounts for 300 patients. b) (4 points) Assign each element of the array a value of 40.00. 2

Final Exam/ Page 3 3. (8 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. bit 2. syntax 3. CPU 4. ASCII code 5. compiler 6. hard-drive 7. Random Access Memory 8. algorithm COLUMN B a. The binary representation of characters stored on a computer b. The set of rules for formulating grammatically correct language statements. c. Volatile memory where your programs and data are stored while you use the computer. d. Secondary storage for data. e. A program which translates instructions written in a high-level language into the equivalent machine language f. Hardware which performs control functions and arithmetic and logical operations g. A step by step problem solving process in which a solution is arrived in a finite amount of time. h. Part of the development environment that allows users to step through code line by line, and view data values. i. Smallest unit of logic equivalent to a 1 or 0 3

Final Exam/ Page 4 4. 1 #include <iostream> 2 using namespace std; 3 4 void taketrip(double m, double & t); 5 int main() 6 { 7 double marker = 46.5; 8 double traveled = 0; 9 cout << "Beginning at mile marker: " << marker << endl; 10 taketrip(marker,traveled); 11 12 cout << "Mile marker is: " << marker << endl; 13 cout << "Traveled: " << traveled << endl; 14 15 taketrip(marker,traveled); 16 cout << "Mile marker is: " << marker << endl; 17 cout << "Traveled: " << traveled << endl; 18 return 0; 19 } 20 void taketrip(double m, double & t) 21 { 22 m = m + 10; 23 t = t + m; 24 } 4

Final Exam/ Page 5 a) (8 points) What is printed by the program above? b) (2 points) Which line(s) contain function calls? c) (2 points) Which line(s) contain function prototype(s)? d) (2 points) List all reference parameters. 5

Final Exam/ Page 6 5. What is printed by the following code? If the loop is infinite, write INFINITE LOOP. a) (8 points) double cells[4]; for (i = 0; i < 4; i++) cells[i] =i * i; for (i = 0; i < 4; i++) cout << cells[i] << '\t'; cout << endl; for (i = 0; i < 2; i++) cells[i * 2] = 5; for (i = 0; i < 4; i++) cout << cells[i] << '\t'; b) (6 points) int i, j; for (i = 0; i <=4; i+=2) { cout << i; for (j = 0; j <= i; j++) { cout << '#'; } cout << j << endl; } 6

Final Exam/ Page 7 c) (4 points) int num = 50; while (num < 52) cout << Hi << endl; cout << Bye << endl; 6) (10 points) Write the definition (header and body) for a value returning function called haspair. This function accepts three double parameters and checks to see if ANY two of the parameters are equal. If any two parameters are equal, the function returns true; otherwise the function returns false. 7

Final Exam/ Page 8 7) Questions a-d are 3 points each, question e is 4 points. Suppose you have strings: char worda[ ] = { HAPPY }; char wordb[ ] = { HOLIDAYS }; char wordc[20]; Suppose you have integer variables: int n1, n2; a. What is the value of wordb[1]? b. n1 = strlen (worda); What value does n1 receive? c. n2 = strcmp (wordb, worda); What is the value of n2? d. After strcpy (wordc, wordb) what is in wordc? e. (4 points) Suppose there was a wordd declared similar to worda or wordb above. Further assume that the initial value stored is not known to you. Write the code fragment that finds the number of occurrences of the letter A in wordd. DO NOT WRITE AN ENTIRE PROGRAM. EXAMPLE: If wordd stored the word ABRACADABRA, your code would display the following output: There are 5 A s in ABRACADABRA. 8

Final Exam/ Page 9 8) (18 points) On the next page, 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 HOUSESEATS.TXT that contains information about the past election for all new representatives in Congress. Each line contains the state name, a number that indicates the district in the state, and the percentage of the vote that the winning candidate has. The first few lines in the file are shown: Alabama 2 61.1 Arizona 1 50.1 Arizona 5 62.3 Arkansas 1 61.8. The first line means that in Alabama, district #2 the new winning representative received 61.1% of the vote. Write the program on the assumption that you do not know how many lines are in the list. You may assume that there are no spaces in the state names. Write a C++ program that will do the following: 9 <i> Open the file and read in the data. <ii> Call a value returning function that returns y if the representative received more than 60% of the vote and n otherwise. <iii> Compute the total number of delegates winning more than 60% of the vote. <iv> Compute the average number percentage win. <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, and we don t know HOW many lines are in the file). All printing is done in the main function. STATE District Percentage Win >60% -------------------------------------------- Alabama 2 61.1 y Arizona 1 50.1 n Arizona 5 62.3 y Arkansas 1 61.8 y Total number who won more than 60% of the vote was: 3 Average Percentage Won: 53.8

Final Exam/ Page 10 Write Your Program Here 10

Final Exam/ Page 11 Scrap 11