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

Size: px
Start display at page:

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

Transcription

1 Name Section: M/W or T/TH True or False (14 Points) 1. (14 pts) Circle T for true and F for false: T F a) In C++, a function definition should not be nested within another function definition. T F b) Static variables retain their value from function call to function call. T F c) The use of the statement: return; is valid in a value returning function. T F d) Arguments corresponding to value parameters can be literal values. T F e) value parameters receive a copy of an arguments value T F f) Arguments corresponding to reference parameters can be literal values. T F g) Members of a structure must have unique names T F h) Members of a structure must all be of the same DataType. T F i) The expression first.name could be used to access the name member of a structure variable first. T F j) Hierarchical structures are structures where at least one member is a structure T F k) All members in a Union can hold a valid value at the same time. T F l) Void functions must use return expression; to transfer control back to the caller of the function. T F m) The lifetime of a local variable is from the point of declaration to the end of the block in which it is declared. T F n) Local identifiers have name precedence over global identifiers. Page 1 of 11

2 Multiple choice (8 points) Questions 2 9 For these problems circle all correct answers. For example if answers A, C and E are all valid then circle A, C and E. 2. How many function values does a value-returning function have? A) 4 B) 2 C) As many as necessary D) 1 E) 3 F) None of these 3. Which operations below ARE ALLOWABLE aggregate operations on structures? A) Return as a functions return value B) Arithmetic C) Input/Output D) Pass by value in a function call E) Assignment F) Comparison 4. A function that does not return a function value is known as what kind of function? A) Value returning function B) Reference Parameter C) Empty D) Void function E) Expression less F) None of these 5. Reference parameters (passing by reference) are used if a parameters data flow is A) One-way, into the function B) One-way, out of the function C) Two-way, into and out of the function D) A and C E) B and C F) None of these 6. What are the reference parameters in the following function heading? void DoSomething(string& date, int& num, float& average, float& sum, string& name) A) date B) num C) average D) sum E) name F) None of them 7. What are the value parameters in the following function heading? void DoSomething(string year, int value, float avg, float per, string city) A) year B) value C) avg D) per E) city F) None of them Page 2 of 11

3 8. The void function named GetNums has two parameters A pass-by-reference parameter named x of type float A pass-by-value parameter named num of type int. Which of the following choices is a valid function prototype given the description of the parameters for the function GetNums? A) void GetNums( float&, int ); B) void GetNums( float&, int& ); C) void GetNums( float, int ); D) void GetNums( float, int& ); E) none of the above 9. The void function named GetNums has two parameters A pass-by-reference parameter named x of type float A pass-by-value parameter named num of type int. Which of the following choices is a valid function heading given the description of the parameters for the function GetNums? A) void GetNums( float& x, int ) B) void GetNums( float&, int& num ) C) void GetNums( float& x, int num) D) A, B and C E) none of the above Short Answer (78 points) Questions (4 pts) Write a structure declaration for a structure named Car containing the following members: - an integer variable representing the number of doors - a string variable representing the maker of the car - a string variable representing the model of the car - a string variable representing the color of the car Page 3 of 11

4 11. (10 pts) Consider the following structure declarations when answering the questions below. struct Date int day; int month; int year; ; struct Customer string item; string custname; Date purchdate; ; a) Write a statement that declares the identifier birthday as a variable of DataType Date. b) Write a cout statement that will output the value of the month member of the variable birthday. c) Write a statement that declares the identifier johndoe as a variable of DataType Customer. d) Write a statement that assigns a value of Coat to the item member of johndoe. e) Write a cout statement that will output the value of the year member of the purchdate member of johndoe. Page 4 of 11

