Homework Assignment #3 J. H. Wang Oct. 29, 2007.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
LAB-04 IF Structure I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
Chapter 4 Repetitive Execution. 2 Types of Repetition There are two basic types of repetition: 1) Repetition controlled by a counter; The body of the.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Conditions and if/else. Conditions score > 90 Evaluates to true (1) or false (0) Generally … variable operator variable variable operator constant.
Lab 6 rOperators l Relational Operators l Equality Operators l Logical Operators rIf statement l One Alternative l With Compound Statement l Nested If.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
1 Selection Structures. 2 Making Decisions Sample assignment statements to figure worker pay with possible overtime PayAmount = Hours * Rate PayAmount.
Chapter 4 Making Decisions
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
Chapter 1 Pseudocode & Flowcharts
FUNCTIONS AND FUNCTION NOTATION
Advanced Math Chapter P
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Looping Exercises Deciding Which Loop to Use At this.
Agenda  Commenting  Inputting Data from Keyboard (scanf)  Arithmetic Operators  ( ) * / + - %  Order of Operations  Mixing Different Numeric Data.
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Homework Assignment #3 J. H. Wang Apr. 19, 2007.
1 CSC103: Introduction to Computer and Programming Lecture No 7.
A First C Program /* Print a Message */ #include main() { printf("This is a test!\n"); } The program is compiled and run as cc pg32.c  a.out  This is.
Please CLOSE YOUR LAPTOPS, and turn off and put away your cell phones, and get out your note- taking materials.
Value and Reference Parameters. CSCE 1062 Outline  Summary of value parameters  Summary of reference parameters  Argument/Parameter list correspondence.
CPS120: Introduction to Computer Science Operations Lecture 9.
EXERCISES for ALGORITHMS WRITING
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Homework Assignment #4 J. H. Wang Dec. 3, 2007.
Agenda Basic Logic Purpose if statement if / else statement
1 Programming 2 Overview of Programming 1. Write the equations in C++ notation : a) R =   a + b  24  2 a  b) W = a 12 + b 2 – 2abcos(y) 2a.
Assignment statement and Arithmetic operation 1 The major part of data processing.
Decision Structures and Boolean Variables. Sequence Structures Thus far, we’ve been programming “sequence structures” Thus far, we’ve been programming.
Any questions on today’s homework? (Sections 1.6/1.7) Reminder: You should be doing this homework without using a calculator, because calculators can’t.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
Chapter 7 Problem Solving with Loops
Structured Programming II: If Statements By the end of this class you should be able to: implement branching in a program describe and use an “if” statement.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Iterative Structures (Loops) CS 1401 Spring 2013 Shirley Moore, Instructor February 28, 2013.
 Constants A constant is a fixed value of a data type that cannot be changed Integer Constants Whole numbers → Do not have decimal points Examples: 83.
Python Basics  Values, Types, Variables, Expressions  Assignments  I/O  Control Structures.
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
1 Project 4: Computing Distance. 222 Computing Distance Write a program to compute the distance between two points. Recall that the distance between the.
CS 101 – Oct. 7 Solving simple problems: create algorithm Structure of solution –Sequence of steps (1,2,3….) –Sometimes we need to make a choice –Sometimes.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Section 7.1 The Rectangular Coordinate System and Linear Equations in Two Variables Math in Our World.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Introduction to programming in java Lecture 11 Boolean Expressions and Assignment no. 2.
Chapter 4.  integer  negative sign  opposites  absolute value.
CIS 115 All Exercises Devry University (Devry) FOR MORE CLASSES VISIT CIS 115 All Exercises Devry University.
Exercise 2 : Using for loop Repetition (loop) (1)control variable initialization (2)Test Conditon (3)Modification of control variable value order : (1)
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Based on slides by Shawn.
Algorithm & Flowchart.
1-1 Logic and Syntax A computer program is a solution to a problem.
Chapter P Prerequisites. Chapter P Prerequisites.
Chapter 1 Jeopardy! Variables & Expressions
ALGORITHMS AND FLOWCHARTS
PROBLEM SOLVING CSC 111.
The Coordinate Plane; Graphs of Equations; Circles
Programming Right from the Start with Visual Basic .NET 1/e
Chapter 2 - Introduction to C Programming
ALGORITHMS AND FLOWCHARTS
CSE 1020:Control Structure
Chapter 2 - Introduction to C Programming
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Chapter 2 - Introduction to C Programming
CSC 1051 – Data Structures and Algorithms I
Unit 3: Variables in Java
Sullivan Algebra and Trigonometry: Section 2.1
DATA TYPES AND OPERATIONS
REPETITION Why Repetition?
Presentation transcript:

