Scis.regis.edu ● CS-361: Control Structures Week 6 Dr. Jesús Borrego Lead Faculty, COS Regis University 1.

Slides:



Advertisements
Similar presentations
Repetition Control Structures
Advertisements

Chapter 4 Loops Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X.
Display a 12-Month Calendar CS-2301 D-term Programming Assignment #2 12-Month Calendar CS-2301 System Programming C-term 2009 (Slides include materials.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
11.3 Function Prototypes A Function Prototype contains the function’s return type, name and parameter list Writing the function prototype is “declaring”
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
CMPUT 101 Lab #6 October 29, :00 – 17:00. Array in C/C++ Array is a structure type variable. One dimension of array int: int num[3]; There are.
Loops – While, Do, For Repetition Statements Introduction to Arrays
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
1 Lab Session-6 CSIT-121 Spring 2005 Structured Choice The do~While Loop Lab Exercises.
Chapter 5: Control Structures II (Repetition)
CSCI/CMPE 4341 Topic: Programming in Python Chapter 3: Control Structures (Part 1) – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
1 Lab Session-7 CSIT-121 Fall Introducing Structured Choice 4 The do~While Loop 4 Lab Exercises.
Assignment #2, 12- month Calendar CS-2301, B-Term Programming Assignment #2 12-Month Calendar CS-2301, System Programming for Non-Majors (Slides.
COMP 110 Introduction to Programming Mr. Joshua Stough September 24, 2007.
CS1101: Programming Methodology Aaron Tan.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 5: Control Structures II (Repetition)
Presented by Joaquin Vila Prepared by Sally Scott ACS 168 Problem Solving Using the Computer Week 12 Boolean Expressions, Switches, For-Loops Chapter 7.
CSC 1051 M.A. Papalaskari, Villanova University Repetition CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing.
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Looping Exercises Deciding Which Loop to Use At this.
Chapter 5: Control Structures II (Repetition)
CHAPTER 5: CONTROL STRUCTURES II INSTRUCTOR: MOHAMMAD MOJADDAM.
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
CNG 140 C Programming (Lecture set 9) Spring Chapter 9 Character Strings.
1 Lab Session-8 CSIT-121 Spring 2005 Call by Reference Lab Exercise for Demo Practice Problems.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 4 Loops.
CS 108 Computing Fundamentals Notes for Thursday, February 19, 2015.
Previously Repetition Structures While, Do-While, For.
Chapter 5: Control Structures II (Repetition). Objectives In this chapter, you will: – Learn about repetition (looping) control structures – Learn how.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
Chapter 4: Control Structures II
Repetition Control Structures Simple Program Design Third Edition A Step-by-Step Approach 5.
Control Structures Repetition or Iteration or Looping Part II.
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)
© Copyright 2013 by Pearson Education, Inc. All Rights Reserved.1 Chapter 5 Loops.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Homework #2: Functions and Arrays By J. H. Wang Mar. 20, 2012.
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.
REPETITION STATEMENTS - Part2 Structuring Input Loops Counter-Controlled Repetition Structure Sentinel-Controlled Repetition Structure eof()-Controlled.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Homework #2: Functions and Arrays By J. H. Wang Mar. 24, 2014.
Scis.regis.edu ● CS-361: Control Structures Week 2 Dr. Jesús Borrego Lead Faculty, COS Regis University 1.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 5: Control Structures II (Repetition)
© The McGraw-Hill Companies, 2006 Chapter 3 Iteration.
Exception Handling and String Manipulation. Exceptions An exception is an error that causes a program to halt while it’s running In other words, it something.
CISC105 – General Computer Science Class 4 – 06/14/2006.
CS1010: Programming Methodology
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
While loops. Iteration We’ve seen many places where repetition is necessary in a problem. We’ve been using the for loop for that purpose For loops are.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 11 GEORGE KOUTSOGIANNAKIS 1 Copyright: 2015 Illinois Institute of Technology_ George Koutsogiannakis.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 5: Control Structures II (Repetition)
Chapter 4 Repetition Statements Program Development and Design Using C++, Third Edition.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Introduction to Loop. Introduction to Loops: The while Loop Loop: part of program that may execute > 1 time (i.e., it repeats) while loop format: while.
Control Structures Repetition or Iteration or Looping Part II.
Introduction to Computer Programming
Topic 4: Looping Statements
REPETITION CONTROL STRUCTURE
Chapter 5: Control Structures II (Repetition)
Engineering Problem Solving with C++, Etter/Ingber
Repetition.
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
OBJECT ORIENTED PROGRAMMING I LECTURE 11 GEORGE KOUTSOGIANNAKIS
Chapter 5: Control Structures II (Repetition)
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Presentation transcript:

