1 / 21

Haverford Cascade Mentoring Program

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. C++ and Python. Brief History: C++

jennis
Download Presentation

Haverford Cascade Mentoring Program

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. C++ and Python Brief History: C++     In 1985 Bjarne Stroustrup, also of Bell Labs,invented the C++ programming language. To the Clanguage he added features for data abstraction andobject-oriented programming. Instead of naming thelanguage D, the Bell Labs group named it C++ in ahumorous vein. As we see later, ++ signifies theincrement operation  in the C and C++ language. Givena variable x, the expression x++ means to increment(add one to) the current value of x. Therefore, thename C++ suggests an enhanced ("incremented") versionof the C++ language. Although C originally was intended as a systemprogramming language, both C and C++ are widely usedtoday in business, industry, and personal computing.C++ is powerful and versatile, embodying a wide rangeof programming concepts.

  3. 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.

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

  5. C++ #include <iostream.h> int main() { cout<<“Hello Haverford”<<endl; return 0; } Python print “Hello Haverford” Simple program

  6. C++ //this program demonstrates C++ //in its simplest form #include <iostream.h> int main() { cout<<“Hello Haverford”<<endl; return 0; } Python #this program demonstrates #python in its simplest form print “Hello Haverford” Simple program (with comments)

  7. C++ cout<<“Please enter a name ”<<endl; cin>>name; cout<<“the name you entered was”, name<<endl; Python name = raw_input(“Please enter a name”) print “the name you entered was”, name Syntax (input/output)

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

  9. 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”<<endl; } Else if (num3 > num2) { cout<<“14 is greater than 32”<<endl; } Else cout<<“please review your first grade math material”<<endl Python Num1 = 10 Num2 = 32 Num3 = 14 If num1 > 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” If statement (If-Then-Else form)

  10. C++ Count = 0; While (count < 10) { cout<<“Andre O’Brien”<<endl; count =count +1; } Python Count = 0 While count < 10: print “Andre O’Brien” count = count + 1 While loops

  11. C++ For (loopCount = 1; loopCount<=10; loopCount++) { cout<<“Andre O’Brien”<<endl; } Python For loopCount in range(10): print “Andre O’Brien” For loops

  12. C++ Void someFunction() { count = 0; while (count<10) { cout<<“Hey OB”<<endl; } someFunction() //function call Python Def someFunction: count = 0 while count < 10: print “Hey OB” someFunction() #function call Functions

  13. Differences Between C++ and PythonSummary 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.

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

  15. Lab 1

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

  17. Do two rectangles overlap? Level – beginner # Do 2 Windows overlap? Def window_overlap(minx1,maxx1,miny1 ,maxy1,minx2,maxx2,miny2,maxy2): if maxy1<miny2 or maxx1<minx2 or maxy2 < miny1 or maxx2 < minx1: return False else: return True

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

  19. 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): testX = center_x testY = center_y if testX < xmin: testX = xmin if testX > xmax: testX = xmax if testY < ymin: testY = ymin if testY > ymax: testY = ymax distanceX2 = (center_x-testX) * (center_x-testX) distanceY2 = (center_y-testY) * (center_y-testY) distTotal2 = distanceX2 + distanceY2 fDist = sqrt(distTotal2) if fDist < radius: return True else: return False

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

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

More Related