Session 19 csit 121 spring 2006
Download
1 / 8

Session-19 CSIT 121 Spring 2006 - PowerPoint PPT Presentation


  • 118 Views
  • Uploaded on

Session-19 CSIT 121 Spring 2006. Count controlled loops can be implemented with for statement This statement becomes the loop header for (lcv=initial value; lcv<=final value; lcv modification statement)

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Session-19 CSIT 121 Spring 2006' - tamira


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Session 19 csit 121 spring 2006
Session-19 CSIT 121 Spring 2006

  • Count controlled loops can be implemented with for statement

  • This statement becomes the loop header

  • for (lcv=initial value; lcv<=final value; lcv modification statement)

  • For example; we have to evaluate factorial of a number. If we use a for loop, it will be quick and simple


Count controlled nested loops
Count Controlled Nested Loops

  • You can embed loops within loops (nested loops)

  • It may be useful when processing data in separate categories

  • The task may be performing repetitive operations and the task itself may be repetitive

  • Example: A program displays multiplication tables for numbers 1 through 10 as on the next page

  • A clock is incrementing seconds and after 60 seconds it increments minutes and after 60 minutes, it increments hours. Thus it is performing repetitive operations.



Lab demo due april 11th
Lab Demo Due April 11th

  • Design a program that simulates a digital clock. When the program starts running, it displays the following time:

  • 00:00:00

  • Later, the program starts changing the time just like a clock would do. For example, the next display would be:

  • 00:00:01


Help familiar format
Help: Familiar Format

  • Instead of using Sleep() function with a changed format of the program, you may want to waste about one second with this idle loop. Plug it in to your program where you need the delay of one second:

  • for (int j=0; j<500000000; j++);

  • system("cls"); //to clear the screen


Help unfamiliar format
Help: Unfamiliar Format

  • Instead of :

    • #include <iostream>

    • #include <iomanip>

    • Using namespace std;

  • Use the following directives (Old C Style):

    • #include <stdio.h>

    • #include <windows.h>

    • #include <iomanip.h>

  • Then use the following line to sleep for one second:

  • Sleep(1000);


  • Help both formats
    Help: Both Formats

    • You also need the following statements to set the format of your output:

    • cout.setf(ios::fixed | ios::right);

    • cout.fill('0'); //leading zeroes displayed


    Practice exercises
    Practice Exercises

    • Warm up exercise 1 Page 299

    • Warm up exercise 6 Page 300

    • Warm up exercise 12 Page 300


    ad