Presentation is loading. Please wait.

Presentation is loading. Please wait.

Haverford Cascade Mentoring Program Computer Programming: C++ to Python Conversion Professor: Dave Wannacott Student: Kris Brower Dobbins Vocational Tech.

Similar presentations


Presentation on theme: "Haverford Cascade Mentoring Program Computer Programming: C++ to Python Conversion Professor: Dave Wannacott Student: Kris Brower Dobbins Vocational Tech."— Presentation transcript:

1

2 Haverford Cascade Mentoring Program Computer Programming: C++ to Python Conversion Professor: Dave Wannacott Student: Kris Brower Dobbins Vocational Tech Teacher: Andre O’Brien Student: Denisha Davis

3 C++ and Python Brief History: C++ In 1985 Bjarne Stroustrup, also of Bell Labs, invented the C++ programming language. To the C language he added features for data abstraction and object-oriented programming. Instead of naming the language D, the Bell Labs group named it C++ in a humorous vein. As we see later, ++ signifies the increment operation in the C and C++ language. Given a variable x, the expression x++ means to increment (add one to) the current value of x. Therefore, the name C++ suggests an enhanced ("incremented") version of the C++ language. Although C originally was intended as a system programming language, both C and C++ are widely used today in business, industry, and personal computing. C++ is powerful and versatile, embodying a wide range of programming concepts. In 1985 Bjarne Stroustrup, also of Bell Labs, invented the C++ programming language. To the C language he added features for data abstraction and object-oriented programming. Instead of naming the language D, the Bell Labs group named it C++ in a humorous vein. As we see later, ++ signifies the increment operation in the C and C++ language. Given a variable x, the expression x++ means to increment (add one to) the current value of x. Therefore, the name C++ suggests an enhanced ("incremented") version of the C++ language. Although C originally was intended as a system programming language, both C and C++ are widely used today in business, industry, and personal computing. C++ is powerful and versatile, embodying a wide range of programming concepts.

4 C++ and Python Brief History: Python Python is a portable, interpreted, object-oriented programming language. Its development started in 1990 at CWI in Amsterdam, and continues under the ownership of the Python Software Foundation. The language has an elegant (but not over-simplified) syntax; a small number of powerful high-level data types are built in. Python can be extended in a systematic fashion by adding new modules implemented in a compiled language such as C or C++. Such extension modules can define new functions and variables as well as new object types. CWIPython Software FoundationCWIPython Software Foundation

5 Differences Between C++ and Python Simple program Simple program Comments (Declarations) Comments (Declarations) Syntax (input/output) Syntax (input/output) Variables (Identifier and Data Type) Variables (Identifier and Data Type) If statement If statement While loops While loops For loops For loops Functions Functions

6 Simple program C++ #include #include int main() { cout<<“Hello Haverford”<

7 Simple program (with comments) C++ //this program demonstrates C++ //in its simplest form #include #include int main() { cout<<“Hello Haverford”<

8 Syntax (input/output) C++ cout<<“Please enter a name ”<>name; cout<<“the name you entered was”, name<

9 Variables C++ int number; char name; float calculate; number = 27; name = “Denisha”; calculate = 99.8; Python Number = 27 Name = “Denisha” Calculate = 99.8

10 If statement (If-Then-Else form) C++ Num1 = 10; Num2 = 32; Num3 = 14; If (num1 > num2) { cout<<“10 is greater than 32<<“endl; } Else if (num2 < num3) { cout<<“32 is less than 14”< num2) { cout<<“14 is greater than 32”< num2: print “10 is greater than 32” Elif num2 < num3: print “32 is less than 14” Elif num3 >num2: print “14 is greater than 32” Else print “please review your first grade math material”

11 While loops C++ Count = 0; While (count < 10) { cout<<“Andre O’Brien”<

12 For loops C++ For (loopCount = 1; loopCount<=10; loopCount++) { cout<<“Andre O’Brien”<

13 Functions C++ Void someFunction() { count = 0; while (count<10) { cout<<“Hey OB”<

14 Differences Between C++ and Python Summary On the average Python programs compile slower than C++ programs. However, it usually takes less time to write programs in Python and they tend to be shorter in length than their C++ counter parts. The approach to programming remains virtually the same. Another noteworthy comparison deals with how C++ and Python deals with debugging issues. C++ highlights a syntax or logic error but you must know the language well to understand what’s wrong. Python, on the other hand, doesn’t highlight your errors. It does, however, tell you what line your error can be found on and it tells you what datatype or function is undefined. I personally prefer Python’s approach better.

15 Summer Experiment – Lab 1 Do two lines overlap? Do two lines overlap? Do two rectangles overlap? Do two rectangles overlap? Do two circles overlap? Do two circles overlap? Does a rectangle and a circle overlap? Does a rectangle and a circle overlap? Do two line segments intersect? – beyond the scope of my current skill level. Do two line segments intersect? – beyond the scope of my current skill level.

16 Lab 1

17 Do two lines overlap? Level – beginner # Do 2 ranges overlap? def range_overlap(min1,max1,min2,max2): if max1 max2: if max1 max2: return False return False else: else: return True return True

18 Do two rectangles overlap? Level – beginner # Do 2 Windows overlap? Def window_overlap(minx1,maxx1,miny1,maxy1,minx2,maxx2,miny2,maxy2):,maxy1,minx2,maxx2,miny2,maxy2): if maxy1

19 Do two circles overlap? Level – intermediate # Do 2 Cicles overlap? def circle_overlap(x1,y1,r1,x2,y2,r2): distanceX = x2 - x1 distanceX = x2 - x1 distanceY = y2 - y1 distanceY = y2 - y1 distanceGAP = pow(distanceX,2) + pow(distanceY,2) distanceGAP = pow(distanceX,2) + pow(distanceY,2) roc = r1 + r2 roc = r1 + r2 roc = pow(roc,2) roc = pow(roc,2) if distanceGAP<=roc: if distanceGAP<=roc: return True return True else: else: return False return False

20 Does a rectangle and a circle overlap? Level – hard # Do a circle and a rectangle overlap? def circle_rectangle_overlap(center_x,center_y, radius,xmin,xmax,ymin,ymax): radius,xmin,xmax,ymin,ymax): testX = center_x testX = center_x testY = center_y testY = center_y if testX < xmin: if testX < xmin: testX = xmin testX = xmin if testX > xmax: if testX > xmax: testX = xmax testX = xmax if testY < ymin: if testY < ymin: testY = ymin testY = ymin if testY > ymax: if testY > ymax: testY = ymax testY = ymax distanceX2 = (center_x-testX) * (center_x-testX) distanceX2 = (center_x-testX) * (center_x-testX) distanceY2 = (center_y-testY) * (center_y-testY) distanceY2 = (center_y-testY) * (center_y-testY) distTotal2 = distanceX2 + distanceY2 distTotal2 = distanceX2 + distanceY2 fDist = sqrt(distTotal2) fDist = sqrt(distTotal2) if fDist < radius: if fDist < radius: return True return True else: else: return False return False

21 Do two line segments intersect? Level – down right unfair!

22 Conclusion C++ and Python Out with the Old in with the New!!!


Download ppt "Haverford Cascade Mentoring Program Computer Programming: C++ to Python Conversion Professor: Dave Wannacott Student: Kris Brower Dobbins Vocational Tech."

Similar presentations


Ads by Google