SEF9 - 52 Programming Concepts Lesson 02 (Correct and incorrect calculations in C, C++ and Python. Why?)

LESSON 02 C/C++ AND PYTHON ==> LEARNING POINTS
==============================================

Some learning points for this tutorial are:

(1) C-PROGRAM ==> SEF-Tutorial-02-Exer-01.c

This is a very simple C program. It compiles and runs successfully. GOOD. But all the answers for wry1, wry2 and wry3 are COMPLETELY WRONG. Why? As future software engineers, there are very important lessons to be learnt here.


(2) C-PROGRAM ==> SEF-Tutorial-02-Exer-02.c

This program is a very small modification to the simple C program provided to you earlier, i.e. Item(1) the SEF-Tutorial-02-Exer-02.c program. This program compiles and runs successfully, as usual, meaning the code steps for the calculations are correct. However, not all the calculations are correct. Why? For example, calculate(1,1,1); gives => CORRECT RESULTS but calculate(3,4,5); gives => INCORRECT RESULTS.


(3) C++ PROGRAM ==> SEF-Tutorial-02-Exer-03.cpp

This is a very simple C++ program that calculates the factorial function. Sometimes this function gives correct results and sometimes it gives incorrect results. Why?


(4) PYTHON PROGRAM ==> SEF-Tutorial-02-Exer-04.py

This is a simple python program that also calculates the value of the factorial function. It answers the questions raised in Item(3), that is, SEF-Tutorial-02-Exer-03.cpp  Unlike Item(3) above, this program gives correct results for all its inputs. This Python program was also done as a comparison to the C++ program.

=================================================
--
WASSALAM
wruslan.hahaha

Attachments:
SEF-Tutorial-02-Exer-01.c
SEF-Tutorial-02-Exer-02.c
SEF-Tutorial-02-Exer-03.cpp
SEF-Tutorial-02-Exer-04.py

Full Version with Microsoft Word Version and Attachments
Return to Software Engineering Fundamentals (SEF9MMUWRY)
Previous Topic: 51 Programming Concepts Lesson 01 (Numerical calculations in Python are easy. )
Next Topic: 53 Programming Concepts Lesson 03 (Decimal numbers in python are exact but not in C/C++. Zero difference means zero values.)

0 comments:

Post a Comment