Homework Assignment #3 J. H. Wang Oct. 29, 2007

Homework Assignment #3 Chap. 3 Chap. 4 Deadline: Exercise 3.2: 1, Prog. 2 (p.111) Exercise 3.5: Prog. 2 (p.136) Review Questions: 4 (p.140) Programming Projects: Prog. 4, 12 (p.141, 144) Chap. 4 Exercise 4.2: 2, 4 (p.157) Exercise 4.4: Prog. 1 (p.166) Exercise 4.7: 3 (p.189) Programming Projects: Prog. 6, 7 (p.205) Deadline: Two weeks (Due: Nov. 12, 2007)

Details Exercise 3.2: 1, Prog. 2 (p.111) 1. Rewrite the following mathematical expressions using C functions: a. b. c. d. Prog. 2. Write a complete C program that prompts the user for the Cartesian coordinates of two points (x1, y1) and (x2, y2) and displays the distance between them computed using the formula:

Exercise 3.5: Prog. 2 (p.136) Prog. 2. Write a function that computes the speed (km/h) one must average to reach a certain destination by a designated time. You need to deal only with arrivals occurring later on the same day as the departure. Function inputs include departure and arrival times as integers on a 24-hour clock (8:30P.M. = 2030) and the distance to the destination in kilometers. Also write a driver program to test your function.

Review Questions: 4 (p.140) 4. What are the three advantages of using functions?

Programming Projects: Prog. 4, 12 (p.141, 144) 4. Write a computer program that computes the duration of a projectile’s flight and its height above the ground when it reaches the target. As part of your solution, write and call a function that displays instructions to the program user. Try your program on the data sets.

Prog.12: Write a program that calculates the speed of sound (a) in air of a given temperature T (°F). Use the formula: Be sure your program does not lose the fractional part of the quotient in the formula shown. As part of your solution, write and call a function that displays instructions to the program user.

Exercise 4.2: 2, 4 (p.157) 2. Evaluate each of the following expressions if a is 5, b is 10, c is 15, and flag is 1. Which parts of these expressions are not evaluated due to short-circuit evaluation? a. c == a+b || !flag b. a != 7 && flag || c>=6 c. !(b<=12) && a%2 ==0 d. !(a>5 || c<a+b) 4. Complement each expression in Exercise 2. Use DeMorgan’s theorem if applicable.

Exercise 4.4: Prog. 1 (p.166) 2. Write an if statement that might be used to compute and display the average of a set of n numbers whose sum is stored in variable total. This average should be found only if n is greater than 0; otherwise, an error message should be displayed.

Exercise 4.7: 3 (p.189) 3. Write as nested if statement for the decision diagrammed in the accompanying flowchart. Use a multiple-alternative if for intermediate decisions where possible. false true pH>7 true true pH is 7 pH<12 false “Neutral" false pH>2 “Alkaline" true false “Very alkaline" “Acidic" “Very acidic"

Programming Projects: 6, 7 (p. 205) 6. Write a program that takes the x-y coordinates of a point in the Cartesian plane and prints a message telling either an axis on which the point lies or the quadrant in which it is found. Sample lines of output: (-1.0, -2.5) is in quadrant III (0.0, 4.8) is on the y axis

7. Write a program that determines the day number (1 to 366) in a year for a date that is provided as input data. As an example, January 1, 1994, is day 1. December 31, 1993, is day 365. December 31, 1996, is day 366, since 1996 is a leap year. A year is a leap year if it is divisible by four, except that any year divisible by 100 is a leap year only if it is divisible by 400. Your program should accept the month, day, and year as integers. Include a function leap() that returns 1 if called with a leap year, 0 otherwise.