EE221 Assignment 1

Program 1 (15pts.)

A demographic study of the metropolitan area around Dogpatch divided it into three regions - urban, suburban, and exurban - and published the following table showing the annual migration from one region to another (the numbers represent percentages):

 UrbanSuburbanExurban
Urban1.10.30.7
Suburban0.11.20.3
Exurban0.20.61.3

For example, 0.3 percent of the urbanites (0.003 times the current population) move to the suburbs each year (subtract it from urban population and add it to the suburban population). The diagonal entries represent internal growth rates (birth rate minus death rate). Write a program to determine the population of each region after 10, 20, 30, 40, and 50 years. Assume that the initial populations of the urban, suburban, and exurban regions are 2.1 million, 1.4 million, and 0.9 million, respectively.

Must not use arrays (there will be a follow up assignment that asks for that), use single variables (since we did not go through the chapter 3 yet), read and initial population from the keyboard. (Coefficients may be either hard coded or also read from the keyboard - it is up to you.) Tabularize the actual population every ten year. (This problem will be assigned again later on, with use of 2D arrays and some other modifications.)

Repeat the calculations 50 times, print the state every ten iterations.

Suggested design - use two sets on populations: oldU, oldS, oldE, and newU, newS, newE, read initial "old" values; calculate the "new" values using "old" values; then assign the "new" to "old"; You can either "hardcode" the coefficients and populations inside the program or ask the user to enter them from the keyboard.

This is a "warm up" assignment. Significant portion of this assignment will be discussed and may be even solved in class. Reviewed material: formulas, loops, conditions, algorithms. This isac tually close to Chapter 3, Problem 6, Page 138.

Program 2 (15pts.)

Reverend Zeller developed a formula for computing the day of the week on which a given date fell or will fall. Suppose that we let a, b, c, and d be integers defined as follows:

      
  a = The number of a month of the year, with March = 1, April = 2, and
      so on, with January and February being counted as Months 11 and
      12 of the *preceding* year
  b = The day of the month
  c = The year of the century
  d = The century

For example, July 31, 1929 gives a = 5, b = 31, c = 29, and d = 19. And January 3, 1988 gives a = 11, b = 3, c = 87, and d = 19. Now calculate the following integer quantities:

      
  w = The integer quotient (13a - 1)/5
  x = The integer quotient c/4
  y = The integer quotient d/4
  z = w + x + y + b + c + 5*d

  r = z reduced modulo 7 (i.e., r = z % 7); r = 0 represents Sunday, 
      r = 1 represents Monday, and so on.

Complete the provided program that receives the date as the number of a month, the day of the month, and a year and returns the name of the day of the week on which that date fell (or will fall).

web site front local main page local list page print this page   general bookmarks software bookmarks go back close this page copyright info   visitor counter