Review the following : Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops.

Slides:



Advertisements
Similar presentations
While Loops Programming. COMP102 Prog Fundamentals I: while Loops/Slide 2 Shortcut Assignments l C++ has a set of shortcut operators for applying an operation.
Advertisements

1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Do/while Structure (L15) * do/while structure * break Statement * continue Statement * Loop Programming Techniques - Interactive input within a loop -
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/28/07CS150 Introduction to Computer Science 1 Loops section 5.2, 5.4, 5.7.
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.
CS150 Introduction to Computer Science 1
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
CS 1400 Chapter 5, section 2. Loops! while (rel-expression)while (rel-expression) {statements statement } if the relational-expression is true, execute.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Functions Outline 3.12Recursion 3.13Example Using Recursion: The Fibonacci Series 3.14Recursion.
1 9/08/06CS150 Introduction to Computer Science 1 Arithmetic Operators.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
What is the out put #include using namespace std; void main() { int i; for(i=1;i
Introduction to C++ Programming
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
 Write a program that uses a one dimension to do a table look-up  Learn about parallel arrays.
1 Copyright (C) 2008 by Dennis A. Fairclough all rights reserved.
 2003 Prentice Hall, Inc. All rights reserved. 1 Functions and Recursion Outline Function Templates Recursion Example Using Recursion: The Fibonacci Series.
 Review structures  Program to demonstrate a structure containing a pointer.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 4: Continuing with C++ I/O Basics.
More on Input Output Input Stream : A sequence of characters from an input device (like the keyboard) to the computer (the program running). Output Stream.
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
Chapter 02 (Part III) Introduction to C++ Programming.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Loop.  While Loop  Do-while Loop  For Loop Continue Statement Conclusion Loop Loop.
Review the following: if-else One branch if Conditional operators Logical operators Switch statement Conditional expression operator Nested ifs if –else.
GAME102 - INTRO WHILE LOOPS G. MacKay. Fundamental Control Structures  STRAIGHT LINE  CONDITIONAL  LOOPS.
111/15/2015CS150 Introduction to Computer Science 1 Summary  Exam: Friday, October 17,  Assignment: Wednesday, October 15, 2003  We have completed.
Overview Go over parts of quiz? Another iteration structure for loop.
C++ Programming Lecture 7 Control Structure I (Selection) – Part II The Hashemite University Computer Engineering Department.
 for loop  while loop  do-while loop for (begin point; end point ; incrementation ) { //statements to be repeated }
1 For Loops l From Chapter 9 l A shorthand way of coding count loops.
Fundamental Programming Fundamental Programming More on Repetition.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
CSC1201: Programming Language 2 1 Functions. 2 Function declaration: return_type FuncName( Type arg1, Type arg2,….. Type argN) { function body } A program.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 2 September 3, 2009.
 Memory setup  Pointer declaration  Address operator  Indirection  Printing addresses or pointers.
Selection Control Structures 2 (L09) * Nested if Statements * The if-else Chain * Exercise: if, if-else, nested if, and if-else chain Selection Control.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
Lesson xx Why use functions Program that needs a function Function header Function body Program rewritten using a function.
Loop Design What goes into coding a loop. Considerations for Loop Design ● There are basically two kinds of loops: ● Those that form some accumulated.
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
Infinite for Loop If you omit the test condition, the value is assumed to be TRUE so the loop will continue indefinitely unless you provide some other.
1 Chapter 4 - Control Statements: Part 1 Outline 4.1 Introduction 4.4 Control Structures 4.5 if Selection Structure 4.6 if/else Selection Structure 4.7.
CHAPTER 2.2 CONTROL STRUCTURES (ITERATION) Dr. Shady Yehia Elmashad.
Introduction to Computer Programming
while Repetition Structure
生查子 ~ 歐陽修 去年元夜時,花市燈如晝, 月上柳梢頭,人約黃昏後; 今年元夜時,月與燈依舊, 不見去年人,淚濕春衫袖。
Two-Dimensional Arrays Lesson xx
CSC113: Computer Programming (Theory = 03, Lab = 01)
Programming Fundamentals
Repetition Statements
Returning Structures Lesson xx
One-Dimensional Array Introduction Lesson xx
File I/O with Records Lesson xx
Passing Structures Lesson xx
Value returning Functions
Counting Loops.
Let’s all Repeat Together
Alternate Version of STARTING OUT WITH C++ 4th Edition
Programs written in C and C++ can run on many different computers
Statements and flow control
do/while Selection Structure
Fundamental Programming
Capitolo 1 – Introduction C++ Programming
Repetition Statements (Loops) - 2
The switch Statement When we want to compare a variable against several values to see which one it has, we can use the switch statement: switch (status)
Presentation transcript:

Review the following : Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops

Read in a year and determine if it is a leap year. A leap year is a year that is evenly divisible by 4 and not by 100. Or, a year that is evenly divisible by 400 is also a leap year.

Prompt Read in year Leap Year? Is not leap year Is leap year End Start TF

//Helen Kow CS 265 Program #1 //This program tells you if a year is a leap year or not #include "stdafx.h" #include using std::cin; using std::cout; using std::endl; int main() { int year, rem4, rem100, rem400; cout <<"Enter a year "; cin>> year; rem4 = year%4; rem100 = year %100; rem400 = year % 400; if ( rem4 == 0 && rem100 != 0 || rem400 == 0) cout << endl << year << " is a leap year " << endl; else cout << endl << year << " is not a leap year \n“; return 0; }

//Helen Kow CS 265 Program #1 //This program tells you if a year is a leap year or not

#include "stdafx.h" #include using std::cin; using std::cout; using std::endl;

int main() { //code goes here return 0; }

int year, rem4, rem100, rem400; year rem4 rem400 rem100

cout <<"Enter a year "; cin>> year; 2018 year rem4 rem400 rem100

rem4 = year%4; rem100 = year %100; rem400 = year % 400; year rem4 rem400 rem100

if ( rem4 == 0 && rem100 != 0 || rem400 == 0) cout << endl << year << " is a leap year " << endl; else cout << endl << year << " is not a leap year \n“; year rem4 rem400 rem100

Read in a year and determine if it is a leap year. A leap year is a year that is evenly divisible by 4 and not by 100. Or, a year that is evenly divisible by 400 is also a leap year. Allow the user to repeat the program as many times as they desire.

While condition is true Code to be repeated _ _ _ _ _ _ _ _ _ _ _ _ | | | | | | | | |_ _ _ _ _ _ _ _ _

do { //code to be repeated } while (some condition is true );

Prompt Read in year Leap Year ? Is not leap year Is leap year Start End Play again? while again == true _ _ _ _ _ _ _ _ _ _ _ _ _ |||||||||||||||||||||||||||||||||| _ _ _ _ _ _ Flowchart with loop

//Helen Kow CS 265 Program #1 //This program tells you if a year is a leap year or not #include "stdafx.h" #include using std::cin; using std::cout; using std::endl; int main() { int year, rem4, rem100, rem400; char again; do { cout <<"Enter a year "; cin>> year; rem4 = year%4; rem100 = year %100; rem400 = year % 400; if ( rem4 == 0 && rem100 != 0 || rem400 == 0) cout << endl << year << " is a leap year " << endl; else cout << endl << year << " is not a leap year " << endl; cout << "\nPlay again ?? "; cin >> again; } while (again == 'y'); return 0; } 1 2 3

Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops