Вы находитесь на странице: 1из 12

1.

Fancy Name Printer


Requires:
Basic printing capability

Write a program that will print your Name in standard output in


letters that are nine lines tall. Each big letter should be made up
of a bunch of *'s. For example, if your name is "DJE", then the
output would look something like:

****** ************* **********


** ** ** **
** ** ** **
** ** ** **
** ** ** ********
** ** ** ** **
** ** ** ** **
** ** ** ** **
***** **** **********

2. Greeting Lucy
Requires:
Variables, Strings.
Write a program that asks the user's name, and then greets the
user by name. Before outputting the user's name, convert it to
upper case letters. For example, if the user's name is Lucy, then
the program should respond "Hello, LUCY, nice to meet you!"

3. Change Counter for Bank Cashers


Requires:
Variables, numerical operators

Write a program that helps the user count his change. The
program should ask how many 100 birr notes the user has then
how many 50 birr notes, then how many 10 birr notes, then how
many 5 birr notes, then how many 1 birr notes, then how many
50 cents, then how many 25 cents, then how many 10 cents,
then how many 5 cents. Then the program should tell the user
how much money he has, expressed in birr.

4. The egg counter

Requires:
Variables, numerical operators.

If you have N eggs, then you have N/12 dozen eggs, with N%12
eggs left over. (This is essentially the definition of the / and %
operators for integers.) Write a program that asks the user how
many eggs she has and then tells the user how many dozen eggs
she has and how many extra eggs are left over.

a. A gross of eggs is equal to 144 eggs. Extend your


program so that it will tell the user how many gross,
how many dozen, and how many left over eggs she has.
For example, if the user says that she has 1342 eggs,
then your program would respond with
Your number of eggs is 9 gross, 3 dozen, and 10

since 1342 is equal to 9*144 + 3*12 + 10.

5. Grading Program
Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)

Write a program that allows the user to enter the grade scored in
a java class (0-100).
If the user scored a 100 then notify the user that they got a
perfect score. It should also print the student grade based on the
following scales 0-59 F 60-69 D 70-79 C 80-89 B 90-100 A

a. It should print an error nun numeric value not


allowed if the user enters a character
b. It should print an error A student grade cannot be
Negative if the user enters a negative value.
c. It should print an error A student grade cannot exceed
maximum if the grade is greater than 100
6. Cola Machine
Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)

Write a program that presents the user w/ a choice of your 5


favorite beverages (Coke, Water, Sprite, Ambo water, Pepsi).
Then to allow the user choose a beverage by entering a number
1-5.
Output which beverage they chose.
a. Write the program using switch statement
b. rite the program using if, else condition

7. Bracketing Search
Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
loops (for, while, do-while)
psudo random numbers

Write a program that calculates a random number 1 through


100. The program then asks the user guesses too high or too low
then the program should output "too high" or "too low"
accordingly.
The program the user to guess the number.
If must let the user continue to guess until the user correctly
guesses the number.
a. Modify the program to output how many guesses it
took the user to correctly guess the right number.

8. Bracketing Search 2
Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
loops (for, while, do-while)
pseudo random numbers

In the above exercise modify the program so that instead of the


user guessing a number the computer came up with, the
computer guesses the number that the user has secretly decided.
The user must tell the computer whether it guessed too high or
too low.
a. Modify the program so that no matter what number the
user thinks of (1-100) the computer can guess it in 7 or
less guesses.

9. Tic Tac Toe


Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
loops (for, while, do-while)
arrays

