Review problems

Review problems#

This week we will review part of what we have seen before and will write various small programs.

Requirements:

  1. Create a single solution and for each program, create a separate project.

  2. Each Project Name must be named after the activity names, e.g., ArithmeticOperations.

  3. In your README describe in a single sentence what each program does.

Activity 48 (ArithmeticOperations)

Write a program that reads two integers from the console and then displays:

  1. sum

  2. product

  3. difference

  4. quotient

  5. remainder

Assume that the user will always provide integer numbers.

Example:

Enter first integer
2
Enter second integer
5
Result:
7
10
-3
0
2
Hint

Activity 49 (MultiplesOfNumbers)

Write a console program that determines whether a given number is multiples of the second given number. Use the modulo operator.

Example 1

Enter dividend
34.1
Enter divisor
0.1
Multiples

Example 2

Enter dividend
12
Enter divisor
5
Not multiples
Hint

Activity 50 (DigitSumForeach)

Read an integer from the console and calculate the sum of its digits.

Steps:

  1. Loop over the characters of the input string

  2. Convert each character to a string and try to parse each character-string as an integer.

  3. Create a sum of all these integers.

Example:

Enter an integer
1090
Sum: 10
Hint

Activity 51 (DigitSumModulo)

Read an integer from the console and calculate the sum of its digits using the following algorithm:

        graph 
s(start)
read[read number]
init[initialize sum]
loop{is number > 0?}
  mod[get the least significant digit of number using modulo]
  add[add the remainder to the sum]
  div[divide number by 10]
e(end)
  
s --> read --> init --> loop --yes--> mod --> add --> div
div --> loop
loop --noo--> e
    

Example:

Enter an integer
123
Sum: 6
Hint

Activity 52 (DecisionBasedOnBooleans)

Should you stay or should you go? You cannot decide from the top of your head whether you want to go to the lecture or not. You came up with the following criteria. If all off the criteria is fulfilled then you will go to the lecture.

  1. Lecture topic is interesting.

  2. At least one of your friends will join or you have problems with the assignment.

Write a program that prompts you three questions and gives a recommendation.

Is the lecture topic interesting?
y
Does one of your friends join?
n
Do you have problems with the assignment?
y
Go. ✅
Is the lecture topic interesting?
n
Does one of your friends join?
y
Do you have problems with the assignment?
y
Stay. ❌
Hint

Activity 53 (SentenceFromWords)

Write a program that puts input words together into a sentence and prints the sentence.

Enter words of a sentence one by one including punctuation:
I
go
home
now.
I go home now.
Hint