0% found this document useful (0 votes)
4 views13 pages

IPC Lecture 1

The document provides an introduction to C++ programming, covering essential components such as the structure of a C++ program, including preprocessor directives, namespaces, and the main function. It also explains input and output streams, C++ statements, and comments, along with a class activity involving calculating the size of a room based on user input. The content serves as a foundational guide for understanding basic C++ programming concepts and syntax.

Uploaded by

naeothato
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views13 pages

IPC Lecture 1

The document provides an introduction to C++ programming, covering essential components such as the structure of a C++ program, including preprocessor directives, namespaces, and the main function. It also explains input and output streams, C++ statements, and comments, along with a class activity involving calculating the size of a room based on user input. The content serves as a foundational guide for understanding basic C++ programming concepts and syntax.

Uploaded by

naeothato
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Introduction to C++

Overview and the Project


Class Project: Internal Assessments

TOPIC: Data Privatizing tool for AI System - Data


Masking and Pseudonymizing (scoped)
Basic C++ Program
• A typical C++ code consists of:
• Include and Namespace statements
• Main function and Its Return Type
• Syntactically correct C++ statements
Technical Word Description
● Program
● Syntax
● Preprocesor and Preprocessor directive
● C++ Statements
● Namespace
● Input and Output Stream
● Console
● Comments
Preprocessor Directive
● A preprocessor reads your program before it is compiled
and only executes the lines beginning with # symbol.
● The #include directive causes the preprocessor to include
the contents of another file known as header file in the
program.
● For example, #include <iostream> will include the
contents of the <iostream> file in the program, which
allows a C++ program to display output on the screen
and read input from the keyboard.
Namespace
● Namespace s used to organize the names of
program entities.
● The statement using namespace std
declares that the program will be accessing
entities whose names are part of the
namespace called std.
● Every name created by the iostream file is
part of the namespace and that is the reason
why the C++ program needs access to the
std namespace.
Main Function and Its Return
Type
● Every C++ program must have on 1 main function
● It is the starting point of the program execution
● When a C++ program executes, the main function
is called the operating system
● C++ Main Function may or may have a return
type:
 int is often the default return type
 void is the default value for no return type
Input/Output Stream: Console
I/O
● cout
 Standard output stream
 Console – Show output on te console
● cin
 Standard input stream
Keyboard – input from Keyboard
C++ Statements
● A statement is a complete instruction that causes the computer to perform
some action
● The body of any function is a sequence of statements
● Statements can be a combination of key words, operators and program-
defined symbols
● They always end with a semicolon (;)
 sum = a + b;
Comments
● Single-line comments
 Two forward slash //

● Multi-line comments
 Start with /* and end with */
More C++ statements
• Adding more to our C++ code:
• Variables
• Data types
• Input stream
• Maths Operations
• Variable: containers for data,
i.e. storage location
• Data type: type of data in c++
• Input stream: get value from
keyboard
• Maths Operations: +, -, *, /, %, etc.
Class Activity: Room Size
● Write a C++ program to accept 3 input numbers from the keyboard, length,
width, and height of a room.
 int length;
 int width;
 int height;
● This program must them calculate the room size as follows:
 int room_size = length * width * height;
● Display you room size on the console using Output stream cout.
TBC…

You might also like