Exercises for OOP in C# .NET lesson 11

C# .NET OOP Exercises for OOP in C# .NET lesson 11

The following exercises will help you put your knowledge of OOP in C# .NET to the test, based off of what you've learned from previous lessons. Try to solve them on your own, but know that you could always download the working solutions under the article. Nonetheless, beware that when you view the solution without solving the exercise, you won't learn anything :)

If you find yourself stuck at some point, you should always try going back to check previous tutorials first and figure the problem out by yourself.

Easy exercise

Write an application that prints the sum of the dates for the following 7 days. For example, 11/24/2013 would be 2013+11+24 = 2048. The date format in the sample below won't matter. The results would be the same, regardless.

Application screen sample:

Console application
Printing the sum of all the numbers in the dates for the following 7 days 10/27/2016 - 2053 10/28/2016 - 2054 10/29/2016 - 2055 10/30/2016 - 2056 10/31/2016 - 2057 11/1/2016 - 2028 11/2/2016 - 2029

Intermediate exercise

Write an application that prints all of the Fridays the 13ths in a given time interval.

Application screen sample:

Console application
Prints all Fridays 13th for entered interval: Enter the first date: 1/1/2013 Enter the second date: 8/15/2015 Fridays 13th: 9/13/2013, 12/13/2013, 6/13/2014, 2/13/2015, 3/13/2015,

Advanced exercise

Write an application that asks the user for his/her birth date. The application will print how old the user is and how many days are left until his/her next birthday. Think carefully about the age calculation part. Dividing the number of days in a TimeSpan by 365.25 would not work because it would give inaccurate results in some cases.

Application screen sample:

Console application
Enter your birth date: 1/15/1989 You're 27 years old and your birthday is coming up in 289 days.



Downloaded 10x (108.13 kB)
Application includes source codes in language C#



Article has been written for you by David Capka
Do you like this article?
1 votes
The author is a programmer, who likes web technologies and being the lead/chief article writer at ICT.social. He shares his knowledge with the community and is always looking to improve. He believes that anyone can do what they set their mind to.
Unicorn College The author learned IT at the Unicorn College - a prestigious college providing education on IT and economics.
Previous article
Date and time in C# .NET
All articles in this section
Object-oriented programming in C# .NET
Next article
Lists in C# .NET
Activities (10)




Lennart Völler:28. November 9:30

Good exercise :)
But when when you use good coding style (classes, encapsulation, etc.) why not use it in all exercise solutions?

Reply 28. November 9:30
David Capka
ICT.social team
Replies to Lennart Völler
David Capka:28. November 9:39

Hi Lennart, do you mean anything particular? These exercises are about working with the DateTime class. We think it'd be counterproductive to introduce complex class models in the solutions since it'd only cloud the main goal. There're other courses with more advanced sample apps available which have nice class models :)

Reply 28. November 9:39
You can walk through a storm and feel the wind but you know you are not the wind.
Replies to David Capka
Lennart Völler:29. November 1:46

In the exercises "Friday13" and "DateDigitsSum" you solved the problem just using the main method. In exercise "birthday" you used another individual class which gave me the impression that my solution which (as the two exercises before) was only written in the main Program.cs was unelegant in comparison ;)

Reply 29. November 1:46
To maintain the quality of discussion, we only allow registered members to comment. Sign in. If you're new, Sign up, it's free.

3 messages from 3 displayed.