0% found this document useful (0 votes)
376 views

Programming C++ On Raspberry Pi

The document provides instructions for programming C++ on Raspberry Pi. It begins by explaining how to install the C++ application and then demonstrates various C++ concepts like displaying output, reading user input, if statements, for loops, and while loops. For each concept, it provides the source code example and commands for compiling and running the program. The overall goal is to teach the user how to program basic C++ applications on Raspberry Pi.

Uploaded by

Nie Date
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
376 views

Programming C++ On Raspberry Pi

The document provides instructions for programming C++ on Raspberry Pi. It begins by explaining how to install the C++ application and then demonstrates various C++ concepts like displaying output, reading user input, if statements, for loops, and while loops. For each concept, it provides the source code example and commands for compiling and running the program. The overall goal is to teach the user how to program basic C++ applications on Raspberry Pi.

Uploaded by

Nie Date
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Programming C++

on Raspberry Pi
Task 1 How to install C++ application in Raspberry Pi

Outcome User can now start programming C++ language on Raspberry Pi

Connect Raspberry Pi with laptop


Run PuTTY and VNC viewer
Open Terminal console (3rd from the
right)
Enter pi@raspberrypi:~ $ sudo apt-get
install g++ to install the C++ application
Task 2 Displaying an output

User can understand on how to simply display an output using C++ on


Outcome Raspberry Pi

Lesson 1.0 : Writing in nano


Enter pi@raspberrypi:~ $ sudo nano
hello.cpp to create a C++ file and write the
program in here
For this example, try entering the source
code on the right
Press Ctrl+X to exit
There will be a yes or no confirmation
whether to save or cancel the file
Lesson 2 : Compiling and Run
Enter pi@raspberrypi:~ $ sudo g++ -o
hello hello.cpp to compile the C++ file
'g++' is to compile the program
'-o hello' flag is to create a program called
hello
It will create this program based on the
'hello.cpp' source code file
To run the program enter pi@raspberrypi:~
$ ./hello
Example 2
Enter pi@raspberrypi:~ $ sudo nano RPi.cpp
to create a C++ file
For this example, try entering the source code
on the right
String is used in this source code which is
another way to display an output
Enter pi@raspberrypi:~ $ sudo g++ -o RPi
RPi.cpp to compile the C++ file
To run the program enter pi@raspberrypi:~
$ ./RPi
Example 3
Enter pi@raspberrypi:~ $ sudo nano
addition.cpp to create a C++ file
For this example, try entering the source
code on the right
Enter pi@raspberrypi:~ $ sudo g++ -o
addition addition.cpp to compile the C++
file
To run the program enter pi@raspberrypi:~
$ ./addition
Task 3 Reading user input

Outcome User can write a program on how to read an input

Enter pi@raspberrypi:~ $ sudo nano


user_input.cpp to create a C++ file
For this task, try entering the source code on
the right
Enter pi@raspberrypi:~ $ sudo g++ -o
user_input user_input.cpp to compile the
C++ file
To run the program enter pi@raspberrypi:~
$ ./user_input
Task 4 If statement

Outcome User can write a program that includes an if statement

Enter pi@raspberrypi:~ $ sudo nano if.cpp


to create a C++ file
For this task, try entering the source code on
the right
Enter pi@raspberrypi:~ $ sudo g++ -o if
if.cpp to compile the C++ file
To run the program enter pi@raspberrypi:~
$ ./if
Here is an example of a correct and incorrect
answer.
Task 5 For loop

Outcome User can loop a certain program using the for loop

Enter pi@raspberrypi:~ $ sudo nano


for_loop.cpp to create a C++ file
For this task, try entering the source code on
the right
Enter pi@raspberrypi:~ $ sudo g++ -o
for_loop for_loop.cpp to compile the C++
file
To run the program enter pi@raspberrypi:~
$ ./for_loop
Task 6 While loop

Outcome User can loop a certain program using the while loop

Enter pi@raspberrypi:~ $ sudo nano


while_loop.cpp to create a C++ file
For this task, try entering the source code on
the right
Enter pi@raspberrypi:~ $ sudo g++ -o
for_loop for_loop.cpp to compile the C++
file
To run the program enter pi@raspberrypi:~
$ ./for_loop
End of Slide

You might also like