Parker Series Set One By John B. Owen All rights reserved ©2011.

Slides:



Advertisements
Similar presentations
Lesson 6D – Loops and String Arrays – split process By John B. Owen All rights reserved ©2011.
Advertisements

Lesson 9 – Matrices By John B. Owen All rights reserved ©2011.
Lesson 6A – Loops By John B. Owen All rights reserved ©2011.
§3 Dynamic Programming Use a table instead of recursion 1. Fibonacci Numbers: F(N) = F(N – 1) + F(N – 2) int Fib( int N ) { if ( N
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Fundamentals of Computer Science Lecture 14: Recursion Instructor: Evan Korth New York University.
Bioinformatics: A New Experience By Emmy Niroula.
Computer Science II Recursion Professor: Evan Korth New York University.
General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.
Computer Science 1620 Loops.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
Fundamentals of Computer Science Lecture 14: Recursion Instructor: Evan Korth New York University.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
1 10/11/06CS150 Introduction to Computer Science 1 do/while and Nested Loops.
General Computer Science for Engineers CISC 106 Final Exam Review Dr. John Cavazos Computer and Information Sciences 05/18/2009.
Recursion Road Map Introduction to Recursion Recursion Example #1: World’s Simplest Recursion Program Visualizing Recursion –Using Stacks Recursion Example.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
Recursion Recitation – 11/(6,7)/2008 CS 180 Department of Computer Science, Purdue University.
Chapter 15 Recursive Algorithms. 2 Recursion Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
COMP 110 Introduction to Programming Mr. Joshua Stough September 24, 2007.
Computer Science 1620 Lifetime & Scope. Variable Lifetime a variable's lifetime is finite Variable creation: memory is allocated to the variable occurs.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 5 – Recursive Funtions From Deitel’s “C” Book 5.13Recursion 5.14Example Using Recursion: The Fibonacci.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
Lesson 6C – Loops 3 – Advanced File Processing By John B. Owen All rights reserved ©2011.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
 For Loops › for (variable set; condition; incremental or decrement){ // loop beginning › } // loop end  While loops › while (condition) { // beginning.
CS1010E Programming Methodology Tutorial 3 Control Structures and Data Files C14,A15,D11,C08,C11,A02.
Python Programming Chapter 6: Iteration Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
My goals were to: To be a more effective listener Opinionated More Open Minded Open up more to the class Not just for the sake of being heard Have something.
Collecting Things Together - Lists 1. We’ve seen that Python can store things in memory and retrieve, using names. Sometime we want to store a bunch of.
CS50 Week 2. RESOURCES Office hours ( Lecture videos, slides, source code, and notes (
CSE 501N Fall ‘09 12: Recursion and Recursive Algorithms 8 October 2009 Nick Leidenfrost.
CSC 107 – Programming For Science. The Week’s Goal.
Loops Wrap Up 10/21/13. Topics *Sentinel Loops *Nested Loops *Random Numbers.
Methods We write methods in our programs for many reasons:
1 CS161 Introduction to Computer Science Topic #9.
Week 8: Decisions Bryan Burlingame 21 October 2015.
Computers, Variables and Types Engineering 1D04, Teaching Session 2.
Lecture 04 – Models of memory Mutable and immutable data.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 8: Recursion Presentation slides for Java Software Solutions for AP* Computer Science 3rd.
Before we get started…. First, a few things… Weighted Grading System Programming Style Submitting your assignments… The char and string variable types.
1 CS161 Introduction to Computer Science Topic #8.
Variables and Expressions CMSC 201. Today we start Python! Two ways to use python: You can write a program, as a series of instructions in a file, and.
© A+ Computer Science - A reference variable stores the memory address of an object. Monster fred = new Monster(); Monster sally.
Computer Science: A Structured Programming Approach Using C1 6-6 Loop Examples This section contains several short examples of loop applications. Each.
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
COMP Loop Statements Yi Hong May 21, 2015.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
1 Recursive Definitions and Structural Induction CS/APMA 202 Rosen section 3.4 Aaron Bloomfield.
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
Nested Loops CS303E: Elements of Computers and Programming.
© A+ Computer Science - Magpie Magpie is a lab that focuses on classes, randomness, and Strings. This lab will make sure that you.
Trace Tables In today’s lesson we will look at:
Object-Oriented programming for Beginners LEAPS Computing 2015
Introduction to Recursion
© A+ Computer Science - Magpie Chatbot Lab © A+ Computer Science -
Topics discussed in this section:
Error Handling Summary of the next few pages: Error Handling Cursors.
Chapter 5: Arrays: Lists and Tables
Learning about Programming Languages
More Nested Loops and Lab 5
One-Dimensional Array Introduction Lesson xx
The best teacher In the whole sea created by Eddie Boudreaux
Module 4 Loops.
Recursion Taken from notes by Dr. Neil Moore
INC 161 , CPE 100 Computer Programming
Two other people.
Presentation transcript:

Parker Series Set One By John B. Owen All rights reserved ©2011

Preface Lab1A – Alpha Triangle Lab1B – Star Triangles Lab1B – Star Triangles Lab1C – Pascals Triangle Lab1D – Fibonacci Loop Lab1E – Fibonacci Recursion Lab1F – Call Me Today Lab1G– Merge Files Acknowledgement of use Table of Contents Parker Series Set One2

Preface This lab set is the first among several originally developed by the late Marjorie L. Parker, my original mentor in computer science. Marge taught for several years at Cypress Creek High School (Northwest Houston area) in the 1980s and 1990s and was instrumental in helping me learn the ropes, first with Pascal, and then C++. She was generous and kind, always willing to help, and a brilliant mind and teacher. Her legacy lives on in my teaching, as well as in the many students and teachers she affected throughout her life. This series is dedicated to her memory and for all the help she gave me in the early days. Thanks, Marge! Parker Series Set One3

The purpose of this set is to review all of the basic skills you have learned so far. It reviews loops, nested loops, if, if else, and string processing, file processing, and recursion, just a few among several important concepts. Objective. Parker Series Set One4

Your are not required to use OOP (Object Oriented Programming) techniques, but are certainly welcome to do so if you wish to practice those as well. Objective. Parker Series Set One5

WAP (write a program) to print the following triangle using a nested loop process: a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j Lab P1A – Alpha Triangle Parker Series Set One6

This process will require a row loop and a column loop, and a separate char variable to output the letters of the alphabet as shown. a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j Lab P1A – Alpha Triangle Parker Series Set One7

Notice carefully that the letters start again when z is reached, so youll need an if statement somewhere in the code to make this happen. a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j Lab P1A – Alpha Triangle Parker Series Set One8

Here s something to help you get started. int r,c; char a = a; for(r=0;r<8;r++) { for(c=0;c<=__;c++) { out.print(__); if(_____) _____; } out.println(); } Lab P1A – Alpha Triangle Parker Series Set One9

WAP that will input 2 integers, N and R, from a data file ( labP1B.dat ). N is the number of triangles and R is the number of rows of asterisks per triangle to be printed (nested loop process). If N=2 and R=4, the output would be: * * * * * * * * * * * * Lab P1B – Star Triangles Parker Series Set One10

This process will require a triple nested loop structure, one for the two triangles, the next for the rows of each triangle, and then the third for the columns of each row. Good luck! * * * * * * * * * * * * Lab P1B – Star Triangles Parker Series Set One11

WAP to print the following pyramid of digits, commonly known as Pascals triangle, spaced exactly as shown. The output must be the a result of an algorithm (another nested loop), not hard-coding Lab P1C – Pascals Triangle Parker Series Set One12

You must first calculate and store the values in an integer matrix, with the values calculated, not just hand-stored. Note that each inner value is the sum of the two values directly above it Lab P1C – Pascals Triangle Parker Series Set One13

It might help to visualize the matrix in a normal fashion, as you see below Lab P1C – Pascals Triangle Parker Series Set One14

To build it, first initialize the first column and diagonal values to 1, then loop through and calculate the inner values of the triangle. Ignore the outside zeroes Lab P1C – Pascals Triangle Parker Series Set One15

When you have finished building the matrix, proceed to the output phase of this program Lab P1C – Pascals Triangle Parker Series Set One16

Note carefully that the spacing distance from one number to the next is always four spaces. Hint: printf has a very nice way of doing this! Lab P1C – Pascals Triangle Parker Series Set One17

The indent distance decreases by two for each row, starting with ten spaces for the first row, then 8, and so on Lab P1C – Pascals Triangle Parker Series Set One18

This indent distance must by dynamically calculated for each row. Hint: use the row number somehow to do this calculation. Do not manually start with 10! That is considered hard-coding…strictly verboten! Lab P1C – Pascals Triangle Parker Series Set One19

Here s something to help you get started. int [][] grid = new int[6][6]; int r,c; //initialize first column and diagonal for(r=0;r<grid.length;r++) { grid[r][0]=1; grid[r][?]=1;} //now calculate the inner values for(r=2;r<___;r++) { for(c=1;c<=__;c++) { grid[?][?] = ????; } //now output the triangle…have fun! Lab P1C – Pascals Triangle Parker Series Set One20

WAP to output the first 16 numbers in the Fibonacci sequence You must use a loop that calculates each value! … Lab P1D – Fibonacci Loop Parker Series Set One21

WAP to output the first 16 numbers in the Fibonacci sequence You must use a recursive method to calculate and output the values! … Lab P1E – Fibonacci Recursion Parker Series Set One22

Given a file of 10-digit telephone numbers, some with 10 digits, some letters, and some mixed, WAP to convert the telephone numbers with letters to 7 digits. Save the new telephone numbers in a file that is different from the input data file. Print a table containing two columns - the original telephone number and the corresponding new telephone number. Sample input: 512WA D CALLMETODAY Lab P1F – Call Me Today Parker Series Set One23

Note that only ten digits are used in the final number, even though a word-based number exceeds ten digits. Sample input: (data file: labp1e.dat) 512WA D CALLMETODAY Resulting output: Lab P1F – Call Me Today Parker Series Set One24

Given 2 files of first names arranged alphabetically, create a third file consisting of these two files merged and still in alphabetical order. Print out and turn in all three files and your source code, in this order…output file, two input files, source code. Sample input: Data file1: labp1fa.dat BUDDHA GABBY RICHEY ZACK Data file2: labp1fb.dat BEN JAMIE KEGAN MADDIE ZACH Resulting output file: BEN BUDDHA GABBY JAMIE KEGAN MADDIE RICHEY ZACH ZACK Lab P1G – Merge Files Parker Series Set One25

Hint: You will need two Scanner objects, one each for the two input files, and a PrintWriter object for the output file. Review the input file processing techniques in Lesson 6C. To output to a file, examine carefully the program segment shown below. PrintWriter pw = new PrintWriter(new FileWriter(labp1f.out)); pw.println(Hello); //put your processing statements //here and use the pw object to //write data to the file pw.close(); //It is very important to close the file, //otherwise it will not contain what you put //there. Lab P1G – Merge Files Parker Series Set One26

You have now reviewed many important skills for basic data processing. CONGRATULATIONS! Parker Series Set One27

Please copy, paste, and customize the brief acknowledgement shown below in an to indicating that you used this lesson. Feel free to include any comments you wish to offer, positive or negative. I, (your name), from (educational institution) in (city, state, country) used Parker Series Set 1 on (date), understand, respect and honor all of the rights claimed by the author, Mr. John Owen, and offer the following comments..._______________. THANK YOU! Acknowledgement of use Parker Series Set One28