Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create functions README #1

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
74495b3
Create functions folder with initial basic README
macintoshhelper Oct 15, 2017
bd0cad4
Add googletest source and update README with learning objectives
macintoshhelper Oct 21, 2017
a678bf6
Add one more goal - the import system
besarthoxhaj Oct 21, 2017
aad2af0
[WIP] Add helloworld example and preprocessor README
macintoshhelper Oct 21, 2017
a9fd7f4
[WIP] Add helloworld example and preprocessor README
macintoshhelper Oct 21, 2017
1de44a6
Resolve merge conflict in README
macintoshhelper Oct 21, 2017
2c1a234
[feature] tyring to build directories and linking
besarthoxhaj Oct 21, 2017
b81bf3e
Add nodemon support for multiple files in examples + add more doc
macintoshhelper Oct 21, 2017
8f48ed4
Improve learning objectives, etc + add contents in main README
macintoshhelper Oct 21, 2017
b85c73d
Fix up formatting in README for #Architecture
macintoshhelper Oct 21, 2017
a0d2c53
Add [WIP] Applications section to main README
macintoshhelper Oct 21, 2017
87b3d74
Add definition and use-cases of a preprocessor
macintoshhelper Oct 22, 2017
d7e7ae7
Clean up README
macintoshhelper Oct 22, 2017
b9e021b
Add package manager learning outcome to main README
macintoshhelper Oct 22, 2017
faa4627
Fix md formatting in README
macintoshhelper Oct 22, 2017
632f3db
[housekeeping] remove logs and clean up
besarthoxhaj Oct 28, 2017
4c70bcd
[feature] add pointers
besarthoxhaj Oct 28, 2017
6516f17
Update README...
macintoshhelper Oct 28, 2017
ae37411
Merge branch 'cpp-basics' of https://github.com/coding-wiki/learn-cpp…
macintoshhelper Oct 28, 2017
ce92a70
Add readmes for operators, pointers and variables
macintoshhelper Oct 28, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 211 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,224 @@
# learn-cpp
learn-cpp

Learn C++

## Goals
General Goals

- [ ] Hello world
- [ ] TDD
- [ ] Understand import system
- [ ] Dev Workflow - compiling
- [ ] Distribution

## Contents
- [**Declarations**](./declarations) - declaring variables and constants that will be used in your application
- [**Assignments**](./assignments) - Assigning values to variables in the application code
- [**Preprocessor Directives**](./preprocessor) - Instructions provided to the compiler based on the execution environment
- [**Comments**](./comments) - Code documentation
- [**Function Declarations**](./functions) - Reusable pieces of code
- [**Executable statements**](./) - Perform operations and execute instructions.
## Learning Outcomes

