Case studies over control structures and iterative structures - PowerPoint PPT Presentation

case studies over control structures and iterative structures n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Case studies over control structures and iterative structures PowerPoint Presentation
Download Presentation
Case studies over control structures and iterative structures

play fullscreen
1 / 7
Case studies over control structures and iterative structures
136 Views
Download Presentation
denzel
Download Presentation

Case studies over control structures and iterative structures

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Case studies over control structures and iterative structures Instructor – GokcenCilingir Cpt S 121 (July 6, 2011) Washington State University

  2. Problem 1 • Problem statement: Calculate number of digits in an integer. Prompt the user for an integer and output the number of digits Sample I/O: Input: 123, Output: 3 Input: 123456, Output: 6 Input: 0, Output: 1

  3. Problem 1 – another related application • Problem statement: Print a given integer such that its digits are reversed. Sample I/O: Input: 123, Output: 321 Input: 123456, Output: 654321 Input: 0, Output: 0

  4. Problem 1 – another related application • Problem statement: Calculate the integer that has the reversed digits of a given integer. • Prompt the user for an integer and output the reversedInteger and reversedInteger *2 Sample I/O: Input: 123, Output: 321, 642 Input: 123456, Output: 654321, 1308642 Input: 0, Output: 0, 0

  5. Problem 2 • Problem statement: Write a program that experiments with the random number generation function rand() of C. Program should prompt user for sample size, and calculates the average of random numbers generated for the given sample size. • Generate random numbers between [0, 10] and observe that average will be closer to 5.0 when your sample size increases.

  6. Problem 3 • Problem statement: Write a program that reads and flattens a text file. • Assume file contains words (which are comprised by alphanumeric characters) separated by whitespace and punctuation characters. • Program should flatten the file, meaning should output the word list to an output file in the order of encounter, ignoring whitespace & punctuation, separating them by newline characters. • If time doesn’t allow to solve, it will be assigned as a lab problem!

  7. Problem 4 • Problem statement: Write a program to print a one month calendar. The user specifies the number of days in the month and the day of the week on which the month begins. • Sample execution: • If time doesn’t allow to solve, it will be assigned as a lab problem!