scis.regis.edu ● CS-361: Control Structures Week 6 Dr. Jesús Borrego Lead Faculty, COS Regis University 1

Topics Homework #4 review Key Terms Chapter 5 (pp ) ▫Programs using loops and sample programs Activity 1 Chapter 7 (pp ) ▫Functions and file processing Homework #5 2

Homework 4 Review Program 8, page 359 in the textbook Use coding standards Must implement at least 4 functions Review inputs and outputs Submit Word documentation Submit to WorldClass/Desire to Learn before week 6 3

Key Terms Compound statements – sentencias compuestas Nested IF – IF anidado Order of precedence – órden de precedencia Short circuit evaluation – evaluación cortocircuito 4

scis.regis.edu ● C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 5: Control Structures II (Repetition) Chapter 7: User Defined Functions II 5

Problem Would like to write a program that asks a user for a large integer number (> 0) The program would then print the digits in reverse order The program must read the number as integer and NOT convert to string Must use at least one function 6

Define the algorithm to be used Together in class: Prompt user for number and verify it is > 0 Process the number evaluating the right most digit and display it to the screen Move the index to the next number from the right until we run out of numbers 7

Solution ReverseDigit0 ReverseDigit1 ReverseDigit2 Convert ReverseDigit2 to use DO WHILE ▫How do we convert from WHILE to DO WHILE?  ReverseDigit3 8

Odd or Even? Write a program that receives an integer and determines if it is ODD or EVEN Program OddEven.cpp 9

Count lines and characters in a file Write a program that asks the user for a file name ▫Ensures file exists Reads the file one character at a time ▫Counts number of lines and characters in file Asks the user if the program should run again 10

Solution CountLinesInFile Program Highlights ▫Note validation for answer (Continue, validAns) ▫Note while (More) to determine if user wants to continue ▫Note DoWhile to process the file ▫Note adjustment of characters to account for EOF character ▫Note call to runAgain 11

What is a Prime number? 12

Activity 1 As a single group in class: ▫Write a program to print the prime numbers between 1 and n, where n is received from user ▫Write algorithm on the whiteboard ▫Write pseudocode on the whiteboard ▫Write the program and test it ▫Upload to WorldClass (Week 6) with names of team members Time: 1 hour ListOfPrimes.cpp 13

Review of Char and String functions CharFunctions.cpp Palindrome ▫A string is a Palindrome if it is the same read backwards or forwards  palindrome-words-sentences html palindrome-words-sentences html ▫Write a program that determines if a sentence is a palindrome or not PalindromeNoRec.cpp 14

Find a character in a string Want to enter a string with no spaces Want to see if a character is present in the string FindCharInString.cpp See StrFunctions.cpp – array of char See StrFunctions1.cpp for string equivalent ▫See different way of handling  Strings versus array of characters 15

Activity 2 Write a program to accomplish the following: ▫Asks the user for a double number with at least 5 digits ▫Includes a function that receives a double number and displays the number of odd, even, and zero digits in the number ▫Includes a function to ask the user to enter a number with at least five digits ▫Calls both functions ▫Test with at least 3 numbers 16

Activity 2 (Continued) Test your program and capture the output Do not worry about coding standards Submit to WorldClass (Week 6) Time: 45 minutes 17

Homework #5 Write a program that asks the user for a file name The program reads the file a character at a time The program will count the following: ▫Number of characters ▫Number of lines ▫Number of digits ▫Number of special characters ▫Number of vowels ▫Number of consonants The program will allow the user to try again 18

Homework #5 (Continued) Program must clear counters after each file is read Test your program with the programs you created for Homework 3 and 4 Follow coding standards Review input and output ▫Capture output of each execution ▫One of the execution must be for invalid file name Submit to WorldClass before week 8 19