CENG 198 Spring 2014-15

advertisement
CENG 198
Spring 2014-15
CENG 198 LABWORK 8
1. Write a method that decides whether two given numbers are amicable numbers or
not.
Hint: Amicable numbers are two numbers so related that the sum of the
proper divisors of the one is equal to the other, one being considered as a
proper divisor but not the number itself. Such a pair is (220,284); for the
proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110, of which
the sum is 284; and the proper divisors of 284 are 1, 2, 4, 71, and 142, of
which the sum is 220.
2. Assume user enters a series of characters and wants to know how many vowels exist
in it. Let’s assume the number of characters in the series entered by the users is 20.
Write a program using a while loop to read the characters and count how many
characters of each vowel occurs in it.
For example, if the series is ‘ABNAVOIEIKONVKAPLBO’ then your program
should print:
‘A’ repeated 2 time(s)
‘E’ repeated 1 time(s)
‘I’ repeated 2 time(s)
‘O’ repeated 3 time(s)
‘U’ repeated 0 time(s)
Use switch-case statement to count the vowels. Assume all characters are capital
characters.
CENG 198
Spring 2014-15
3. Assume that you are working for a kinder garden. The meal menu is defined according
youngest child. For this reason head teacher demanded a software that will give the
minimum age of the children.
In your software, you should take 10 children's ages from the user.
Sample Run:
Enter the age: 2
Enter the age: 5
Enter the age: 3
Enter the age: 5
Enter the age: 9
Enter the age: 1
Enter the age: 2
Enter the age: 6
Enter the age: 4
Enter the age: 3
The youngest child is 1 year old.
4. Write a program that input n and n personal information of employees. Each employee
information contains gender code (F for females, M for males) and age. Program will
find and display:
a. Number of female workers older than 30 and number of male workers younger
than 50
b. Average age of female and male workers
Sample Run:
Enter number of employees: 100
Enter gender and age: F 39
Enter gender and age: F 33
Enter gender and age: M 45
Enter gender and age: F 45
Number of female workers older than 30: 45
Number of male workers younger than 50: 33
Average age of females: 35.7
Average age of males: 47.8
Download