Homework #2: Functions and Arrays By J. H. Wang Mar. 24, 2014.

Slides:



Advertisements
Similar presentations
Contest format 5 hours, around 8-12 problems One computer running (likely)Linux, plus printer 3 people on one machine No cell phones, calculators, USB.
Advertisements

1 Various Methods of Populating Arrays Randomly generated integers.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7- 1 Overview 7.1 Introduction to Arrays 7.2 Arrays in Functions 7.3.
Homework #2: Functions and Arrays
CS102--Object Oriented Programming Discussion 2: (programming strategy in java) – Two types of tasks – The use of arrays Copyright © 2008 Xiaoyan Li.
实验11.28.
Hand Crafting your own program By Eric Davis for CS103.
Chapter 10.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 14 – Student Grades Application: Introducing.
Introduction to Analysis of Algorithms
1 ICS102: Introduction To Computing King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
Assemblers Dr. Monther Aldwairi 10/21/20071Dr. Monther Aldwairi.
Designing Algorithms Csci 107 Lecture 3. Designing algorithms Last time –Pseudocode –Algorithm: computing the sum 1+2+…+n –Gauss formula for 1+2+…+n Today.
1 Lab Session-XIV CSIT121 Spring 2002 b Namespaces b First Class Travel b Lab Exercise 14 (Demo) b Lab Exercise b Practice Problem.
Computer Science 1620 Programming & Problem Solving.
Principles of Procedural Programming
Programming is instructing a computer to perform a task for you with the help of a programming language.
1 Project 5: Median. 2 The median of a collection of numbers is the member for which there are an equal number less than or equal and greater than or.
Variables, Data Types and Constants Yared Semu Addis Ababa Institute of Technology Mar 31, 2012.
Programming Languages -1 (Introduction to C) arrays Instructor: M.Fatih AMASYALI
Foundations of Computer Science Computing …it is all about Data Representation, Storage, Processing, and Communication of Data 10/4/20151CS 112 – Foundations.
1 Data Structures A Data Structure is an arrangement of data in memory. A Data Structure is an arrangement of data in memory.  The purpose is to map real.
11 Chapter 5 METHODS CONT’D. 22 MORE ON PASSING ARGUMENTS TO A METHOD Passing an Object Reference as an Argument to a Method Objects are passed by reference.
First tutorial.
1 7.Algorithm Efficiency What to measure? Space utilization: amount of memory required  Time efficiency: amount of time required to process the data Depends.
Homework #3: Classes and Constructors
Announcements Final NEXT WEEK (August 13 th Thursday at 16:00) Recitations will be held on August 12 th Wednesday We will solve sample final questions.
Introduction to Programming (in C++) Loops Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Homework #4: Operator Overloading and Strings By J. H. Wang May 8, 2012.
1 7.Algorithm Efficiency What to measure? Space utilization: amount of memory required  Time efficiency: amount of time required to process the data.
Practice and Evaluation. Practice Develop a java class called: SumCalculator.java which computes a sum of all integer from 1 to 100 and displays the result.
Implementation of the Hangman Game in C++
Data Structures and Algorithms Introduction to Algorithms M. B. Fayek CUFE 2006.
IR Homework #2 By J. H. Wang Mar. 31, Programming Exercise #2: Query Processing and Searching Goal: to search relevant documents for a given query.
Calculations Chapter 11 Library of math functions, and constants cos, sin, tan, abs, min, max, log, random, sqrt, pow, exp Constants.PI,.E Use care with.
1 Building Java Programs Chapter 7: Arrays These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold, or.
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)
Two-Dimensional Arrays That’s 2-D Arrays Girls & Boys! One-Dimensional Arrays on Steroids!
1 Flight Times. 2 Problem Specification 3 Additional Specifications You may assume that the input is a valid 24 hour time. Output the time entered by.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
CS140: Intro to CS An Overview of Programming in C by Erin Chambers.
Scis.regis.edu ● CS-361: Control Structures Week 6 Dr. Jesús Borrego Lead Faculty, COS Regis University 1.
IR Homework #1 By J. H. Wang Mar. 5, Programming Exercise #1: Indexing Goal: to build an index for a text collection using inverted files Input:
ITI 1120 Lab #5 Contributors: S. Boyd, R. Plesa, A. Felty, D. Inkpen, A. Williams, D. Amyot.
Homework #2: Functions and Arrays By J. H. Wang Mar. 20, 2012.
EXERCISE Arrays, structs and file processing. Question You own a pet store. You want to keep an inventory of all the pets that you have. Pets available.
Homework #1: C++ Basics, Flow of Control, and Function Basics By J. H. Wang Mar. 13, 2012.
Control of flow We learned that default flow of instructions is sequential. Then, we learned how to control the flow using "if" and "switch." Now, we will.
Homework #4: Operator Overloading and Strings By J. H. Wang Apr. 17, 2009.
Intermediate 2 Computing Unit 2 - Software Development.
Function Overloading Two different functions may have the same name as long as they differ in the number or types of arguments: int max(int x, int y) and.
Homework #1: C++ Basics, Flow of Control, and Function Basics
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
Programming Fundamentals I Java Programming Spring 2009 Instructor: Xuan Tung Hoang TA: Tran Minh Trung Lab 03.
Homework #3: Classes and Constructors By J. H. Wang Apr. 14, 2014.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
Homework #5: Pointers, Dynamic Arrays and Inheritance By J. H. Wang Jun. 5, 2009.
Functions Structured Programming. Topics to be covered Introduction to Functions Defining a function Calling a function Arguments, local variables and.
Computer Programming for Engineers
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
Homework #3: Classes and Constructors
Homework #3: Classes and Constructors By J. H. Wang Apr. 24, 2015.
L AB 4 July 5th. F OR LOOP Exercise 1: Find two ways of “Summing all 1, 2, and 3 digit prime numbers.” Use for loop Hint: isprime, primes.
Recursion in Java The answer to life’s greatest mysteries are on the last slide.
CSC 212 – Data Structures Lecture 15: Big-Oh Notation.
Homework 1 (due:April 13th) Deadline : April 13th 11:59pm Where to submit? eClass 과제방 ( How to submit? Create a folder. The name.
© 2016 Pearson Education, Ltd. All rights reserved.
IPC144 Introduction to Programming Using C Week 2 – Lesson 1
Arrays.
Presentation transcript:

Homework #2: Functions and Arrays By J. H. Wang Mar. 24, 2014

Programming Exercises 1.Your time machine is capable of going forward in time up to 24 hours. The machine is configured to jump ahead in minutes. To enter the proper number of minutes into your machine, you would like a program that can take a start time and an end time and calculate the difference in minutes between them, The end time will always be within 24 hours of the start time. Use military notation for both the start and end time (e.g., 0000 for midnight and 2359 for one minute before midnight). [… to be continued on the next slide…]

[… continued from the previous slide …] Write a function that takes as input a start time and an end time represented as an int, using military notation. The function should return the difference in minutes as an integer. Write a C++ program that calls your function with times entered by the user. (Hint : Be careful of time intervals that start before midnight and end the following day.)

2.An array can be used to store large integers one digit at a time. For example, the integer 1234 could be stored in the array a by setting a[0] to 1, a[1] to 2, a[2] to 3, and a[3] to 4. However, for this exercise you might find it more useful to store the digits backward, that is, place 4 in a[0], 3 in a[1], 2 in a[2], and 1 in a[3]. [… to be continued on the next slide …]

[… continued from the previous slide …] In this exercise you will write a program that reads in two positive integers that are 20 or fewer digits in length and then outputs the sum of two integers. You program will read the digits as values of type char so that the number 1234 is read as the four characters ‘1’, ‘2’, ‘3’, and ‘4’. After they are read into the program, the characters are changed to values of type int. [… to be continued on the next slide …]

[… continued from the previous slide …] The digits will be read into a partially filled array, and you might find it useful to reverse the order of the elements in the array after the array is filled with data from the keyboard. Your C++ program will perform the addition by implementing the usual paper-and-pencil addition algorithm. The result of the addition is stored in an array of size 20 and the result is then written to the screen. [… to be continued on the next slide …]

[… continued from the previous slide …] If the result is an integer with more than the maximum number of digits (that is, 20), then your program should issue a message saying that it has encountered “integer overflow.” You should be able to change the maximum length of integers by changing only one globally defined constant. Include a loop that allows the user to continue to do more additions until the user says the program should end.

3.Use a one-dimensional array to solve the following problem. Write a function to check if a given array of integers contains a duplicate with other numbers in the array. Then, the function should store only the unique values into another array as an array parameter. Also, the number of unique values has to be returned via a call-by- reference parameter. (a) Write a C++ program that allows the user to test the function, and display the output of the array after duplicate elimination. (b) Suppose the integers represent scores between 0 and 100, inclusive. Please design a more efficient function to do the duplicate elimination, and test the function in your program.

Homework Submission Due: 2 weeks (Apr. 7, 2014) Submission instructions: – – File names : Please name your file according to our homework. For example, _HW1.zip or _quiz2.rar

Questions or Comments?