IFD:EAI SoS21/introduction to c++: Difference between revisions

From Medien Wiki
(Created page with "## Basics You can find (and edit) the code examples from today in the following links: [https://replit.com/@abnutzer/CppDataTypes#main.cpp Data Types] Classes Po...")
 
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
## Basics
==Session 2: Basics==


You can find (and edit) the code examples from today in the following links:
You can find (and edit) the code examples from today in the following links:


    [https://replit.com/@abnutzer/CppDataTypes#main.cpp Data Types]
* [https://replit.com/@abnutzer/CppDataTypes#main.cpp Data Types]
    Classes
* [https://replit.com/@abnutzer/ClassesInCpp Classes]
    Pointers


===Homework===


As your homework task I want you to extend the code in Repl.it. as follows:
As a homework task I want you to extend the code in Repl.it. as follows:


    For the "Classes" example above, add a Header (Point2D.h) and a Function definitions (Point2D.cpp) file to the project where you define the class and its functions seperately. Finally include the header file with #include "Point2D.h" in the main.cpp file, so we can use our custom C++ class. Watch the online tutorial below to learn how to do that!
# For the "Classes" example above, add a Header (Point2D.h) and a Function definitions (Point2D.cpp) file to the project where you define the class and its functions seperately. Finally include the header file with #include "Point2D.h" in the main.cpp file, so we can use our custom C++ class. Watch [https://youtu.be/vz1O9nRyZaY this online tutorial] to learn how to do that! You don't need to put the .h and .cpp file in different folders, as shown in the video. Putting them in the same folder as the main.cpp works as well.
 
# As a second task, I want you to extend the code of the Point2D to include a function to measure the distance between two points in 2D space. Do you remember the "Theorem of Pythagoras"?
 
The function body should look like this:
 
    float distanceToOtherPoint(Point2D otherPoint) {
      float distance = ... // calculate distance here
      return distance;
    }
 
Include that function in our Point2D class and make it calculate the distance!

Latest revision as of 10:34, 19 April 2021

Session 2: Basics

You can find (and edit) the code examples from today in the following links:

Homework

As a homework task I want you to extend the code in Repl.it. as follows:

  1. For the "Classes" example above, add a Header (Point2D.h) and a Function definitions (Point2D.cpp) file to the project where you define the class and its functions seperately. Finally include the header file with #include "Point2D.h" in the main.cpp file, so we can use our custom C++ class. Watch this online tutorial to learn how to do that! You don't need to put the .h and .cpp file in different folders, as shown in the video. Putting them in the same folder as the main.cpp works as well.
  1. As a second task, I want you to extend the code of the Point2D to include a function to measure the distance between two points in 2D space. Do you remember the "Theorem of Pythagoras"?

The function body should look like this:

   float distanceToOtherPoint(Point2D otherPoint) {
      float distance = ... // calculate distance here
      return distance;
   }

Include that function in our Point2D class and make it calculate the distance!