Chapter 4 Homework Individual/Team (1-2 Persons) Assignment 15 Points

Similar documents
A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

Operators & Expressions

Unit 3. Operators. School of Science and Technology INTRODUCTION

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

Fundamental of Programming (C)

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

C: How to Program. Week /Mar/05

Programming for Engineers Introduction to C

Chapter 2 - Introduction to C Programming

Basics of Programming

First of all, it is a variable, just like other variables you studied

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

Lecture 3. More About C

Unit-2 (Operators) ANAND KR.SRIVASTAVA

Informatics Ingeniería en Electrónica y Automática Industrial

Operators and Expressions:

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

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

ANSI C Programming Simple Programs

CS102: Variables and Expressions

Computers Programming Course 6. Iulian Năstac

A flow chart is a graphical or symbolic representation of a process.

3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value.

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

UNIT- 3 Introduction to C++

Programming and Data Structures

Overview of C, Part 2. CSE 130: Introduction to Programming in C Stony Brook University

Fundamentals of Programming

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Flow Control. CSC215 Lecture

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Programming for Engineers: Operators, Expressions, and Statem

6.096 Introduction to C++ January (IAP) 2009

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

Programming in C++ 5. Integral data types

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

COMP Primitive and Class Types. Yi Hong May 14, 2015

Chapter 2, Part III Arithmetic Operators and Decision Making

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

QUIZ: What value is stored in a after this

C Pointers. Indirection Indirection = referencing a value through a pointer. Creating Pointers. Pointer Declarations. Pointer Declarations

Outline. Performing Computations. Outline (cont) Expressions in C. Some Expression Formats. Types for Operands

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

Week 4 Lecture 1. Expressions and Functions

Operators And Expressions

Variables and Operators 2/20/01 Lecture #

VENTURE. Section 1. Lexical Elements. 1.1 Identifiers. 1.2 Keywords. 1.3 Literals

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University

Chapter 1 & 2 Introduction to C Language

CSCE 110 PROGRAMMING FUNDAMENTALS

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

Expressions and Precedence. Last updated 12/10/18

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Lecture 02 Summary. C/Java Syntax 1/14/2009. Keywords Variable Declarations Data Types Operators Statements. Functions

Chapter 2, Part I Introduction to C Programming

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

C/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock)

C/Java Syntax. Lecture 02 Summary. Keywords Variable Declarations Data Types Operators Statements. Functions. if, switch, while, do-while, for

by Pearson Education, Inc. All Rights Reserved.

Data types, variables, constants

Data Types and Variables in C language

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

Introduction to C. Systems Programming Concepts

Programming Fundamentals - A Modular Structured Approach using C++ By: Kenneth Leroy Busbee

Information Science 1

4. Inputting data or messages to a function is called passing data to the function.

Work relative to other classes

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows

Chapter 3: Operators, Expressions and Type Conversion

BITG 1233: Introduction to C++

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

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

JAVA OPERATORS GENERAL

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

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

Homework #3 CS2255 Fall 2012

C Programs: Simple Statements and Expressions

Loops and Expression Types

Fundamentals of Programming CS-110. Lecture 3

Chapter 2: Introduction to C++

Department of Computer Science

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

Functions. Systems Programming Concepts

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

CMSC 104 -Lecture 6 John Y. Park, adapted by C Grasso

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

Yacoub Sabatin Muntaser Abulafi Omar Qaraeen. Introduction

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING

Full file at C How to Program, 6/e Multiple Choice Test Bank

Part I Part 1 Expressions

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

Pointers and Structure. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

GridLang: Grid Based Game Development Language Language Reference Manual. Programming Language and Translators - Spring 2017 Prof.

Variation of Pointers

Transcription:

All of the work in this project is my own! I have not left copies of my code in public folders on university computers. I have not given any of this project to others. I will not give any portion of this project to others taking this class. I realize that the penalty for turning in work that is not my own can range from an "F" in the class to dismissal from Trinity University. Print Title Time Required =. Hrs. Signature (pledged) Print Title Time Required =. Hrs. Signature (pledged) Chapter 4 Homework Individual/Team (1-2 Persons) Assignment 15 Points Answers To These Questions Must Be Handwritten; No Electronic Solutions Will Be Accepted! All programming/code questions refers to the C programming language. When writing program statements, include semicolons where necessary! Remember that C is case sensitive! 1] T/F The principles of top-down design and structured programming dictate that a program should be divided into a main module and its related modules. 2] T/F The function definition contains the code for a function. 3] T/F Function calls that return void may not be used as a part of an expression. 4] T/F The address operator (&) is used to tell the compiler to store data at an address. 5] T/F Variables defined within a block have global scope. 6] The process of dividing a program into functions which in turn are divided into functions until they consist of only elementary processing that is intrinsically understood and cannot be further subdivided - is known as a. charting b. flow charting c. factoring d. programming e. structuring 7] Which of the following statements about function declaration and definition is true? a. The function call is found in the called function. b. The function declaration requires that the parameters be named. c. The function definition is done with a function declaration. d. The function definition contains executable statements that perform the function s task. e. The function definition header concludes with a semicolon (;). 8] Which of the following is not a part of a function header? a. name b. parameter list c. return type d. title

