1 / 29

Case Study

Case Study. Instructor: Chieh-Chih (Bob) Wang Department of Computer Science & Information Engineering National Taiwan University. Print a table that shows the value of π approximated by one term of this series, by two terms, by three terms, etc.

penda
Télécharger la présentation

Case Study

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Case Study Instructor: Chieh-Chih (Bob) Wang Department of Computer Science & Information Engineering National Taiwan University

  2. Introduction to Computer Programming -- Fall 2008 • Print a table that shows the value of π approximated by one term of this series, by two terms, by three terms, etc. • How many terms of this series do you have to use before you first get 3.14? 3.141? 3.1415? 3.14159?

  3. Introduction to Computer Programming -- Fall 2008 Pythagorean Triples • A right triangle can have sides that are all integers. The set of three integer values for the sides of a right triangle is called a Pythagorean triple. These three sides must satisfy the relationship that the sum of the squares of two of the sides is equal to the square of the hypotenuse. • Find all Pythagorean triples for side1, side2, and the hypotenuse all no larger than 500. Use a triple-nested for loop that simply tries all possibilities.

  4. Introduction to Computer Programming -- Fall 2008 Round a number to a specific decimal place • Function floor may be used to round a number to a specific decimal place. • The statement y = floor( x * 10 + .5 ) / 10; rounds x to the tenths position (the first position to the right of the decimal point). • The statement y = floor( x * 100 + .5 ) / 100; rounds x to the hundredths position (i.e., the second position to the right of the decimal point). • Write a program that defines four functions to round a number x in various ways • a) roundToInteger( number ) • b) roundToTenths( number ) • c) roundToHundreths( number ) • d) roundToThousandths( number )

  5. Introduction to Computer Programming -- Fall 2008 Write statements that assign random integers to the variable n in the following ranges:

  6. Introduction to Computer Programming -- Fall 2008 Write a function that returns the smallest of three floating point numbers.

  7. Introduction to Computer Programming -- Fall 2008 Perfect Number • An integer number is said to be a perfect number if its factors, including 1 (but not the number itself), sum to the number. • For example, 6 is a perfect number because 6 = 1 + 2 + 3. • Write a function perfect that determines if parameter number is a perfect number. Use this function in a program that determines and prints all the perfect numbers between 1 and 1000. • Challenge the power of your computer by testing numbers much larger than 1000.

  8. Introduction to Computer Programming -- Fall 2008

  9. Introduction to Computer Programming -- Fall 2008 Prime • An integer is said to be prime if it is divisible only by 1 and itself. For example, 2, 3, 5 and 7 are prime, but 4, 6, 8 and 9 are not. • How?

  10. Introduction to Computer Programming -- Fall 2008 Greatest Common Divisor • The greatest common divisor (GCD) of two integers is the largest integer that evenly divides each of the two numbers

  11. Introduction to Computer Programming -- Fall 2008 Recursive version

  12. Introduction to Computer Programming -- Fall 2008 Arrays • Mean, median, mode

  13. Introduction to Computer Programming -- Fall 2008

  14. Introduction to Computer Programming -- Fall 2008

  15. Introduction to Computer Programming -- Fall 2008 • Write a program that simulates the rolling of two dice. The program should use rand to roll the first die, and should use rand again to roll the second die. The sum of the two values should then be calculated.

  16. Introduction to Computer Programming -- Fall 2008

  17. Introduction to Computer Programming -- Fall 2008 Characters and Strings • Write a program that inputs a line of text with function gets into char array s[ 100 ]. Output the line in uppercase letters and in lowercase letters.

  18. Introduction to Computer Programming -- Fall 2008 • Write a program that inputs four strings that represent integers, converts the strings to integers, sums the values and prints the total of the four values. atoi

  19. Introduction to Computer Programming -- Fall 2008 • Write a program that inputs a line of text and a search string from the keyboard. • Using function strstr, locate the first occurrence of the search string in the line of text, and assign the location to variable searchPtr of type char *.

  20. Introduction to Computer Programming -- Fall 2008

  21. Introduction to Computer Programming -- Fall 2008 Use the string comparison functions and the techniques for sorting arrays to write a program that alphabetizes a list of strings.

  22. Introduction to Computer Programming -- Fall 2008

  23. Introduction to Computer Programming -- Fall 2008 Write a program that reads a series of strings and prints only those strings that end with the letters “ed.”

  24. Introduction to Computer Programming -- Fall 2008 • Write a program that merges two ordered lists of integers into a single ordered list of integers. • Function merge should receive pointers to the first node of each of the lists to be merged and should return a pointer to the first node of the merged list.

  25. Introduction to Computer Programming -- Fall 2008

  26. Introduction to Computer Programming -- Fall 2008

  27. Introduction to Computer Programming -- Fall 2008 • Write a program that inserts 25 random integers from 0 to 100 in order in a linked list. The program should calculate the sum of the elements and the floating-point average of the elements.

  28. Introduction to Computer Programming -- Fall 2008 Final Exam Reminder • Array, String • Pointer, Data Structure • File Processing • Sorting • Recursion

  29. Introduction to Computer Programming -- Fall 2008 Questions?

More Related