https://github.com/ardacebi/cpp-examples
Simple and basic C++ examples for educational purposes.
https://github.com/ardacebi/cpp-examples
basic-example cpp cpp-examples cpp-programming educational educational-materials examples examples-cpp simple-example simple-examples
Last synced: about 1 month ago
JSON representation
Simple and basic C++ examples for educational purposes.
- Host: GitHub
- URL: https://github.com/ardacebi/cpp-examples
- Owner: ardacebi
- License: unlicense
- Created: 2020-04-12T13:33:00.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-06-17T16:55:47.000Z (almost 5 years ago)
- Last Synced: 2025-03-24T12:21:30.362Z (2 months ago)
- Topics: basic-example, cpp, cpp-examples, cpp-programming, educational, educational-materials, examples, examples-cpp, simple-example, simple-examples
- Language: C++
- Size: 70.3 KB
- Stars: 4
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# C++ Examples
Simple and basic C++ examples for educational purposes.
## Index
- [Building/Compiling](#building_compiling)
- [Contributing](#contributing)
- [Example Index](#example_index)You can compile/build all these examples on your computer to change and try them out yourself.
### Method 1: Using an IDE
Compiling C++ projects using your IDE is an easy way of editing and seeing it's result in a shorter time.
#### Visual Studio
After you've loaded (and perhaps edited) the project to Visual Studio, build it from the Build section.
### Method 2: Terminal
Of course, you can follow the traditional way of building C++ projects from the terminal.
#### Linux
1. Install GNU C/C++ compiler:
If you are using Fedora, Red Hat, CentOS, or Scientific Linux, use the following yum command to install GNU C/C++ compiler:
`yum groupinstall 'Development Tools'`
If you are using Debian or Ubuntu Linux, type the following apt-get command to install GNU C/C++ compiler:
`$ sudo apt-get update`
`$ sudo apt-get install build-essential manpages-dev`
2. `cd` to the directory in which the C++ project is located
3. Compile with `g++ file.cpp -o file2`
4. Run with `./file`#### Mac
1. Compile with `g++ file.cpp`
2. Run with `./file`#### Windows
1. Download MinGW from [here](https://sourceforge.net/projects/mingw-w64/) or [here](https://sourceforge.net/projects/mingw/files/OldFiles/).
2. `cd` to the directory in which the C++ project is located (like: cd C:\Desktop\...)
3. Compile with `g++ file.cpp -o file.exe`
4. Run the executable: `file.exe`.You can contribute your examples with a pull request.
1. Prepare your example with the necessary code and a comment that indicates you're author on the top (see existing examples).
2. Fork the repository
3. Add your example(s)
4. Open a pull request.Your examples should be **instructive and explanatory with comments**. Make sure to explain important lines on your code (see existing examples). This is an important step as the main objective is to create an explanatory tutorial with all examples.
- [BMI Calculator](#bmi_calculator) [(file)](bmi.cpp)
- [Hello World](#hello_world) [(file)](helloworld.cpp)
- [Space Traveler](#space_traveler) [(file)](space.cpp)
- [Temperature Converter](#temperature_converter) [(file)](temperature.cpp)---
Body mass index (BMI) is a value derived from the mass and height of a person. The BMI is defined as the body mass divided by the square of the body height.
This program calculates the BMI of a person by:
1. Asking them their height in metres (m)
2. Asking them their weight in kilograms (kg)
3. Calculating their BMI with the formula weight / (height \* height).### [Hello World](helloworld.cpp)
This is a basic Hello World program.
### [Space Traveler](space.cpp)
Someone is travelling from Earth to six potential other planets in our solar system. This program requests the person's weight on Earth, and then calculates their weight on the other planets.
The program does this by:
1. Asking the person their weight on Earth
2. Asking the person which planet they want to travel
3. After receiving those information, it multiplies the person's weight with the gravitational force of that planet to calculate their weight on those planets.### [Temperature Converter](temperature.cpp)
This program converts Fahrenheit to Celsius and vice versa based on user selection.
The program does this by:
1. Asking the user what they want to convert to and from (Fahrenheit to Celsius or Celsius to Fahrenheit)
2. Asking the user to input the temperature value
3. Outputting the final calculated value.