9] Which of the following statements about function parameters is true? a. Empty parameter lists are declared with the keyword void. b. If there is only one parameter, the function list parentheses are not required. c. In the definition of a function, the parameters are known as actual parameters. d. Parameters are separated by semicolons. e. The parameters in a function definition are defined in the function s body (local declaration section). 10] Which of the following statements about local variables is false? a. A local variable s value may be returned through a return statement. b. Local variables are defined inside a function. c. Local variables cannot be referenced through their identifiers outside the function. d. Local variables may be initialized with an initializer. e. Local variables names can be the same as the function s parameter names. 11] To tell the compiler to store data at an address, use the a. address operator (&) b. array operator ([ ]) c. deference operator (#) d. indirection operator (*) e. pointer operator (^) 12] The function that returns the absolute value of a long integer is a. abs b. dabs c. fabs d. labs e. tabs 13. Which of the following statements will generate a random number in the range 30-50? a. rand (33) b. (rand ( ) % 20) + 1 c. (rand ( ) % 21) + 20 d. (rand ( ) % 21) + 30 e. (rand ( ) % 51) + 1 14] Which of the following statements about structure charts is false? a. Structure charts are a replacement for flowcharts. b. Structure charts are a primary design tool for a program. c. Structure charts are used in a structured walk-through to validate the design. d. Structure charts can be used to assess the testability of a program. e. Structure charts should be created before you start writing a program.

15] Find any errors in the following function definition: (Write something to correct the problem if possible - otherwise just void fun (int x, y) int z; return z; // fun 16. Find any errors in the following function definition: (Write something to correct the problem if possible - otherwise just int fun (int x, y) int z; return z; // fun 17. Find any errors in the following function definition: (Write something to correct the problem if possible - otherwise just int fun (int x, int y) int sun (int t) return (t + 3); return z; // fun 18. Find any errors in the following function definition: (Write something to correct the problem if possible - otherwise just void fun (int x,) return; // fun 19. Find any errors in the following function declarations/prototypes: (Write something to correct the problem if possible - otherwise just a. int sun (int x, y); b. int sun (int x, int y) c. void sun (void, void); d. void sun (x int, y float); 20. Find any errors in the following function calls: : (Write something to correct the problem if possible - otherwise just a. void fun ( ); b. fun (void); c. void fun (int x, int y); d. fun ( );

21. Evaluate the value of the following expressions: a. fabs (9.5) = b. fabs (-2.4) = c. fabs (-3.4) = d. fabs (-7) = e. fabs (7) = 22. Evaluate the value of the following expressions: a. floor ( 9.5 ) = b. floor ( -2.4 ) = c. floor ( -3.4 ) = d. ceil ( 9.5 ) = e. ceil ( -2.4 ) = f. ceil ( -3.4 ) = 23. Evaluate the value of the following expressions when x is 3.5, 3.45, 3.76, 3.234, and 3.4567: a. floor (x * 10 + 0.5) / 10 = b. floor (x * 100 + 0.5) / 100 = c. floor (x * 1000 + 0.5) / 10000 = 24. Define the range of the random numbers generated by the following expressions: a. rand ( ) % 10 = to b. rand ( ) % 4 = to c. rand ( ) % 10 + 1= to d. rand ( ) % 52= to e. rand ( ) % 2 + 1= to f. rand ( ) % 52-5= to Priority Table For All Of C Priority is Highest at Top of Chart and Lowest at Bottom of Chart. Operations between horizontal lines, above, have the same precedence!

C Operator Associativity Direction ( ) Parentheses Innermost Out ++ (Increment),-- (Decrement) Right to Left! (Unary Not) Right to Left & (Address) Right to Left * (De-reference) Right to Left & (Address) Right to Left (cast type) Right to Left (Unary Minus) Right to Left sizeof (returns # bytes for argument) Right to Left * (Multiplication) Left To Right / (Division) Left To Right % (Remainder) Left To Right + (Addition) Left To Right (Subtraction) Left To Right < (Less Than) Left To Right > (Greater Than) Left To Right <= (Less Than or Equal To) Left To Right >= (Greater Than or Equal To) Left To Right == (Equal) Left To Right = Equal) Left To Right && (And) Left To Right (Or) Left To Right = (Assignment Equal) Right To Left += (Plus Equal Assignment) Right To Left = (Minus Equal Assignment) Right To Left *= (Times Equal Assignment) Right To Left /= (Divide Equal Assignment) Right To Left %= (Modulus Equal Assignment) Right To Left

Run the following & List the output! printf("(true) ==> %d\n", (true) ); This implies that true = 1 false = 0 In reality, true =!0 false = 0 printf("(false) ==> %d\n\n", (false) ); 24] Evaluate each of the following as either true or false. Run the code if you are not sure. If the output from the program would be 0 then put false ; otherwise put true. printf("(true) ==> %d\n", (true) ); printf("(false) ==> %d\n\n", (false) ); printf("(false == false) ==> %d\n", (false == false) ); printf("(false == 0) ==> %d\n", (false == 0) ); printf("(false == 1) ==> %d\n\n", (false == 1) ); printf("(true == true) ==> %d\n", (true == true) ); printf("(true == 1) ==> %d\n", (true == 1) ); printf("(true == 2) ==> %d\n", (true == 2) ); printf("(true && true) ==> %d\n", (true && true) ); printf("(true && false) ==> %d\n", (true && false) ); printf("(false && true) ==> %d\n", (false && true) ); printf("(false && false) ==> %d\n", (false && false) ); printf("(true true) ==> %d\n", (true true) ); printf("(true false) ==> %d\n", (true false) ); printf("(false true) ==> %d\n", (false true) ); printf("(false false) ==> %d\n\n",(false false) ); printf("(! true) ==> %d\n", (! true) ); printf("(! false) ==> %d\n\n", (! false) ); printf("%d\n", (4.2 >= 5.0) && (8 == (3 + 5)) ); printf("%d\n", (4.2 >= 5.0) (8 == (3 + 5)) ); (4.2 >= 5.0) && (8 == (3 + 5)) (4.2 >= 5.0) (8 == (3 + 5))

25] Evaluate each of the following as either true or false. Run the code if you are not sure. If the output from the program would be 0 then put false ; otherwise put true. ( 2 < 0) && (18 >= 10) (-2 < 0) (18 >= 10) (3 > 5) && (14.1 == 0.0) (3 > 5) (14.1 == 0.0)! (18 == (10 + 8))! ( 4 > 0)! 7 == 7! 3.0 == 0.0! 4.2 > 3.7! 18 < 15! 13 < 100 13 <= 100 13 <= 13 0.012 > 0.013 17.32!= 17.32 4!= 5 X <= Y Y > X 'B' > 'A' 'A' <= 'B' 'B' > 'a' 'C' > 'A' 'a' == 'A' 26] What output is produced from each of the following program fragments? Assume all variables have been suitably declared. Record the output, if any, to the right of the print statement; some will be blank! a. A = 14.; B = 0.0; if (A < B) printf ("%f %f\n", A, abs(a)); printf ("%f\n", A * B);

