You are on page 1of 4

 

Private High School for Digital Sciences "SoftUni Svetlina”

Lab: Defining Simple Classes


Problems for exercises and homework for the "Programming Advanced: OOP Basics" course from the official
"Applied Programmer" curriculum.
You can check your solutions here: https://judge.softuni.bg/Contests/2842/Defining-Simple-Classes-Lab.

1. Day of Week
You are given a date in format day-month-year. Calculate and print the day of week in English.

Examples
Input Output

18-04-2016 Monday

27-11-1996 Wednesday

Hints
 Read the date as string from the Console.
 Use the method DateTime.ParseExact(string date, format, provider) to convert the input
string to object of type DateTime. Use format “d-M-yyyy” and CultureInfo.InvariantCulture.
o Alternatively split the input by “-“ and you will get the day, month and year as numbers. Now you
can create new DateTime(year, month, day).
 The newly created DateTime object has property DayOfWeek.

2. Randomize Words
You are given a list of words in one line. Randomize their order and print each word at a separate line.

Examples
Input Output Comments

Welcome to SoftUni and have fun learning The order of the words in the output will be
learning programming Welcome different after each program execution.
SoftUni
and
fun
programming
have
to

Hints
 Split the input string by (space) and create an array of words.
 Create a random number generator – an object rnd of type Random.
 In a for-loop exchange each number at positions 0, 1, … words.Length-1 by a number at random
position. To generate a random number in range use rnd.Next(minValue, maxValue). Note that by
definition minValue is inclusive, but maxValue is exclusive.
 Print each word in the array on new line.

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
 Private High School for Digital Sciences "SoftUni Svetlina”

3. Big Factorial
Calculate and print n! (n factorial) for very big integer n (e.g. 1000).

Examples
Input Output

5 120

50 3041409320171337804361260816606476884437764156896051200000000000

Hints
Use the class BigInteger from the built-in .NET library System.Numerics.dll.
1. Import the namespace “System.Numerics”:

2. Use the type BigInteger instead of long or decimal to keep the factorial value:

4. Rectangle Class
Write a program that calculates the area of a rectangle. To do this, you need to define a Rectangle class and create
a Rectangle object. It should have width, height (integers) and color (string). Your task is to calculate its area,
and print.
You are given two numbers on two lines. First number is width and the second number is height. Use the correct
properties from the Rectangle class and print the result in the following format:
"Rect({Width}, {Height}, {Color}) has area {Area}.")

Examples
Input Output

10
50 Rect(10, 50, green) has area 500.
green

5
3 Rect(5, 3, blue) has area 15.
blue

Hints
Create a file for this class: [Project] -> [Add Class] or: right click on the project [Add] -> [New Item] ->
[Class]

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
 Private High School for Digital Sciences "SoftUni Svetlina”

Make the class public and add properties Width, Height (integers) and Color.

Read the input, create a new Rectangle object, and set the read data into it.

Use the given input, calculate the area by getting the data from the object and print the result.
Note:

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
 Private High School for Digital Sciences "SoftUni Svetlina”

To test your solution for this task, move your Rectangle class after Program class.

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

You might also like