Description
Problem 2.1 Reading from the keyboard (1 point)
Presence assignment, due by 11:00 AM today Graded automatically with testcases only
Language: C
Write a program which does the following:
1. reads two doubles from the keyboard,
2. prints the sum of the two doubles,
3. prints the difference of the two doubles (first minus second),
4. prints the square of the first double,
5. reads two integers from the keyboard,
6. computes the sum and product of the two integers,
7. prints the sum and product of the integers,
8. reads two chars from the keyboard,
9. computes the sum and product of the two chars,
10. prints the sum and product of the chars as decimal values and as chars.
You can assume that the input will be correct.
Your solution has to satisfy the requirements from the problem description and has to pass the
following testcase and potentially other testcases which are uploaded. All characters are relevant
for passing testcases including newlines and spaces.
Testcase 2.1: input
1.2
3.6
2
5
(
)
Testcase 2.1: output
sum of doubles=4.800000
difference of doubles=-2.400000
square=1.440000
sum of integers=7
product of integers=10
sum of chars=81
product of chars=1640
sum of chars=Q
product of chars=h
Problem 2.2 Decimal, octal and hexadecimal numbers (1 point)
Due by Monday, September 20th, 23:00 Graded automatically with testcases only
Language: C
Write a program which does the following:
1. reads a char from the keyboard,
2. and prints the char as character as well as in decimal, octal and hexadecimal notation.
You can assume that the input will be correct.
Your solution has to satisfy the requirements from the problem description and has to pass the
following testcase and potentially other testcases which are uploaded. All characters are relevant
for passing testcases including newlines and spaces.
Testcase 2.2: input
{
Testcase 2.2: output
character={
decimal=123
octal=173
hexadecimal=7b
Problem 2.3 Time calculation (1 point)
Due by Monday, September 20th, 23:00 Graded manually
Language: C
Write a program where you can enter integer numbers for weeks, days and hours as input from
the keyboard. Your program should compute and output by printing on the screen the total
number of hours.
You can assume that the input will be correct.
Problem 2.4 Area computations (1 point)
Due by Monday, September 20th, 23:00 Graded automatically with testcases only
Language: C
Write a program that reads from the keyboard three float values for the variables a, b and h.
Compute and print on the screen the areas of: the square with the side a, the rectangle with the
length a and the width b, a triangle with the base a and the height h, and a trapezoid with the
bases a, b and the height h.
You can assume that the input will be correct.
Your solution has to satisfy the requirements from the problem description and has to pass the
following testcase and potentially other testcases which are uploaded. All characters are relevant
for passing testcases including newlines and spaces.
Testcase 2.4: input
10
14.5
5
Testcase 2.4: output
square area=100.000000
rectangle area=145.000000
triangle area=25.000000
trapezoid area=61.250000
Problem 2.5 Pointers and their content (1 point)
Due by Monday, September 20th, 23:00 Graded manually
Language: C
Write a program which reads an integer variable a from the keyboard and prints the value on the
screen. Then declare and initialize a pointer ptr_a pointing to a, print the address contained in
the pointer variable on the screen, increase the value of a by 5 by using the pointer variable and
print the modified value and the address of the variable on the screen as well.
You can safely assume that the input will be correct.
Problem 2.6 Multiple pointers to same data (1 point)
Due by Monday, September 20th, 23:00 Graded manually
Language: C
Write a program which reads two double variables x and y from the keyboard. Then declare and
initilize three pointers ptr_one, ptr_two and ptr_three such that ptr_one and ptr_two
will both point to the variable x and ptr_three will point to y. By using printf show that
ptr_one and ptr_two contain the same memory address and ptr_three contains a different
address.
You can assume that the input will be correct.
Problem 2.7 Infinite loop by bad coding (1 point)
Due by Monday, September 20th, 23:00 Graded manually
Language: C
The program below prints
i is 8
i is 8
…
until you stop the execution by pressing Ctrl-C. Fix the program such that it prints 8, 7, 6, 5 and
4 as values for i.
#include <stdio.h>
int main()
{
int i = 8;
while (i >= 4)
printf(“i is %d\n”, i);
i–;
printf(“That’s it.\n”);
return 0;
}
Problem 2.8 Divisible by 2 and 7? (1 point)
Due by Monday, September 20th, 23:00 Graded automatically with testcases only
Language: C
Write a program, where you can enter an integer from the keyboard. Determine whether the
number is divisible by both 2 and 7. Then either print on the screen
“The number is divisible by 2 and 7” or
“The number is NOT divisible by 2 and 7”.
You can safely assume that the input will be valid.
Your solution has to satisfy the requirements from the problem description and has to pass the
following testcase and potentially other testcases which are uploaded. All characters are relevant
for passing testcases including newlines and spaces.
Testcase 2.8: input
56
Testcase 2.8: output
The number is divisible by 2 and 7
Problem 2.9 Categorization of characters (1 point)
Due by Monday, September 20th, 23:00 Graded automatically with testcases only
Language: C
Write a program where you can enter a character from the keyboard. Then determine whether
the character is a digit or a letter or some other symbol and print a corresponding message on the
screen.
You can safely assume that the input will be valid.
Your solution has to satisfy the requirements from the problem description and has to pass the
following testcase and potentially other testcases which are uploaded. All characters are relevant
for passing testcases including newlines and spaces.
Testcase 2.9: input
!
Testcase 2.9: output
! is some other symbol
Problem 2.10 Days and hours (2 points)
Due by Monday, September 20th, 23:00 Graded manually
Language: C
Write a program where you can enter an integer n from the keyboard. Then a conversion table for
1 to n days should be printed on the screen as in the example below. Make sure that the integer
value you entered for n is valid (positive and non-zero). If an invalid integer n was entered then
repeat the entering until a valid value will be entered.
Use a while loop in your solution.
1 day = 24 hours
2 days = 48 hours
3 days = 72 hours
…
How to submit your solutions
• Your source code should be properly indented and compile with gcc or g++ depending on the problem without any errors or warnings (You can use gcc -Wall -o program program.c or g++
-Wall -o program program.cpp). Insert suitable comments (not on every line . . . ) to explain
what your program does.
• Name the programs according to the suggested filenames (they should match the description of the
problem) in Grader.
Each program must include a comment on the top like the following:
/*
CH-230-A
a2 p1.[c or cpp or h]
Firstname Lastname
myemail@jacobs-university.de
*/
• You have to submit your solutions via Grader at
https://grader.eecs.jacobs-university.de.
If there are problems (but only then) you can submit the programs by sending mail to
k.lipskoch@jacobs-university.de with a subject line that begins with CH-230-A.
It is important that you do begin your subject with the coursenumber, otherwise I might have
problems to identify your submission.
• Note, that after the deadline it will not be possible to submit any solutions. It is useless to send late
solutions by mail, because they will not be accepted.
This assignment is due by Monday, September 20th, 23:00.