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

C++ Exam

Follow the instructions in order to get maximum points. Please take your time and read the
instructions carefully.

Each question is worth 20 points. If you don't know how to solve one of the problems, just
skip it and go to the next one, first do the things you are sure that you know, later you can
come back and try the ones which you didn't know.

Open Dev C++. For each question make a new file. Save the files as Problem 1, Problem
2, etc.

Good luck!

PROBLEM 1 (20 POINTS)

Write a program that asks the user for their name then it greets them. After that it should
ask the user how they feel and respond like in the example below.
NOTE: the varaible needs to be of type string, not int.

EXAMPLE:

What is your name?


Ron
Hello. How are you Ron?
bad
I feel bad too.
______________________________________________________________

What is your name?


Harry
Hello. How are you Harry?
Good
I feel Good too.
PROBLEM 2 (20 POINTS)

• Write a program which will take a number as an input.


• The program needs to decide if the number is divisible by 2, 3 or 6. For 6 use if the
number is divisible by 2 and 3 at the same time.
• If the number is not divisible by any of them don't print anything.

EXAMPLE:

Enter a number:12

The number is divisible by 2.


The number is divisible by 3.
The number is divisible by 6.

Enter a number: 4
The number is divisible by 2.
PROBLEM 3 (20 POINTS)

• Make a program which will ask the user to enter a character. Use the switch function.
• Explain to the user what the program will do, print the following on the screen:
o Please choose a character.
Addition = +
Subtraction = -
Division = /
Multiplication = *
• If the character is „+“ the program should ask the user to enter 2 numbers and print
their sum.
• If the character is „-“ the program should ask the user to enter 2 numbers and print
their difference.
• If the character is „/“ the program should ask the user to enter 2 numbers and print
their ratio.
• If the character is „*“ the program should ask the user to enter 2 numbers and print
their product.
• If the user enters a wrong character print: „The character is wrong“.

EXAMPLE:

Please choose a character. -

Please enter 2 numbers:


5
10

The difference is: -5


PROBLEM 4 (20 POINTS)

• Write a program that requires a user to enter a natural number n from the keypad.
• The program prints a sum of even numbers smaller or equal to n.

EXAMPLE:

Enter a natural number n: 8

The sum of even numbers smaller than 8 is 20.


PROBLEM 5 (20 POINTS)

• Write a program that requires a user to enter a number until the user guesses the
correct number.
• When the user enters a number which is higher than the required one, you should
print: „The number you entered is bigger than the one you are looking for. Please try
again.“ The user should then enter the number again. The process is repeated until
the user guesses the correct number.
• When the user enters a number which is smaller than the required one, you should
print: „The number you entered is smaller than the one you are looking for. Please try
again.“ The user should then enter the number again. The process is repeated until
the user guesses the correct number.
• When the user guesses the number print: „You win.“
• The number which the user needs to guess is 16.

EXAMPLE:

Enter a natural number n: 8

The number you entered is smaller than the one you are looking
for. Please try again.

25

The number you entered is bigger than the one you are looking
for. Please try again.

10

The number you entered is smaller than the one you are looking
for. Please try again.

16

You win.

When you finish all the requirements, save the files in one folder and save it as a .rar file,
then go to your Google Classroom account and upload the file to the „C++ Exam“
assignment.

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