5 12. (6 pts) Given the following constant and variable definitions/declarations. const string NAME = Ron ; int value; float sum; string city; void cube(int); // function prototype consider the following list of possible expressions for use as arguments in a function call: a) NAME b) value c) city d) sum e) 13 f) cube(value) g) Ron h) X A) List all expressions above that are valid for use as arguments with value parameters? B) List all expressions above that are valid for use as arguments with reference parameters? 13. (6 pts) There are three functions shown in the code segment below. Assume all variables and function prototypes have been correctly declared before this segment of code. status = Average(sum); WriteInfo(outFile, Add(sum)); A) Which function(s) is(are) most likely value-returning function(s)? B) Which function(s) is(are) most likely void function(s)? C) What are the arguments that are used in the function calls. Page 5 of 11

6 14. (6 pts) Rewrite the value returning function definition below as a void function definition such that the caller of the function still has access to the result (contained in the variable sub) that is being returned by the value returning function. (Hint: need to add a reference parameter for the void function) string FindSub(string line, string name) string sub; sub = line.substr(line.find(name),line.size()); return sub; 15. (6 pts) Rewrite the void function definition below as a value returning function definition such that the caller of the function still has access to the result that is being returned by the void function. - Do not use any reference parameters with the value returning function. - Use two parameters only with the value returning function only void Calculate (float& num1, float num2, float num3) num3 = num2*num3; num1 = num2*num2 + num3; Page 6 of 11

7 16. (8 pts) When the program shown below is executed, what is the output to the screen? This problem deals with the scope of a variable in a program, and the order of execution of statements. #include <iostream> using namespace std; void function_a(int&); void function_b(int&); int number = 2; int main() int number = 4; function_b(number); cout << number in main is: << number << endl; return 0; void function_a(int& num) int number = 1; num = num - 2; cout << number in function A is: << number << endl; void function_b(int& sum) cout << sum in function B is: << sum << endl; function_a(sum); cout << number in function B is: << number << endl; sum = sum + 1; The identifying phrases written by the cout statements in this program are shown below. In the blank to the left of the lines, place 1,2,3 or 4 to indicate the order the statements are printed (1 for first, 4 for last). In The blank at the end of the line, put in the output value. number in main is: number in function A is: sum in function B is: number in function B is: Page 7 of 11

8 17. (12 pts) Write a void function definition that counts the number of non-empty lines in an input file. The number of non-empty lines contained in the input file is returned to the caller using a reference parameter. This function requires two parameters the input file stream and a line count. When an empty line is read with the getline function, the string variable holding the line read contains a null string (represented by ). The function assumes that the input file stream passed into the function is already open and associated with a file on the hard drive. Write the function definition only. This is not a complete program. Page 8 of 11

9 18. (12 pts) Finish the program below by adding a void function as specified below. Add only a function prototype, function call statement and function definition to the following program. The name of the void function is InitStruct. The function has one parameter of the struct DataType Date. The function is to initialize the structure parameter with a date of November 22, The information stored in the structure must be available in main() after the function call. #include <iostream> using namespace std; struct Date string month; int day; int year; ; // Place the function prototype below this line int main() Date turkey; // variable to hold the date of Thanksgiving // Place the function call statement below this line return 0; // Place the function definition below this line write the definition // This function initializes a structure variable // with the date November 22, 2012 Page 9 of 11

10 19. (8 pts) For the following code segment, write out what is printed to the screen. Show the displayed output precisely by using the following rules: o Write one character per box. o Skip a box to indicate the presence of a blank space in the output. o Skip a row to indicate the presence of a blank line in the output. #include <iostream> using namespace std; void Test(int); int main() Test(1); Test(2); Test(3); Test(2); Test(1); return 0; void Test(int value) static int j = 0; cout << j << - << value << endl; j = j + value; Page 10 of 11

11 Extra Credit (5 pts) For this problem show precisely the displayed output o Write one character per box. o Skip a box to indicate the presence of a blank space in the output. o Skip a row to indicate the presence of a blank line in the output. What is the output for the following segment of code? All variables are integers for (int i = 0 ; i < 10; i++) if ( i > 4) continue; for (int j = i; j < 10; j++) cout << j; // output value of j if (j < 5) cout << A ; else break; // output of letter A cout << - << i << endl; // output a dash and value of i Page 11 of 11

