Institute of Computer Science
  1. Courses
  2. 2020/21 fall
  3. Introduction to Programming II (MTAT.03.256)
ET
Log in

Introduction to Programming II 2020/21 fall

  • Home
  • Grading
  • Links

Homework 1

The deadline is Sunday, the 15th of November, 23:59 (Estonian time).

The caloric value of food shows how much energy your body gets from the carbohydrates, proteins and fats that the food contains. The file calories.txt contains different meals on separate lines. The number of carbohydrates, proteins and fats is given for each meal in grams. It is known that

  • 1 g of carbohydrate gives 4 Kcal,
  • 1 g of protein gives 4 Kcal,
  • 1 g of fat gives 9 Kcal.

Write a program that calculates and outputs how many calories all meals together give.

If the file calories.txt contains the following lines:

 40 53 14
 62 47 26
 49 43 20
 10 35 22

then the output of the program should be

 2094

Go to Moodle and upload your solution into Homework 1.

  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment