Git Product home page Git Product logo

cpp-examples's Introduction

C++ Examples

Simple and basic C++ examples for educational purposes.

Index

Building/Compiling

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

  1. cd to the directory in which the C++ project is located
  2. Compile with g++ file.cpp -o file2
  3. Run with ./file

Mac

  1. Compile with g++ file.cpp
  2. Run with ./file

Windows

  1. Download MinGW from here or here.
  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.

Contributing

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.

Example Index


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

This is a basic Hello World program.

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.

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.

cpp-examples's People

Contributors

ardacebi avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.