$25
• The problems of this assignment must be solved in C or C++ (instruction in each problem).
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
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
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.
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: inputTestcase 2.4: output
10square area=100.000000
14.5rectangle area=145.000000
5triangle area=25.000000 trapezoid area=61.250000
Problem 2.5 Pointers and their content
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)
You can assume that the input will be correct.
Problem 2.7 Infinite loop by bad coding
(1 point)
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)
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: inputTestcase 2.8: output
56The number is 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.9: input !
Testcase 2.9: output
! is some other symbol
Problem 2.10 Days and hours
(2 points)
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