Example programs in cpp

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Simple and basic C++ examples for educational purposes.

License

ardacebi/cpp-examples

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Simple and basic C++ examples for educational purposes.

You can compile/build all these examples on your computer to change and try them out yourself.

Compiling C++ projects using your IDE is an easy way of editing and seeing it’s result in a shorter time.

After you’ve loaded (and perhaps edited) the project to Visual Studio, build it from the Build section.

Of course, you can follow the traditional way of building C++ projects from the terminal.

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

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.

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.

  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.

  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.

About

Simple and basic C++ examples for educational purposes.

Источник

C++ Programs and Examples | C++ Samples

While learning any programming language, practicing the language with examples will help you to understand the concepts better.
We have collected the List of Frequently asked questions (FAQ code examples) in C++ programming. the list contain C++ language basic and simple source codes and examples. This list of C++ tutorials with examples can be very useful to learn the basic concepts in C++.

  • C++ Simple Programs And Examples
  • C++ – Hello World Program
  • C++ – Simple calculator
  • C++ – Even and Odd
  • C++ – Swap two numbers
  • C++ – Prime Number
  • C++ – Find Perfect Number
  • C++ – Factorial of Number
  • C++ – Fibonacci Series
  • C++ – Human Resource Management Program
  • C++ – Calculate number of characters, words, sentences
  • C++ – Subtract two Strings
  • C++ – Processing of the Students structure
  • C++ – Program with Matrices
  • C++ – Calculate Equation
  • C++ – Arrange Numbers in Ascending order
  • C++ – Check Armstrong Number
  • C++ – HCF and LCM
  • C++ – Square Root of a Number
  • C++ – Cube Root of a Number
  • C++ – ASCII Code for Characters and numbers
  • C++ – Check Palindrome Number
  • C++ – Bubble sort
  • C++ – Random Number Generator
  • C++ – Sum of ODD Numbers in the Given Range
  • C++ – Display current date and time
  • C++ – Reverse a Number
  • Formula Based Programs
  • C++ – Leap Year
  • C++ – Surface Area and volume of cone
  • C++ – Solve Quadratic equation
  • C++ – Factorial using recursive function
  • String Based Programs
  • C++ – String into Upper case or lower case
  • C++ – Concatenate Strings
  • Array Based Programs
  • C++ – Program with Matrices
  • Print Any Patterns
  • C++ – Print 5 rows of 10 Stars (*)
  • C++ – Half Pyramid of Stars (*)
  • C++ – Half Pyramid of numbers
  • C++ – Print Triangle of Stars
  • C++ – Display Reverse pyramid.
  • C++ – Print Alphabet Pattern
  • C++ – Diamond of Star
  • C++ – Pascal Triangle
  • C++ – Floyd Triangle
  • C++ Conversion
  • C++ – Convert decimal to Hexadecimal
  • C++ – Decimal to Binary
  • C++ – Binary To Decimal
  • C++ – Decimal to Octal
  • C++ – Hexadecimal to Decimal
  • C++ – Integer to String
  • C++ Sorting algorithms & Techniques
  • C++ – Bubble Sort
  • C++ – Insertion Sort
  • C++ – Selection Sort
  • C++ – Merge Sort
  • C++ – Quick Sort
  • C++ Handling Files
  • C++ – How to get Current Directory in Linux/Windows
  • C++ – How Create a Text File and Write in It
  • C++ – Program find if file exists of not
  • C++ – Program to list all files in the Directory on Windows / Linux

Stuff I use to make videos

Screen Recording Software – Camtasia

Источник

Читайте также:  Build html with jquery
Оцените статью