19.06.2013 Views

Starting Out with C++: Early Objects - EEMB DERSLER

Starting Out with C++: Early Objects - EEMB DERSLER

Starting Out with C++: Early Objects - EEMB DERSLER

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

676 Chapter 10 Pointers<br />

Solving the<br />

Days in Current<br />

Month Problem<br />

taken to be the average of the two middle values. Write a function that determines the<br />

median of a sorted array. The function should take an array of numbers and an integer<br />

indicating the size of the array and return the median of the values in the array. You may<br />

assume the array is already sorted. Use pointer notation whenever possible.<br />

7. Movie Statistics<br />

Write a program that can be used to gather statistical data about the number of movies college<br />

students see in a month. The program should ask the user how many students were<br />

surveyed and dynamically allocate an array of that size. The program should then allow<br />

the user to enter the number of movies each student has seen. The program should then<br />

calculate the average, median, and mode of the values entered.<br />

8. Days in Current Month<br />

Write a program that can determine the number of days in a month for a specified month<br />

and year. The program should allow a user to enter two integers representing a month and<br />

a year, and it should determine how many days are in the specified month. The integers 1<br />

through 12 will be used to identify the months of January through December. The user<br />

indicates the end of input by entering 0 0 for the month and year. At that point, the program<br />

prints the number of days in the current month and terminates.<br />

Use the following criteria to identify leap years:<br />

1. A year Y is divisible by 100. Then Y is a leap year if and if only it is divisible by 400.<br />

For example, 2000 is a leap year but 2100 is not.<br />

2. A year Y is not divisible by 100. Then Y is a leap year if and if only it is divisible by 4.<br />

For example, 2008 is a leap year but 2009 is not.<br />

Here is sample run of the program:<br />

Enter month and year: 2 2008[Enter]<br />

29 days<br />

Enter month and year: 0 0[Enter]<br />

The current month, September 2009, has 30 days.<br />

9. Age<br />

Write a program that asks for the user’s name and year of birth, greets the user by name,<br />

and declares the user’s age in years. Users are assumed to be born between the years 1800<br />

and 2099, and should enter the year of birth in one of the three formats 18XX, 19XX, or<br />

20XX. A typical output should be “Hello Caroline, you are 23 years old.”

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!