True or False (12 Points)

True or False (12 Points) Name True or False (12 Points) 1. (12 pts) Circle T for true and F for false: T F a) A void function call occurs as part of an expression. T F b) Value Returning Functions cannot have reference parameters.

More information

True or False (15 Points)

True or False (15 Points) Name Number True or False (15 Points) 1. (15 pts) Circle T for true and F for false: T F a) Void Functions cannot use reference parameters. T F b) Arguments corresponding to value parameters can be variables

More information

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

Name SECTION: 12:45 2:20. True or False (12 Points) Name SECION: 12:45 2:20 rue or False (12 Points) 1. (12 pts) Circle for true and F for false: F a) Local identifiers have name precedence over global identifiers of the same name. F b) Local variables

More information

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

CPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points) Name rue or False (12 Points) 1. (12 pts) Circle for true and F for false: F a) Local identifiers have name precedence over global identifiers of the same name. F b) Local variables retain their value

More information

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

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

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

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

True or False (14 Points)

True or False (14 Points) Name Number True or False (14 Points) 1. (15 pts) Circle T for true and F for false: T F a) void functions can use the statement return; T F b) Arguments corresponding to value parameters can be variables.

More information

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

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

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

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

True or False (15 Points)

True or False (15 Points) Name Number True or False (15 Points) 1. (15 pts) Circle T for true and F for false: T F a) Value Returning Functions cannot use reference parameters. T F b) Arguments corresponding to value parameters

More information

Name Section: M/W T/TH Number Definition Matching (6 Points)

Name Section: M/W T/TH Number Definition Matching (6 Points) Name Section: M/W T/TH Number Definition Matching (6 Points) 1. (6 pts) Match the words with their definitions. Choose the best definition for each word. Event Counter Iteration Counter Loop Flow of Control

More information

Name Section: M/W T/TH Number Definition Matching (8 Points)

Name Section: M/W T/TH Number Definition Matching (8 Points) Name Section: M/W T/TH Number Definition Matching (8 Points) 1. (8 pts) Match the words with their definitions. Choose the best definition for each word. Iteration Counter Event Counter Loop Abstract Step

More information

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.

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. 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. B. Outputs to the console a floating point number f1 in scientific format

More information

FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each):

FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): 1. The basic commands that a computer performs are input (get data), output (display result),

More information

5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (!

5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (! FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): 1. Assume that all variables are properly declared. The following for loop executes 20 times.

More information

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

CPE Summer 2015 Exam I (150 pts) June 18, 2015 Name Closed notes and book. If you have any questions ask them. Write clearly and make sure the case of a letter is clear (where applicable) since C++ is case sensitive. You can assume that there is one

More information

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

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures The main body and cout Agenda 1 Fundamental data types Declarations and definitions Control structures References, pass-by-value vs pass-by-references The main body and cout 2 C++ IS AN OO EXTENSION OF

More information

Definition Matching (10 Points)

Definition Matching (10 Points) Name SOLUTION Closed notes and book. If you have any questions ask them. Write clearly and make sure the case of a letter is clear (where applicable) since C++ is case sensitive. There are no syntax errors

More information

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

Starting Out with C++: Early Objects, 9 th ed. (Gaddis, Walters & Muganda) Chapter 2 Introduction to C++ Chapter 2 Test 1 Key Starting Out with C++ Early Objects 9th Edition Gaddis TEST BANK Full clear download (no formatting errors) at: https://testbankreal.com/download/starting-c-early-objects-9thedition-gaddis-test-bank/ Starting

More information

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

Week 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7. Week 3 Functions & Arrays Gaddis: Chapters 6 and 7 CS 5301 Fall 2015 Jill Seaman 1 Function Definitions! Function definition pattern: datatype identifier (parameter1, parameter2,...) { statements... Where

More information

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

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): 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): 1. If a function has default arguments, they can be located anywhere