- Understand and use the basic *programming constructs* of C/C++
- What are the basic *programming constructs*?
- **Definition:** A programming construct is the syntax in which a programming language is written. It is often used as a reference to *control flow* or *flow control statements*
- *Conditional statements:* `if`, `case`, etc
- *Repetition:* `for` and `while` loops
- *Exception handling:* `try`, `catch`,
- *Async:*
- [What is a *preprocessor*?](./preprocessor)
- Manipulate various C/C++ datatypes, such as arrays, strings, and pointers
- Create, manipulate and use *primitive data-structures:* variables and constants: `int`, `std::string`, etc
- What is the best type of data-type for numbers, strings, etc? e.g. `char` vs `std::string`
- Create, manipulate and use *complex data-structures:* arrays, structs, unions, and enumerations
- How do we do *string* manipulation?
- Create and use simple functions
- Be able to manage external dependencies in an elegant fashion
- [Conan - C++ Package Manager](https://conan.io/)
- Using **TDD** in C++
- Isolate and debug common errors in C++ apps
- How can we efficiently debug?
- What are common errors?
- Use memory appropriately, including proper allocation/deallocation procedures
- How do we allocate to memory?
- How do we deallocate from memory?
- Apply object-oriented programming approaches to software problems in C++
- What is a class and object?
- What is the standard way of using classes/objects?
- What is a contstructor?
- Write small-scale C++ apps using the above skills
- What are the applications for small C++ apps?



## Applications

Ref: [edX - C++ Algorithms and Data Structures](https://courses.edx.org/courses/course-v1:Microsoft+DEV285x+4T2017/course/)

**Basic Algorithms**

- [Selection Sort]() -
- [Linear Search]() -
- [Bubble Search]() -

**Algorithmic Analysis**

- [Merge Sort]() -
- [Binary Search]() -
- [Big O]() -

**Basic Data-Structures**

- [Linked Lists]()
- [Stack]()
- [Queue]()



## Architecture
When should I use a `class`?
- Something which is a "separate" idea

When should I use an `object`?
- Something which is a "separate" entity
- An `object` is declared inside of a `class`

When should I use an `abstract class`?
- If two classes have a common interface

When should I use a `base class`?
- A base `class` is a significant commonality in the implementations of two classes

When should I use a `template`?
- When a `class` is a *container* of *objects*

When should I use a *common namespace*?
- When a set of classes, templates, etc are logically related


## Modularising Code into Files
Each source file is compiled separately from other source files. `.cpp` files are clueless to what is happening in other `.cpp` files

**Headers** are used to link `.cpp` files by making the *interface* visible to other `.cpp` files

Classes are declared in the header file?

`#include` is basically a *copy/paste* operation

- so duplicate `#include`s should be avoided with *include guards*

### File Extensions - Convention

*Header* files should use `.h__` which can be `.h`, `.hpp` or `.hxx`
- `.hpp` used for inline functions?
Anything starting with `.h` is a header file

*C++ source files* should use `.c__` extension which can be `.cpp`, `.cxx` or `.cc`

*C source files* should use `.c` *ONLY*

Header files use preprecessor directive `#include`s and not compiled

*Do not include source/implementation files*

*Derived class* - an `extends`

Parent and child classes

What is a *friend declaration*?

Are all objects *datatypes*?

What is the difference between using an object as a paramater or as say a variable declaration

Pointer, return type or parameter should use a forward declare?

How to `extend` a class:
`class ChildClass : public Parent` -

Main header file with all imports? https://github.com/oitofelix/mininim/blob/master/src/mininim.h

What is *instantiate*?

How and what is injecting a function with `inline`

## IOStream
**std::endl** - Inserts a newline character and flushes the output sequence
What does *flushing* mean?

**std::cout** - Standard character output


## Guards

Do not define files twice, or import the same thing multiple times

## Namespace
`std::cout` becomes `cout`...

## Functions
Main function has to return an `int`.

Functions must be declared before being used

## Pointers
A *primitive* datatype that reference an object.
- To what degree is it *primitive*?
- What is a *structure*?
- Primitive version of a *class*?
[Pointers - Wikiversity](https://en.wikiversity.org/wiki/C%2B%2B/Pointers)

### Arrays
An array is a collection of similar data types under the same name
Syntax:

```cpp
int arr[25];
// Where 25 is the length/size of the array
```

Although arr behaves as a pointer, its value cannot be changed as it references a specific region in memory.


### Allocating variables
The new operator allocates an object from the `memory?` heap and `optionally initializes?` it

When you have finished using an object/variable, you must delete it. Otherwise, the pointed memory will be inaccessible and the result is a memory leak.

### Referencing variables
The *&* operator is used to *reference?* an object. Using the *&* operator, you can get a pointer to the object. This new pointer can be used as a function parameter or be *assigned to a variable?*.

### Multidimensional Array
- How can you implement a map with an array?


### LinkedList
Linear data structure where each element is a separate object, with *chaotic* memory locations
https://www.youtube.com/watch?v=vcQIFT79_50

Primitive array implementation?

## Resources

- http://www.stroustrup.com/C++.html
- [basic programming constructs?](http://www.cs.wustl.edu/~schmidt/PDF/C++-C-portions4.pdf)
- [Introduction to C++ Syllabus](https://d37djvu3ytnwxt.cloudfront.net/assets/courseware/v1/61b41fca32ac19441fc06b34c87e40c0/asset-v1:Microsoft+DEV210x+4T2017+type@asset+block/Introduction_to_C___Syllabus.pdf)


- MIT - Introduction to C++ - 2011
- MIT - Introduction to C and C++
- Stanford slides and code - super useful
- https://classroom.udacity.com/courses/ud210/lessons
- http://www.cppsamples.com/
- https://github.com/jesyspa/linear-cpp
- http://en.cppreference.com/w
- https://medium.com/@vardanator/why-cs-students-must-learn-c-as-their-main-programming-language-6d3b4f8720bd

- https://github.com/jwasham/practice-cpp

[C++ Programming in 1 Hour](https://www.youtube.com/watch?v=Rub-JsjMhWY)

Cool site: https://www.codesdope.com/cpp-lets-start/

Cool stuff
- https://opencv.org/
5 changes: 5 additions & 0 deletions compiling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ main_code_file.cpp # source code input

g++ -o compiledfile folder/code.cpp
```

Running compiled code:
```sh
./compiled
```
7 changes: 7 additions & 0 deletions examples/helloworld/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <iostream>
#include "message.h"

int main() {
Message m;
m.echo();
};
6 changes: 6 additions & 0 deletions examples/helloworld/message.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>
#include "message.h"

void Message::echo() {
std::cout << "Hello import" << std::endl;
};
9 changes: 9 additions & 0 deletions examples/helloworld/message.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef __ECHO_H_INCLUDED__
#define __ECHO_H_INCLUDED__

class Message {
public:
void echo();
};

#endif
6 changes: 6 additions & 0 deletions examples/pointer/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>

int main() {
std::cout << "Hello Bes" << std::endl;
return 0;
};
32 changes: 32 additions & 0 deletions functions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# C++ Functions

## Basic Syntax
```c++
type name(parameter list) {
// statements in the function body
}
```
Where
- *type* is: `string`, `int`, etc.
- *name* is: the function name
- *parameter list* is: list of variable declarations that hold the input data


## Simple Example
```c++
int addOne(int n) {
return n + 1;
}
```

## Syntax

### Optional Parameters
Functions can specify optional parameters by including an initializer in the variable declaration:

```c++
void getValue(int value = 72);
```

## Resources
- https://web.stanford.edu/class/archive/cs/cs106b/cs106b.1134/handouts/05-FunctionsInC++.pdf
2 changes: 2 additions & 0 deletions lib/googletest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# python
*.pyc
Loading