Computer Engineering Department

Bilkent University

CS101: Algorithms and Programming I

Assignment No. 7

March 14, 2002

Notes: 1. Please READ the assignment.  2. Always bring your textbook to the lab for reference purposes.  3. Study the programs before coming to the lab and try to solve them as much as possible, finish the HTML assignment, see below, before coming to the lab.  Keep them in your H drive so that it would be easy to access them in the labs.  You may also keep them in diskette.  4. Your assistants may slightly change the programs as you work on them.

 

A. Purpose of Assignment

More on programming structures and an introduction to web page creation using HTML.

 

B. Description of Assignment

At the beginning of each program you must indicate your name, date, and the purpose of the program.  Your programs must have proper indentation, and make sure that 1. your variable names are meaningful, 2. your program has enough comments and blank lines for readability. 3. Your programs must have an easy to follow user interface, and for each printed number your program must provide its explanation such as

 summation of even numbers from 2 to 7: 12.

 

Program 1: Find the reverse of a number.

Examples: 1234 becomes 4321, 1200 becomes 21  (i.e., ignore the leading zeros).

Note that you can construct a number from its individual digits.

Hint: Initialize sum as 0, and execute the following in a loop for each nextDigit: sum= 10 *sum +  nextDigit.

 

Program 2: Check if a number is a palindrome. 

Examples: 121, 123321 are palindromes.

 

Program 3: Write an integer in terms of product of powers of primes. 

Every integer can be written as product of powers of primes, for example 2= 2, 13= 13, 18= 2 x 3 x 3 (21.32), 36= 2 x 2 x 3 x 3 x 3.

 

Program 4: Find summation.

Find the summation: 1 + ½ + 1/3 + ... + 1/10000

With two for loops.  First try

for(i= 1; i <= 10000; i++)

and then try

for(i= 10000; i >= 1; i--)  // ß corrected on Sunday, March 17, ‘02

Explain why the values are different.  Which one is the more accurate value?  (Note that you have to use floating point arithmetic.)

 

Program 5: HTML Assignment (Finish this one before coming to the lab.)  Due to Aykut Unal.

First read the accompanying HTML handout and the related appendix of the textbook for an introduction to HTML.

  1. Open the URL http://www.cs.bilkent.edu.tr/~canf/CS101/Assignments/assignment7/index.html
  2. Click View/Source to view the HTML code of the template page.  The source code should be opened in Notepad.
  3. Modify the file as follows:  

1.        The title of the document must be “Your Name ‘s– Home Page.”

2.        Change the background and foreground colours of the document as you wish.  The colours you choose do not matter as long as your document is not unreadable.

3.        Find the Bilkent University logo from the web and place it to the center of the very top of your document.

4.        Modify the Personal Info and Educational Background according to your personal info.

5.        Between the Personal Info and Educational Background sections, write two paragraphs about yourself.  The context is not crucial and you may copy and paste from your previous assignments.

6.        List the courses you are taking this semester within the Course Information section.  Make sure to add links to the homepage of the courses, as in the “CS-101:Introduction to Java” item in the list.

7.        Populate the table in the Schedule section according to your real course schedule.

8.        Add a new section “Some of my friends” that gives the names of at least three of your friends and links to their web pages.

  1. Create a folder in your home driver (H) as public_html.  Save the file as index.html in the public_html folder you created.  Make sure the folder and file names are correct.  Otherwise, you can not publish your document in WWW.
  2. Close the document.
  3. Open your web browser and write http://www.ug.bcc.bilkent.edu.tr/~login into the address bar, where login is your username. Click Go next to the address bar or press enter.  If everything is ok, you will see your HTML document.  If not, check you have followed the instructions correctly.
  4. If you are not connected to WWW, you can still see your document using your web browser.  To open a document offline in Internet Explorer, click File/Open/Browse and locate the file you saved in step 4. Then click Open and OK.
  5. You may repeat the steps 4-7 until the document looks exactly like you wish.

 

C. When and How to Submit Your Work

Make sure that your programs are all seen and approved by your assistant.  If they have different instructions regarding grading please follow their instructions.