b. c. d. e. B = 25; Count = 0; Sum = 0; if (A == B) printf ("%d %d\n", A, abs(a)); Count = Count + 1; Sum = Sum + A + B; printf ("%d %d\n", Count, Sum); printf ("%d %d\n", Count, Sum); Temp = 0; A = 10; B = 5; if (A > B) printf ("%d %d\n", A, B); Temp = A; A = B; B = Temp; printf ("%d %d\n", A, B); B = 25; A = 10; Count = 0; Sum = 0; if (B = 12) printf ("%d %d\n", A, abs(a)); Count = Count + 1; Sum = Sum + A + B; printf ("%d %d\n", Count, Sum); printf ("%d %d\n", Count, Sum); int X = 7; if ( 123 ) printf ("Now\n"); printf ("is\n"); if ( 0 ) printf ("the\n"); printf ("time\n"); if ( 1 ) printf ("to\n"); printf ("get\n"); if ( X = 5 ) printf ("out\n"); printf ("and\n");

27] Identify and correct all errors. a. if (Ch! = '.') CharCount = CharCount + 1; printf ('Ch = %c\n', Ch); PeriodCount = Period Count + 1; b. if (Age < = 20) YoungCount = YoungCount + 1; YoungAge = YoungAge + Age; OldCount = OldCount + 1; OldAge = OldAge + Age; c. if Age <= 20 YoungCount = YoungCount + 1; YoungAge = YoungAge + Age OldCount = OldCount + 1; OldAge = OldAge + Age