Make a two player tic tac toe game (


http://en.wikipedia.org/wiki/Tic-tac-toe ).
a. The program should announce when a player has won
the game (and which player won, x or o)
b. The program should block any further moves after one
of the party has won the game.

10. Tic Tac Toe 2


Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
loops (for, while, do-while)
arrays

Change the above program so that the program becomes a one


player game against the computer (with the computer making its
moves randomly)

11. Dungeon Crawl


Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
loops (for, while, do-while)
arrays

Make a program that outputs a simple grid based gameboard to the


screen using either numbers or characters.
i.e.

..........
.G........
......T...
..........
....T.....
......T...
.........X

or

0000000000
0500600000
0000007000
0000000000
0007000000
0000007000
0000000004

Allow the user (marked by G in the example) to move either


up, down, left, or right each turn. If the player steps on a trap
then they lose. If the make it to the treasure 'X' then they win.

Add enemies that move randomly in any direction once per


turn. (enemies just like traps cause the player to lose if
touched)

a. Don't let the player move off the gameboard! You


program will crash if they move off the top or bottom
of the board!(the same holds true for enemies)

Functions
12. Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
loops (for, while, do-while)
functions

Write a function titled say_hello() that outputs to the screen


"Hello World, I am a Programmer"

13. Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
loops (for, while, do-while)
functions
Write a function so that it takes an integer argument and says
hello a number of times equal to the value passed to it.

14. Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
loops (for, while, do-while)
functions

Write a function that takes two integers arguments and then


returns an integer that is the product of the two integers.
(i.e., integer1: 4, Integer2: 5 returns: 20)

15. Recursive Function


Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
loops (for, while, do-while)
functions

Make a function called half() that takes an integer argument.


The function must print the number it received to the screen,
then the program should divide that number by two to make a
new number. If the new number is greater than zero the function
then calls the function half() passing it the new number as its
argument. If the number is zero or less than the function exits
e.g. Call to the function half() with an argument of 100, the
screen output should be
100
50
25
...
...
1.

16. Default arguments


Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
loops (for, while, do-while)
functions

Say you have a function with 2 arguments, but one of the arguments is
usually the same. For instance, say we want a function that prints
message n times, but most of the time it will only need to print it once:

Rather than writing printNTimes("Some message", 1); every


time when it is called, allow the calling of the function using
printNTimes("Some message") when the user wants to
print the message ones.

Strings
17. Concatenate users first name and last name
Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
loops (for, while, do-while)
functions
strings & string functions

Write a program that asks for a user first name and last name
separately.
The program must then store the users full name inside a single
string and out put it to the string.
i.e.
Input:
Gidey
Gemechu
Output:
Gidey Gemechu

18. Replace Vowels with letter Z


variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
loops (for, while, do-while)
functions
strings & string functions
Write a program that accept users first name and last name and
print the value by replacing every a, e, i, o, u with the letter z
e.g.
Gidey Gemechu -> Gzdzy Gzmzchu

19. Reverse Users name


Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
loops (for, while, do-while)
functions
strings & string functions

Write a program that accept uers full name and print thir name
in reversed order.name

e.g.:- Gidey Gemechu -> uhcemeG yediG

20. Text breaker

Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
loops (for, while, do-while)
functions
strings & string functions

Write a program that reads one line of input text and breaks it
up into words. The words should be output one per line. A word
is defined to be a sequence of letters. Any characters in the input
that are not letters should be discarded. For example, if the user
inputs the line
He said, "That's not a good idea."

then the output of the program should be


He
said
That
s
not
a
good
idea
a. Write an improved version of the program which lists
"that's" as a single word. An apostrophe can be
considered to be part of a word if there is a letter on
each side of the apostrophe
Hint: to test whether a character is a letter u can use its ASCII
value or Character.isLetter(ch) function which returns Boolean
value

21. Text Tokenize

Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
loops (for, while, do-while)
functions
strings & string functions

Write a program that reads one line of input text and tokenize
into words by taking space as a tokenizing delimiter.

22. Capitalize
Requires:
variables, data types, and numerical operators
basic input/output
loops (for, while, do-while)
functions
strings & string functions

Write a program that accept a text and capitalizes the first letter
of each word on the text

23. Real Number


Sorter

Write a program that will read a sequence of positive real


numbers entered by the user and will print the same numbers in
sorted order from smallest to largest. The user will input a zero to
mark the end of the input. Assume that at most 100 positive
numbers will be entered.

References

http://www.cplusplus.com/forum/articles/12974/
http://ocw.mit.edu/courses/electrical-engineering-and-computer-
science/6-096-introduction-to-c-january-iap-2011/index.htm
http://math.hws.edu/javanotes/index.html

Вам также может понравиться