Homework Module 1 HT18
Homework Module 1 HT18
Homework Module 1 HT18
Test program (Do this warm up program before you start with the actual
homework, but you don’t need to include it as part of your homework.)
Important notice: Please pay attention to ‘.’ and ‘,’ in floats if you are working in English
or Swedish.
You write a program that calculate the three results and display the result as table with three
columns. If the input number is 45,58 the output looks like the table below:
[email protected] 1
Last updated 2018 July
Homework Module 1
With this test program you verify the syntax such (float)2.20 and if you have written the
correct value for the numbers to multiply within the same time you test your calculations for
different input numbers, you may test with negative numbers too.
Homework:
In this assignment, you shall create only one project. All the tasks shall be implemented in
the same project (e.g. Homework1) as different methods (code blocks) named Task1(),
Task2(), … Task8(), as it is shown below. Call all the Task-methods from the project’s main
method. Like this:
}
...
}
(Press Ctrl + F5 to run your program)
You will learn about methods later in the course but for now all you need to do is to create the
above format in your program and write the corresponding code for each task inside it’s block.
Tasks:
1. Read two strings from the user, concatenate them and print the result string on screen.
Below you can see an example of the output:
Your program will ask the user to enter the first string, then it will ask the user for the next
string and finally the two strings will be concatenated and the result will be printed. For
example, if the user enters for the first time: ”The family name of John is”, and for the
second time: “Dale”, the output may look like:
[email protected] 2
Last updated 2018 July
Homework Module 1
2. Read an integer from the keyboard and determine and display whether it is odd or even.
(Hint: Use the remainder operator)
3. Read three numbers from the keyboard and display it on one line on the screen as a table by
using escape sequence \t. If the user enters “456”, “12,25”, “36,89”, the output looks like:
4. Write your initials on the screen by using the first letters of your first and last name, such
as:
5. Read two numbers from the keyboard and assign them to two variables of the type
int, named x and y, compute the sum, difference, product, division and remainder of
these two integers, then display the result on the screen. The pattern of the output could
be like that:
“The sum of xValue with yValue is …”
6. Read the radius r of a circle from the keyboard as integer and display the circle’s
diameter, circumference and area using π value. C# has defined a data type that represents
floating-point numbers that contains decimal point, such as 3.14159. Use the following
formulas, where r is radius:
Diameter = 2r
Circumference = 2πr
Area = πr2
You can define PI yourself using this approximate value, or you can use the constant from
the Math library (Math.PI).
7. Read a four digit integer, such as 5893, from the keyboard and display the digits
separated from one another by a tab each. Use both integer division and modulus operator
% to pick off each digit. If the user enters 4567, the output looks like:
[email protected] 3
Last updated 2018 July
Homework Module 1
8. Read an integer from the keyboard and display the square and the cube of the
number. If the user enters 456, the output looks like:
Other measures that could affect the grade in a positive (+) or negative (-) way
a. Elegant solution + (note: “elegant” is not always the same as extremely compact
code)
b. Unnecessary complex solution –
c. Well formatted and well-structured code with descriptive variable names +
d. Ugly and messy code
–
e. Commented code +
f. Try to write well formatted and well-structured code. Ugly and messy code is
hard to understand and more likely to contain errors. It is good to write short
comments before each block of code or where you think it is necessary.
Remember to compress the whole project folder, name it as your first and last name
(like Nazila_Hasanzade_Homework1) and upload it on Canvas.
Good luck
Nazila
Thanks to
Alexandru & Christian
[email protected] 4
Last updated 2018 July