More information

CSCE Practice Midterm. Data Types

CSCE Practice Midterm. Data Types CSCE 2004 - Practice Midterm This midterm exam was given in class several years ago. Work each of the following questions on your own. Once you are done, check your answers. For any questions whose answers

More information

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

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points) Name Definition Matching (8 Points) 1. (8 pts) Match the words with their definitions. Choose the best definition for each word. Relational Expression Iteration Counter Count-controlled loop Loop Flow

More information

Programming. C++ Basics

Programming. C++ Basics Programming C++ Basics Introduction to C++ C is a programming language developed in the 1970s with the UNIX operating system C programs are efficient and portable across different hardware platforms C++

More information

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

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam 2: FORM 2 (Please put your name and form # on the scantron!!!!) True (A)/False(B) (2 pts each): 1. Recursive algorithms tend to be less efficient than iterative algorithms. 2. A recursive function

More information

Functions, Arrays & Structs

Functions, Arrays & Structs Functions, Arrays & Structs Unit 1 Chapters 6-7, 11 Function Definitions! Function definition pattern: datatype identifier (parameter1, parameter2,...) { statements... Where a parameter is: datatype identifier

More information

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

Name. Classes and Objects 1. We re going to develop a class to help out Café Below is the definition for a class called Name CPTR246 Spring '17 (100 total points) Exam 1 Classes and Objects 1. We re going to develop a class to help out Café 1812. Below is the definition for a class called Beverage. The public and private

More information

Lecture 23: Pointer Arithmetic

Lecture 23: Pointer Arithmetic Lecture 23: Pointer Arithmetic Wai L. Khoo Department of Computer Science City College of New York November 29, 2011 Wai L. Khoo (CS@CCNY) Lecture 23 November 29, 2011 1 / 14 Pointer Arithmetic Pointer

More information

DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++

DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++ DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++ Objective: To Learn Basic input, output, and procedural part of C++. C++ Object-orientated programming language

More information

CSCE Practice Midterm. Data Types

CSCE Practice Midterm. Data Types CSCE 2004 - Practice Midterm This midterm exam was given in class several years ago. Work each of the following questions on your own. Once you are done, check your answers. For any questions whose answers

More information

Consider the following statements. string str1 = "ABCDEFGHIJKLM"; string str2; After the statement str2 = str1.substr(1,4); executes, the value of str2 is " ". Given the function prototype: float test(int,

More information

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

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char Week 1 Operators, Data Types & I/O Gaddis: Chapters 1, 2, 3 CS 5301 Fall 2016 Jill Seaman Programming A program is a set of instructions that the computer follows to perform a task It must be translated

More information

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

Test 2: CPS Owen Astrachan. November 17, Name: Honor code acknowledgement (signature) Test 2: CPS 53.2 Owen Astrachan November 17, 1993 Name: Honor code acknowledgement (signature) Problem 1 value 12 pts. grade Problem 2 16 pts. Problem 3 10 pts. Problem 4 13 pts. Problem 5 14 pts. TOTAL:

More information

Introduction to Programming

Introduction to Programming Introduction to Programming session 6 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Spring 2011 These slides are created using Deitel s slides Sharif University of Technology Outlines

More information

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

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science. Instructor: Final Exam Fall 2011 The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science Instructor: Final Exam Fall 2011 Last Name :... ID:... First Name:... Section No.: EXAMINATION

More information

! Pass by value: when an argument is passed to a. ! It is implemented using variable initialization. ! Changes to the parameter in the function body

! Pass by value: when an argument is passed to a. ! It is implemented using variable initialization. ! Changes to the parameter in the function body Week 3 Pointers, References, Arrays & Structures Gaddis: Chapters 6, 7, 9, 11 CS 5301 Fall 2013 Jill Seaman 1 Arguments passed by value! Pass by value: when an argument is passed to a function, its value

More information

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

The University of Alabama in Huntsville Electrical and Computer Engineering CPE Example of Objective Test Questions for Test 4 The University of Alabama in Huntsville Electrical and Computer Engineering CPE 112 02 Example of Objective Test Questions for Test 4 True or False Name: 1. The statement switch (n) case 8 : alpha++; case

More information

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

Week 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7. CS 5301 Spring 2018 Week 3 Functions & Arrays Gaddis: Chapters 6 and 7 CS 5301 Spring 2018 Jill Seaman 1 Function Definitions l Function definition pattern: datatype identifier (parameter1, parameter2,...) { statements...

More information

CMSC 202 Midterm Exam 1 Fall 2015

CMSC 202 Midterm Exam 1 Fall 2015 1. (15 points) There are six logic or syntax errors in the following program; find five of them. Circle each of the five errors you find and write the line number and correction in the space provided below.

More information

M1-R4: Programing and Problem Solving using C (JAN 2019)

M1-R4: Programing and Problem Solving using C (JAN 2019) M1-R4: Programing and Problem Solving using C (JAN 2019) Max Marks: 100 M1-R4-07-18 DURATION: 03 Hrs 1. Each question below gives a multiple choice of answers. Choose the most appropriate one and enter

More information

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

Functions. CS111 Lab Queens College, CUNY Instructor: Kent Chin Functions CS111 Lab Queens College, CUNY Instructor: Kent Chin Functions They're everywhere! Input: x Function: f Output: f(x) Input: Sheets of Paper Function: Staple Output: Stapled Sheets of Paper C++

More information

Functions, Arrays & Structs

Functions, Arrays & Structs Functions, Arrays & Structs Unit 1 Chapters 6-7, 11 Function Definitions l Function definition pattern: datatype identifier (parameter1, parameter2,...) { statements... Where a parameter is: datatype identifier

More information

Objectives. In this chapter, you will:

Objectives. In this chapter, you will: Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about

More information

Local and Global Variables

Local and Global Variables Lecture 10 Local and Global Variables Nearly every programming language has a concept of local variable. As long as two functions mind their own data, as it were, they won t interfere with each other.

More information

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

a. a * c - 10 = b. a % b + (a * d) + 7 = 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 =

More information

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

Integer Data Types. Data Type. Data Types. int, short int, long int Data Types Variables are classified according to their data type. The data type determines the kind of information that may be stored in the variable. A data type is a set of values. Generally two main

More information

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

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011 The American University in Cairo Department of Computer Science & Engineering CSCI 106-07&09 Dr. KHALIL Exam-I Fall 2011 Last Name :... ID:... First Name:... Form I Section No.: EXAMINATION INSTRUCTIONS

More information

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

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are

More information

Why Is Repetition Needed?

Why Is Repetition Needed? Why Is Repetition Needed? Repetition allows efficient use of variables. It lets you process many values using a small number of variables. For example, to add five numbers: Inefficient way: Declare a variable

More information

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100 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

More information

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

Name. CPTR246 Spring '17 (100 total points) Exam 2 Name CPTR246 Spring '17 (100 total points) Exam 2 1. Pointer parameters (the old C way) In the following program, make all of the changes to convert the call-by-reference parameters in the function computeoptions

More information

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

Chapter 6: User-Defined Functions. Objectives (cont d.) Objectives. Introduction. Predefined Functions 12/2/2016 Chapter 6: User-Defined Functions Objectives In this chapter, you will: Learn about standard (predefined) functions Learn about user-defined functions Examine value-returning functions Construct and use

More information

Topics. Functions. Functions

Topics. Functions. Functions Topics Notes #8 Functions Chapter 6 1) How can we break up a program into smaller sections? 2) How can we pass information to and from functions? 3) Where can we put functions in our code? CMPT 125/128

More information

Introduction to Programming EC-105. Lecture 2

Introduction to Programming EC-105. Lecture 2 Introduction to Programming EC-105 Lecture 2 Input and Output A data stream is a sequence of data - Typically in the form of characters or numbers An input stream is data for the program to use - Typically

More information

EECS402 Lecture 02. Functions. Function Prototype

EECS402 Lecture 02. Functions. Function Prototype The University Of Michigan Lecture 02 Andrew M. Morgan Savitch Ch. 3-4 Functions Value and Reference Parameters Andrew M. Morgan 1 Functions Allows for modular programming Write the function once, call

More information

CAAM 420 Fall 2012 Lecture 29. Duncan Eddy

CAAM 420 Fall 2012 Lecture 29. Duncan Eddy CAAM 420 Fall 2012 Lecture 29 Duncan Eddy November 7, 2012 Table of Contents 1 Templating in C++ 3 1.1 Motivation.............................................. 3 1.2 Templating Functions........................................

More information

CS242 COMPUTER PROGRAMMING

CS242 COMPUTER PROGRAMMING CS242 COMPUTER PROGRAMMING I.Safa a Alawneh Variables Outline 2 Data Type C++ Built-in Data Types o o o o bool Data Type char Data Type int Data Type Floating-Point Data Types Variable Declaration Initializing

More information

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

Lab 2: Pointers. //declare a pointer variable ptr1 pointing to x. //change the value of x to 10 through ptr1 Lab 2: Pointers 1. Goals Further understanding of pointer variables Passing parameters to functions by address (pointers) and by references Creating and using dynamic arrays Combing pointers, structures

More information

LECTURE 02 INTRODUCTION TO C++

LECTURE 02 INTRODUCTION TO C++ PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 02 INTRODUCTION

More information

Fundamentals of Programming CS-110. Lecture 2

Fundamentals of Programming CS-110. Lecture 2 Fundamentals of Programming CS-110 Lecture 2 Last Lab // Example program #include using namespace std; int main() { cout

More information

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

Basic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces Basic memory model Using functions Writing functions Basics Prototypes Parameters Return types Functions and memory Names and namespaces When a program runs it requires main memory (RAM) space for Program

More information

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

CS2141 Software Development using C/C++ C++ Basics CS2141 Software Development using C/C++ C++ Basics Integers Basic Types Can be short, long, or just plain int C++ does not define the size of them other than short

More information

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

CSCS 261 Programming Concepts Exam 1 Fall EXAM 1 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam. Name: Print legibly! Section: COMPUTER SCIENCE 261 PROGRAMMING CONCEPTS EXAM 1 VERSION 1 Fall 2014 150 Points Absolutely no electronic devices may be used during this exam. 1. No cell phones, computers,

More information

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

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program? Intro to Programming & C++ Unit 1 Sections 1.1-4 and 2.1-10, 2.12-13, 2.15-17 CS 1428 Spring 2019 Jill Seaman 1.1 Why Program? Computer programmable machine designed to follow instructions Program a set

More information

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9 Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Uppercase Alphabets Lowercase Alphabets Character Set A, B, C, Y, Z a, b, c, y, z Digits

More information

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

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 1 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 variables. Apply C++ syntax rules to declare variables, initialize

More information

Looping and Counting. Lecture 3 Hartmut Kaiser hkaiser/fall_2012/csc1254.html

Looping and Counting. Lecture 3 Hartmut Kaiser  hkaiser/fall_2012/csc1254.html Looping and Counting Lecture 3 Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/ hkaiser/fall_2012/csc1254.html Abstract First we ll discuss types and type safety. Then we will modify the program

More information

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

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Instructor: Final Exam Fall Section No. The American University in Cairo Computer Science & Engineering Department CSCE 106 Instructor: Final Exam Fall 2010 Last Name :... ID:... First Name:... Section No.: EXAMINATION INSTRUCTIONS * Do not

More information

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

Exam 2. CSI 201: Computer Science 1 Fall 2016 Professors: Shaun Ramsey and Kyle Wilson. Question Points Score Total: 80 Exam 2 CSI 201: Computer Science 1 Fall 2016 Professors: Shaun Ramsey and Kyle Wilson Question Points Score 1 18 2 29 3 18 4 15 Total: 80 I understand that this exam is closed book and closed note and

More information

CS201 Spring2009 Solved Sunday, 09 May 2010 14:57 MIDTERM EXAMINATION Spring 2009 CS201- Introduction to Programming Question No: 1 ( Marks: 1 ) - Please choose one The function of cin is To display message

More information

Looping and Counting. Lecture 3. Hartmut Kaiser hkaiser/fall_2011/csc1254.html

Looping and Counting. Lecture 3. Hartmut Kaiser  hkaiser/fall_2011/csc1254.html Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/ hkaiser/fall_2011/csc1254.html 2 Abstract First we ll discuss types and type safety. Then we will modify the program we developed last time (Framing

More information

Your first C++ program

Your first C++ program Your first C++ program #include using namespace std; int main () cout

More information

BITG 1233: Introduction to C++

BITG 1233: Introduction to C++ BITG 1233: Introduction to C++ 1 Learning Outcomes At the end of this lecture, you should be able to: Identify basic structure of C++ program (pg 3) Describe the concepts of : Character set. (pg 11) Token

More information

Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering

Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering Lecture 3 Winter 2011/12 Oct 25 Visual C++: Problems and Solutions New section on web page (scroll down)

More information

CSCE 110 PROGRAMMING FUNDAMENTALS

CSCE 110 PROGRAMMING FUNDAMENTALS CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class Prof. amr Goneid, AUC 1 Dictionaries(1): A Key Table Class Prof. Amr Goneid, AUC 2 A Key Table

More information

CMPS 221 Sample Final

CMPS 221 Sample Final Name: 1 CMPS 221 Sample Final 1. What is the purpose of having the parameter const int a[] as opposed to int a[] in a function declaration and definition? 2. What is the difference between cin.getline(str,

More information

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)

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) Introduction to C++ 1. General C++ is an Object oriented extension of C which was derived from B (BCPL) Developed by Bjarne Stroustrup (AT&T Bell Labs) in early 1980 s 2. A Simple C++ Program A C++ program

More information

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

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc. Week 1: Introduction to C++ Gaddis: Chapter 2 (excluding 2.1, 2.11, 2.14) CS 1428 Fall 2014 Jill Seaman Literals A literal represents a constant value used in a program statement. Numbers: 0, 34, 3.14159,

More information

CSCE 110 PROGRAMMING FUNDAMENTALS

CSCE 110 PROGRAMMING FUNDAMENTALS CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 8. Characters & Strings Prof. amr Goneid, AUC 1 Characters & Strings Prof. amr Goneid, AUC 2 Characters & Strings Characters & their

More information

Computer Science II Lecture 1 Introduction and Background

Computer Science II Lecture 1 Introduction and Background Computer Science II Lecture 1 Introduction and Background Discussion of Syllabus Instructor, TAs, office hours Course web site, http://www.cs.rpi.edu/courses/fall04/cs2, will be up soon Course emphasis,

More information

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

Chapter void Test( int, int, int ); // Function prototype int main() // Function heading { int h; // Local variable EXERCISE ANSWERS Chapter 7 Exam Preparation Exercises 1 Function call The mechanism that transfers control to the body of a function Argument list A mechanism by which functions communicate with each other;

More information

CS 251 Practice Final Exam R. Brown May 1, 2015 SHOW YOUR WORK No work may mean no credit Point totals will be adjusted to a 120 point scale later

CS 251 Practice Final Exam R. Brown May 1, 2015 SHOW YOUR WORK No work may mean no credit Point totals will be adjusted to a 120 point scale later Name CS 251 Practice Final Exam R. Brown May 1, 2015 SHOW YOUR WORK No work may mean no credit Point totals will be adjusted to a 120 point scale later I pledge my honor that I have neither given nor received

More information

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

2. It is possible for a structure variable to be a member of another structure variable. FORM 1(put name, form, and section number on scantron!!!) CS 162 Exam I True (A) / False (B) (2 pts) 1. What value will the function eof return if there are more characters to be read in the input stream?

More information

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

Functions that Return a Value. Approximate completion time Pre-lab Reading Assignment 20 min. 92 L E S S O N S E T 6.2 Functions that Return a Value PURPOSE PROCEDURE 1. To introduce the concept of scope 2. To understand the difference between static, local and global variables 3. To introduce the

More information

Pointers, Dynamic Data, and Reference Types

Pointers, Dynamic Data, and Reference Types Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple

More information

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

The University Of Michigan. EECS402 Lecture 02. Andrew M. Morgan. Savitch Ch. 3-4 Functions Value and Reference Parameters. The University Of Michigan Lecture 02 Andrew M. Morgan Savitch Ch. 3-4 Functions Value and Reference Parameters Andrew M. Morgan 1 Functions Allows for modular programming Write the function once, call

More information

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

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank 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. integer B 1.427E3 B. double D "Oct" C. character B -63.29 D. string F #Hashtag

More information

Input And Output of C++

Input And Output of C++ Input And Output of C++ Input And Output of C++ Seperating Lines of Output New lines in output Recall: "\n" "newline" A second method: object endl Examples: cout

More information

Lab Instructor : Jean Lai

Lab Instructor : Jean Lai Lab Instructor : Jean Lai Group related statements to perform a specific task. Structure the program (No duplicate codes!) Must be declared before used. Can be invoked (called) as any number of times.

More information

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays Outline 13.1 Test-Driving the Salary Survey Application 13.2 Introducing Arrays 13.3 Declaring and Initializing Arrays 13.4 Constructing

More information

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

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable Basic C++ Overview C++ is a version of the older C programming language. This is a language that is used for a wide variety of applications and which has a mature base of compilers and libraries. C++ is

More information

! A data structure representing a list. ! A series of nodes chained together in sequence. ! A separate pointer (the head) points to the first

! A data structure representing a list. ! A series of nodes chained together in sequence. ! A separate pointer (the head) points to the first Ch. 17: Linked Lists 17.1 Introduction to Linked Lists! A data structure representing a list! A series of nodes chained together in sequence CS 2308 Spring 2013 Jill Seaman - Each node points to one other

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

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

Chapter 8 - Notes User-Defined Simple Data Types, Namespaces, and the string Type Chapter 8 - Notes User-Defined Simple Data Types, Namespaces, and the string Type I. Enumeration Type A. Data Type: A set of values together with a set of operations on those values. 1. C++ provides the

More information

CSCE 110 PROGRAMMING FUNDAMENTALS

CSCE 110 PROGRAMMING FUNDAMENTALS CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 2. Overview of C++ Prof. Amr Goneid, AUC 1 Overview of C++ Prof. Amr Goneid, AUC 2 Overview of C++ Historical C++ Basics Some Library

More information

PIC 10A. Review for Midterm I

PIC 10A. Review for Midterm I PIC 10A Review for Midterm I Midterm I Friday, May 1, 2.00-2.50pm. Try to show up 5 min early so we can start on time. Exam will cover all material up to and including todays lecture. (Only topics that

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

CS 115 Exam 3, Spring 2010

CS 115 Exam 3, Spring 2010 Your name: Rules You must briefly explain your answers to receive partial credit. When a snippet of code is given to you, you can assume o that the code is enclosed within some function, even if no function

More information

CS 1428 Review. CS 2308 :: Spring 2016 Molly O Neil

CS 1428 Review. CS 2308 :: Spring 2016 Molly O Neil CS 1428 Review CS 2308 :: Spring 2016 Molly O Neil Structure of a C++ Program Hello world // This program prints a greeting to the screen #include using namespace std; int main() { cout

More information

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

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming

More information