Assignment 0
1. Roman Numeral Converter
Write a program that asks the user to enter a number within the range of 1 through 10. Use a switch
statement to display the Roman numeral version of that number.
Input Validation: Do not accept a number less than 1 or greater than 10.
2. Magic Dates
Write a program that asks the user to enter a month (in numeric form), a day, and a two-digit year. The
program should then determine whether the month times the day is equal to the year. If so, it should
display a message saying the date is magic. Otherwise it should display a message saying the date is not
magic.
3. Days in a Month
Write a program that asks the user to enter the month (letting the user enter an inte- ger in the range of
1 through 12) and the year. The program should then display the number of days in that month. Use the
following criteria to identify leap years:
1. Determine whether the year is divisible by 100. If it is, then it is a leap year if and only if it is
divisible by 400. For example, 2000 is a leap year but 2100 is not.
2. If the year is not divisible by 100, then it is a leap year if and if only it is divisible by 4. For example,
2008 is a leap year but 2009 is not.
4. Sum of Numbers
Write a program that asks the user for a positive integer value. The program should use a loop to get the
sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will
find the sum of 1, 2, 3, 4, ... 50.
Input Validation: Do not accept a negative starting number.
5. The Greatest and Least of These
Write a program with a loop that lets the user enter a series of integers. The user should enter −99 to
signal the end of the series. After all the numbers have been entered, the program should display the
largest and smallest numbers entered.
6. Winning Division
Write a program that determines which of a company’s four divisions (Northeast, Southeast, Northwest,
and Southwest) had the greatest sales for a quarter. It should include the following two functions, which
are called by main.
• double getSales() is passed the name of a division. It asks the user for a division’s quarterly sales
figure, validates the input, then returns it. It should be called once for each division.
• void findHighest() is passed the four sales totals. It determines which is the larg- est and prints the
name of the high grossing division, along with its sales figure.
Input Validation: Do not accept dollar amounts less than $0.00.
7. Larger Than n
In a program, write a function that accepts three arguments: an array, the size of the array, and a number
n. Assume that the array contains integers. The function should display all of the numbers in the array
that are greater than the number n.
8. Median Function
In statistics, when a set of values is sorted in ascending or descending order, its median is the middle
value. If the set contains an even number of values, the median is the mean, or average, of the two middle
values. Write a function that accepts as arguments the following:
a. An array of integers
b. An integer that indicates the number of elements in the array
The function should determine the median of the array. This value should be returned as a double.
(Assume the values in the array are already sorted.)
Demonstrate your pointer prowess by using pointer notation instead of array notation in this function.
9. Reverse Array
Write a function that accepts an int array and the array’s size as arguments. The function should create a
copy of the array, except that the element values should be reversed in the copy. The function should
return a pointer to the new array. Demonstrate the function in a complete program.
10. Quadratic Equation
Write a function solving the quadratic equation ax2 + bx + c = 0.
Function quadraticEquation() takes the parameters a, b and c and returns the number of roots and the
roots (if they exist).